14052022-09-02 01:58:51Zoli9Szakaszokcpp17Time limit exceeded 79/100158ms37144 KiB
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second
vector<int> st(3000001, 0);
vector<int> cop;

int comp(int y){
    return lower_bound(cop.begin(), cop.end(), y) - cop.begin() + 1;
}

void update(int v, int tl, int tr, int pos, int val){
    if (tl == tr){
        st[v] += val;
        return;
    }
    int tm = (tl + tr) / 2;
    if (pos <= tm){
        update(2*v, tl, tm, pos, val);
    }
    else{
        update(2*v+1, tm+1, tr, pos, val);
    }
    st[v] = st[2*v] + st[2*v+1];
}

int get(int v, int tl, int tr, int l, int r){
    if (max(tl, l) > min(tr, r)){
        return 0;
    }
    if (tl >= l && tr <= r){
        return st[v];
    }
    int tm = (tl + tr) / 2;
    return get(2*v, tl, tm, l, r) + get(2*v+1, tm+1, tr, l, r);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vector<pair<pii, pii > > obj;
    cop.resize(n+2*m);
    int x, y, z;
    for (int i=0; i<n; i++){
        cin >> x >> y >> z;
        obj.push_back({{x, -1*1e5}, {z, 0}});
        obj.push_back({{y, 1e5}, {z, 0}});
        cop[i] = z;
    }
    for (int i=0; i<m; i++){
        cin >> x >> y >> z;
        obj.push_back({{x, i+1},{y, z}});
        cop[n+2*i] = y;
        cop[n+2*i+1] = z;
    }
    sort(cop.begin(), cop.end());
    cop.erase(unique(cop.begin(), cop.end()), cop.end());
    sort(obj.begin(), obj.end());
    pii maxi = {0, 0};
    for (auto i : obj){
        if (abs(i.fi.se) == 1e5){
            update(1, 1, cop.size()+1, comp(i.se.fi), i.fi.se / 1e5 * -1);
        }
        else{
            int cur = get(1, 1, cop.size()+1, comp(i.se.fi), comp(i.se.se));
            if (cur > maxi.fi){
                maxi = {cur, i.fi.se};
            }
        }
    }
    cout << maxi.second;
}
SubtaskSumTestVerdictTimeMemory
base79/100
1Accepted0/010ms25196 KiB
2Accepted0/035ms26888 KiB
3Accepted2/29ms25952 KiB
4Accepted2/212ms26376 KiB
5Accepted2/216ms26804 KiB
6Accepted3/323ms27092 KiB
7Accepted3/317ms27352 KiB
8Accepted3/330ms27764 KiB
9Accepted3/330ms28000 KiB
10Accepted4/432ms27948 KiB
11Accepted4/437ms28252 KiB
12Accepted4/452ms29532 KiB
13Accepted7/764ms30080 KiB
14Accepted7/779ms30128 KiB
15Accepted7/792ms32292 KiB
16Time limit exceeded0/7158ms36860 KiB
17Accepted7/756ms29844 KiB
18Accepted7/794ms32388 KiB
19Accepted7/7109ms32184 KiB
20Time limit exceeded0/7158ms36876 KiB
21Time limit exceeded0/7158ms37144 KiB
22Accepted7/783ms37080 KiB