13952022-08-31 20:09:56Valaki2Szakaszokcpp14Runtime error 0/1003ms3720 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back

const int inf = 1e9 + 42;
const int maxn = 1e6;
int tree[1 + 4 * maxn];

struct segtree {

    int n;

    void build(const vector<int> &arr, int v, int vl, int vr) {
        if(vl == vr) {
            tree[v] = arr[vl];
        } else {
            int mid = (vl + vr) / 2;
            build(arr, 2 * v, vl, mid);
            build(arr, 2 * v + 1, mid + 1, vr);
            tree[v] = tree[2 * v] + tree[2 * v + 1];
        }
    }

    void update(int pos, int val, int v, int vl, int vr) {
        if(vl == vr) {
            tree[v] += val;
        } else {
            int mid = (vl + vr) / 2;
            if(pos <= mid) {
                update(pos, val, 2 * v, vl, mid);
            } else {
                update(pos, val, 2 * v + 1, mid + 1, vr);
            }
            tree[v] = tree[2 * v] + tree[2 * v + 1];
        }
    }

    int query(int ql, int qr, int v, int vl, int vr) {
        if(qr < vl || ql > vr) {
            return 0;
        }
        if(ql == vl && qr == vr) {
            return tree[v];
        } else {
            int mid = (vl + vr) / 2;
            return (query(ql, min(qr, mid), 2 * v, vl, mid) +
                query(max(ql, mid + 1), qr, 2 * v + 1, mid + 1, vr));
        }
    }

    segtree() : n(0) {}
    segtree(int n_) : n(n_) {}
    segtree(int n_, const vector<int> &arr) : n(n_) {
        build(arr, 1, 1, n_);
    }

};

struct event {
    int type, x, y, y1, y2, id;
    bool operator < (const event &other) const {
        if(x == other.x) {
            return type < other.type;
        }
        return x < other.x;
    }
};

void solve() {
    int m, n;
    cin >> m >> n;
    vector<event> events;
    vector<int> compress;
    for(int i = 0; i < m; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        compress.pb(a);
        compress.pb(b);
        compress.pb(c);
        events.pb({1, a, c, 0, 0, i});
        events.pb({3, b, c, 0, 0, i});
    }
    for(int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        events.pb({2, a, 0, b, c, i});
        compress.pb(a);
        compress.pb(b);
        compress.pb(c);
    }
    sort(events.begin(), events.end());
    sort(compress.begin(), compress.end());
    compress.resize(unique(compress.begin(), compress.end()) - compress.begin());
    for(event &e : events) {
        e.x = (lower_bound(compress.begin(), compress.end(), e.x) - compress.begin()) + 1;
        e.y = (lower_bound(compress.begin(), compress.end(), e.y) - compress.begin()) + 1;
        e.y1 = (lower_bound(compress.begin(), compress.end(), e.y1) - compress.begin()) + 1;
        e.y2 = (lower_bound(compress.begin(), compress.end(), e.y2) - compress.begin()) + 1;
    }
    segtree my_tree(maxn);
    int ans = -1, best_cnt = 0;
    for(event e : events) {
        //cout << e.type << " " << e.x << " " << e.y << " " << e.y1 << " " << e.y2 << "\n";
        if(e.type == 1) {
            my_tree.update(e.y, 1, 1, 1, maxn);
        } else if(e.type == 2) {
            int cnt = my_tree.query(e.y1, e.y2, 1, 1, maxn);
            if(cnt > best_cnt) {
                best_cnt = cnt;
                ans = e.id;
            } else if(cnt == best_cnt && ans > e.id) {
                ans = e.id;
            }
        } else {
            my_tree.update(e.y, -1, 1, 1, maxn);
        }
    }
    cout << ans + 1 << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/100
1Runtime error0/03ms1324 KiB
2Runtime error0/02ms1464 KiB
3Runtime error0/22ms1668 KiB
4Runtime error0/22ms1860 KiB
5Runtime error0/22ms2052 KiB
6Runtime error0/32ms2196 KiB
7Runtime error0/32ms2312 KiB
8Runtime error0/32ms2308 KiB
9Runtime error0/32ms2572 KiB
10Runtime error0/42ms2760 KiB
11Runtime error0/42ms2948 KiB
12Runtime error0/42ms3004 KiB
13Runtime error0/72ms3004 KiB
14Runtime error0/72ms3064 KiB
15Runtime error0/72ms3136 KiB
16Runtime error0/72ms3200 KiB
17Runtime error0/72ms3184 KiB
18Runtime error0/72ms3288 KiB
19Runtime error0/72ms3420 KiB
20Runtime error0/72ms3464 KiB
21Runtime error0/72ms3676 KiB
22Runtime error0/72ms3720 KiB