14072022-09-02 02:09:02Zoli9Szakaszokcpp17Accepted 100/100144ms13848 KiB
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fi first
#define se second
int st[3000009];
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
base100/100
1Accepted0/03ms1832 KiB
2Accepted0/027ms3900 KiB
3Accepted2/22ms2480 KiB
4Accepted2/24ms2664 KiB
5Accepted2/24ms2932 KiB
6Accepted3/313ms3668 KiB
7Accepted3/37ms3572 KiB
8Accepted3/320ms4452 KiB
9Accepted3/321ms4708 KiB
10Accepted4/421ms4648 KiB
11Accepted4/427ms4824 KiB
12Accepted4/441ms6232 KiB
13Accepted7/754ms7264 KiB
14Accepted7/768ms7992 KiB
15Accepted7/782ms8564 KiB
16Accepted7/7144ms13096 KiB
17Accepted7/745ms6576 KiB
18Accepted7/782ms8688 KiB
19Accepted7/797ms10436 KiB
20Accepted7/7143ms13680 KiB
21Accepted7/7143ms13680 KiB
22Accepted7/774ms13848 KiB