13972022-08-31 20:12:31Valaki2Szakaszokcpp14Time limit exceeded 79/100190ms23004 KiB
#include <bits/stdc++.h>
using namespace std;

#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/03ms1956 KiB
2Accepted0/035ms5984 KiB
3Accepted2/22ms2448 KiB
4Accepted2/24ms3048 KiB
5Accepted2/27ms3680 KiB
6Accepted3/317ms4704 KiB
7Accepted3/38ms4400 KiB
8Accepted3/327ms5928 KiB
9Accepted3/328ms6112 KiB
10Accepted4/428ms6292 KiB
11Accepted4/435ms6876 KiB
12Accepted4/454ms9456 KiB
13Accepted7/768ms10176 KiB
14Accepted7/785ms11660 KiB
15Accepted7/7103ms12972 KiB
16Time limit exceeded0/7160ms12708 KiB
17Accepted7/759ms9972 KiB
18Accepted7/7103ms13084 KiB
19Accepted7/7131ms17380 KiB
20Time limit exceeded0/7190ms23004 KiB
21Time limit exceeded0/7162ms12760 KiB
22Accepted7/797ms20348 KiB