10707 | 2024-04-10 09:43:34 | szil | Telefonközpont | cpp17 | Accepted 100/100 | 128ms | 7432 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 300'001;
int pref[MAXN], a[MAXN], tree[2*MAXN], n, m, q;
void upd(int u, int k) {
tree[u += m] = k;
for (u /= 2; u >= 1; u /= 2) {
tree[u] = max(tree[2*u], tree[2*u+1]);
}
}
int qry(int l, int r) {
int res = 0; l += m; r += m;
while (l <= r) {
if (l % 2 == 1) res = max(res, tree[l++]);
if (r % 2 == 0) res = max(res, tree[r--]);
l /= 2; r /= 2;
}
return res;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> m >> n >> q;
for (int i = 1; i <= n; i++) {
int l, r; cin >> l >> r;
pref[l]++;
pref[r+1]--;
}
for (int i = 1; i <= m; i++) {
pref[i] += pref[i-1];
upd(i, pref[i]);
}
while (q--) {
int l, r; cin >> l >> r;
cout << qry(l, r) << "\n";
}
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1900 KiB | ||||
2 | Accepted | 3ms | 2108 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 3ms | 2304 KiB | ||||
4 | Accepted | 3ms | 2648 KiB | ||||
5 | Accepted | 3ms | 2604 KiB | ||||
6 | Accepted | 3ms | 2688 KiB | ||||
7 | Accepted | 3ms | 2860 KiB | ||||
8 | Accepted | 3ms | 2940 KiB | ||||
9 | Accepted | 3ms | 3024 KiB | ||||
subtask3 | 20/20 | ||||||
10 | Accepted | 3ms | 2304 KiB | ||||
11 | Accepted | 3ms | 2648 KiB | ||||
12 | Accepted | 3ms | 2604 KiB | ||||
13 | Accepted | 3ms | 2688 KiB | ||||
14 | Accepted | 3ms | 2860 KiB | ||||
15 | Accepted | 3ms | 2940 KiB | ||||
16 | Accepted | 3ms | 3024 KiB | ||||
17 | Accepted | 4ms | 3332 KiB | ||||
18 | Accepted | 4ms | 3284 KiB | ||||
19 | Accepted | 4ms | 3316 KiB | ||||
20 | Accepted | 4ms | 3280 KiB | ||||
21 | Accepted | 4ms | 3280 KiB | ||||
22 | Accepted | 4ms | 3284 KiB | ||||
23 | Accepted | 4ms | 3292 KiB | ||||
subtask4 | 60/60 | ||||||
24 | Accepted | 3ms | 2304 KiB | ||||
25 | Accepted | 3ms | 2648 KiB | ||||
26 | Accepted | 3ms | 2604 KiB | ||||
27 | Accepted | 3ms | 2688 KiB | ||||
28 | Accepted | 3ms | 2860 KiB | ||||
29 | Accepted | 3ms | 2940 KiB | ||||
30 | Accepted | 3ms | 3024 KiB | ||||
31 | Accepted | 4ms | 3332 KiB | ||||
32 | Accepted | 4ms | 3284 KiB | ||||
33 | Accepted | 4ms | 3316 KiB | ||||
34 | Accepted | 4ms | 3280 KiB | ||||
35 | Accepted | 4ms | 3280 KiB | ||||
36 | Accepted | 4ms | 3284 KiB | ||||
37 | Accepted | 4ms | 3292 KiB | ||||
38 | Accepted | 128ms | 6884 KiB | ||||
39 | Accepted | 127ms | 6900 KiB | ||||
40 | Accepted | 125ms | 7100 KiB | ||||
41 | Accepted | 123ms | 7212 KiB | ||||
42 | Accepted | 123ms | 7432 KiB | ||||
43 | Accepted | 123ms | 7424 KiB | ||||
44 | Accepted | 123ms | 7432 KiB |