10974 | 2024-04-24 20:35:10 | MagyarKendeSZLG | Telefonközpont | cpp17 | Time limit exceeded 40/100 | 582ms | 7432 KiB |
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 2e5, INF = 1e9;
int t[4 * MAXN + 1], lazy[4 * MAXN + 1];
void push(int curr) {
t[curr * 2] += lazy[curr];
t[curr * 2 + 1] += lazy[curr];
lazy[curr * 2] += lazy[curr];
lazy[curr * 2 + 1] += lazy[curr];
lazy[curr] = 0;
}
void update(int curr, int tl, int tr, int l, int r) {
if (tr < tl || r < l) {
return;
}
if (tr == tl) {
t[curr]++;
lazy[curr]++;
} else {
push(curr);
int tmid = (tl + tr) / 2;
update(curr * 2, tl, tmid, l, min(tmid, r));
update(curr * 2 + 1, tmid + 1, tr, max(tmid + 1, l), r);
t[curr] = max(t[curr * 2], t[curr * 2 + 1]);
}
}
int query(int curr, int tl, int tr, int l, int r) {
if (tr < tl || r < l) {
return -INF;
}
if (tl == l && tr == r) {
return t[curr];
}
push(curr);
int tmid = (tl + tr) / 2;
return max(
query(curr * 2, tl, tmid, l, min(tmid, r)),
query(curr * 2 + 1, tmid + 1, tr, max(l, tmid + 1), r)
);
}
int main() {
cin.tie(0), ios::sync_with_stdio(0);
int M, N, Q;
cin >> M >> N >> Q;
while (N--) {
int B, E;
cin >> B >> E;
update(1, 0, M - 1, B - 1, E - 1);
}
while (Q--) {
int B, E;
cin >> B >> E;
cout << query(1, 0, M - 1, B - 1, E - 1) << "\n";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1912 KiB | ||||
2 | Accepted | 3ms | 2108 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 4ms | 2468 KiB | ||||
4 | Accepted | 4ms | 2676 KiB | ||||
5 | Accepted | 4ms | 2992 KiB | ||||
6 | Accepted | 4ms | 3204 KiB | ||||
7 | Accepted | 4ms | 3516 KiB | ||||
8 | Accepted | 4ms | 3852 KiB | ||||
9 | Accepted | 4ms | 3944 KiB | ||||
subtask3 | 20/20 | ||||||
10 | Accepted | 4ms | 2468 KiB | ||||
11 | Accepted | 4ms | 2676 KiB | ||||
12 | Accepted | 4ms | 2992 KiB | ||||
13 | Accepted | 4ms | 3204 KiB | ||||
14 | Accepted | 4ms | 3516 KiB | ||||
15 | Accepted | 4ms | 3852 KiB | ||||
16 | Accepted | 4ms | 3944 KiB | ||||
17 | Accepted | 111ms | 3956 KiB | ||||
18 | Accepted | 179ms | 4012 KiB | ||||
19 | Accepted | 111ms | 4096 KiB | ||||
20 | Accepted | 112ms | 4248 KiB | ||||
21 | Accepted | 144ms | 4224 KiB | ||||
22 | Accepted | 178ms | 4080 KiB | ||||
23 | Accepted | 203ms | 4068 KiB | ||||
subtask4 | 0/60 | ||||||
24 | Accepted | 4ms | 2468 KiB | ||||
25 | Accepted | 4ms | 2676 KiB | ||||
26 | Accepted | 4ms | 2992 KiB | ||||
27 | Accepted | 4ms | 3204 KiB | ||||
28 | Accepted | 4ms | 3516 KiB | ||||
29 | Accepted | 4ms | 3852 KiB | ||||
30 | Accepted | 4ms | 3944 KiB | ||||
31 | Accepted | 111ms | 3956 KiB | ||||
32 | Accepted | 179ms | 4012 KiB | ||||
33 | Accepted | 111ms | 4096 KiB | ||||
34 | Accepted | 112ms | 4248 KiB | ||||
35 | Accepted | 144ms | 4224 KiB | ||||
36 | Accepted | 178ms | 4080 KiB | ||||
37 | Accepted | 203ms | 4068 KiB | ||||
38 | Time limit exceeded | 575ms | 7100 KiB | ||||
39 | Time limit exceeded | 574ms | 7176 KiB | ||||
40 | Time limit exceeded | 565ms | 7248 KiB | ||||
41 | Time limit exceeded | 546ms | 7164 KiB | ||||
42 | Time limit exceeded | 582ms | 7432 KiB | ||||
43 | Time limit exceeded | 550ms | 7372 KiB | ||||
44 | Time limit exceeded | 582ms | 7376 KiB |