14042022-09-02 01:56:25Zoli9Szakaszokcpp17Runtime error 72/100153ms16224 KiB
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second
vector<int> st(300001, 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()
{
    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
base72/100
1Accepted0/04ms4008 KiB
2Accepted0/043ms5716 KiB
3Accepted2/23ms4536 KiB
4Accepted2/27ms5068 KiB
5Accepted2/28ms5240 KiB
6Accepted3/319ms5568 KiB
7Accepted3/312ms5900 KiB
8Accepted3/332ms6668 KiB
9Accepted3/335ms6752 KiB
10Accepted4/435ms6792 KiB
11Accepted4/443ms7012 KiB
12Accepted4/464ms8288 KiB
13Accepted7/783ms8476 KiB
14Accepted7/7104ms8728 KiB
15Accepted7/7127ms11048 KiB
16Runtime error0/7140ms15496 KiB
17Accepted7/770ms8408 KiB
18Accepted7/7127ms11228 KiB
19Time limit exceeded0/7153ms11372 KiB
20Runtime error0/7141ms16112 KiB
21Runtime error0/7140ms16008 KiB
22Accepted7/7129ms16224 KiB