14032022-09-02 01:43:46Zoli9Szakaszokcpp17Wrong answer 12/100171ms15996 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, n, comp(i.se.fi), i.fi.se / 1e5 * -1);
        }
        else{
            int cur = get(1, 1, n, comp(i.se.fi), comp(i.se.se));
            if (cur > maxi.fi){
                maxi = {cur, i.fi.se};
            }
        }
    }
    cout << maxi.second;
}
SubtaskSumTestVerdictTimeMemory
base12/100
1Accepted0/04ms4012 KiB
2Wrong answer0/039ms5708 KiB
3Accepted2/23ms4420 KiB
4Wrong answer0/26ms4948 KiB
5Wrong answer0/28ms5372 KiB
6Wrong answer0/318ms5928 KiB
7Accepted3/312ms6148 KiB
8Wrong answer0/328ms7048 KiB
9Wrong answer0/330ms7256 KiB
10Wrong answer0/430ms7456 KiB
11Wrong answer0/439ms7552 KiB
12Wrong answer0/459ms8256 KiB
13Wrong answer0/771ms8676 KiB
14Wrong answer0/787ms9032 KiB
15Wrong answer0/7104ms11368 KiB
16Time limit exceeded0/7152ms9388 KiB
17Wrong answer0/761ms8852 KiB
18Wrong answer0/7104ms11268 KiB
19Wrong answer0/7142ms11196 KiB
20Time limit exceeded0/7165ms9356 KiB
21Time limit exceeded0/7171ms9496 KiB
22Accepted7/7131ms15996 KiB