14022022-09-01 17:00:13Valaki2Szakaszokcpp14Accepted 100/100123ms19340 KiB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")

#define pb push_back

const int inf = 1e9 + 42;
const int maxn = 3e5 + 42;
int tree[1 + maxn];

struct fentree {

    int n;

    void update(int idx, int val) {
        while(idx <= maxn) {
            tree[idx] += val;
            idx += idx & (-idx);
        }
    }

    int pref_query(int idx) {
        int res = 0;
        while(idx > 0) {
            res += tree[idx];
            idx -= idx & (-idx);
        }
        return res;
    }

    int query(int ql, int qr) {
        return pref_query(qr) - pref_query(ql - 1);
    }

    fentree() : n(0) {}
    fentree(int n_) : n(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(b);
        compress.pb(c);
        events.pb({1, a, c, -inf, -inf, i});
        events.pb({3, b, c, -inf, -inf, i});
    }
    for(int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        events.pb({2, a, -inf, b, c, i});
        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) {
        if(e.y != -inf) {
            e.y = (lower_bound(compress.begin(), compress.end(), e.y) - compress.begin()) + 1;
        }
        if(e.y1 != -inf) {
            e.y1 = (lower_bound(compress.begin(), compress.end(), e.y1) - compress.begin()) + 1;
        }
        if(e.y2 != -inf) {
            e.y2 = (lower_bound(compress.begin(), compress.end(), e.y2) - compress.begin()) + 1;
        }
    }
    fentree my_tree(maxn);
    int ans = -1, best_cnt = 0;
    for(const 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);
        } else if(e.type == 2) {
            int cnt = my_tree.query(e.y1, e.y2);
            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);
        }
    }
    cout << ans + 1 << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/03ms2056 KiB
2Accepted0/024ms4632 KiB
3Accepted2/22ms2604 KiB
4Accepted2/24ms3048 KiB
5Accepted2/24ms3480 KiB
6Accepted3/310ms4144 KiB
7Accepted3/37ms3932 KiB
8Accepted3/317ms4992 KiB
9Accepted3/318ms5348 KiB
10Accepted4/418ms5024 KiB
11Accepted4/424ms5828 KiB
12Accepted4/437ms7324 KiB
13Accepted7/745ms7752 KiB
14Accepted7/754ms8540 KiB
15Accepted7/765ms11228 KiB
16Accepted7/7123ms18804 KiB
17Accepted7/739ms7284 KiB
18Accepted7/767ms11492 KiB
19Accepted7/786ms13228 KiB
20Accepted7/7123ms19232 KiB
21Accepted7/7123ms19284 KiB
22Accepted7/768ms19340 KiB