13982022-08-31 20:14:44Valaki2Szakaszokcpp14Time limit exceeded 79/100182ms20276 KiB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize ("Ofast","unroll-loops")
#pragma GCC target ("avx2")

#define pb push_back

const int inf = 1e9 + 42;
const int maxn = 3e5 + 42;
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;
    }
};

vector<event> events;
vector<int> compress;

void solve() {
    int m, n;
    cin >> m >> n;
    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
base79/100
1Accepted0/03ms2060 KiB
2Accepted0/039ms5944 KiB
3Accepted2/22ms2488 KiB
4Accepted2/24ms3072 KiB
5Accepted2/27ms3364 KiB
6Accepted3/317ms4500 KiB
7Accepted3/39ms4136 KiB
8Accepted3/329ms5860 KiB
9Accepted3/330ms6172 KiB
10Accepted4/432ms6468 KiB
11Accepted4/439ms7380 KiB
12Accepted4/461ms9932 KiB
13Accepted7/778ms10672 KiB
14Accepted7/797ms12060 KiB
15Accepted7/7116ms13300 KiB
16Time limit exceeded0/7160ms11996 KiB
17Accepted7/765ms10192 KiB
18Accepted7/7118ms13364 KiB
19Accepted7/7146ms17740 KiB
20Time limit exceeded0/7165ms13096 KiB
21Time limit exceeded0/7182ms13204 KiB
22Accepted7/7109ms20276 KiB