10975 | 2024-04-24 20:52:49 | MagyarKendeSZLG | Telefonközpont | cpp17 | Accepted 100/100 | 179ms | 14052 KiB |
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 2e5, INF = 1e9;
int t[4 * MAXN + 1], lazy[4 * MAXN + 1];
void build(const vector<int>& v, int curr, int tl, int tr) {
if (tl == tr) {
t[curr] = v[tl];
} else {
int tmid = (tl + tr) / 2;
build(v, curr * 2, tl, tmid);
build(v, curr * 2 + 1, tmid + 1, tr);
t[curr] = max(t[curr * 2], t[curr * 2 + 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;
}
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;
vector<int> v(M + 1);
while (N--) {
int B, E;
cin >> B >> E;
v[B - 1]++;
v[E]--;
}
for (int i = 1; i < M; i++) {
v[i] += v[i - 1];
}
build(v, 1, 0, M - 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 | 1836 KiB | ||||
2 | Accepted | 3ms | 2044 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 3ms | 2400 KiB | ||||
4 | Accepted | 3ms | 2596 KiB | ||||
5 | Accepted | 3ms | 2916 KiB | ||||
6 | Accepted | 3ms | 2764 KiB | ||||
7 | Accepted | 3ms | 3020 KiB | ||||
8 | Accepted | 3ms | 2976 KiB | ||||
9 | Accepted | 3ms | 3236 KiB | ||||
subtask3 | 20/20 | ||||||
10 | Accepted | 3ms | 2400 KiB | ||||
11 | Accepted | 3ms | 2596 KiB | ||||
12 | Accepted | 3ms | 2916 KiB | ||||
13 | Accepted | 3ms | 2764 KiB | ||||
14 | Accepted | 3ms | 3020 KiB | ||||
15 | Accepted | 3ms | 2976 KiB | ||||
16 | Accepted | 3ms | 3236 KiB | ||||
17 | Accepted | 6ms | 3516 KiB | ||||
18 | Accepted | 6ms | 3764 KiB | ||||
19 | Accepted | 6ms | 3840 KiB | ||||
20 | Accepted | 6ms | 4048 KiB | ||||
21 | Accepted | 6ms | 4132 KiB | ||||
22 | Accepted | 6ms | 4156 KiB | ||||
23 | Accepted | 6ms | 4364 KiB | ||||
subtask4 | 60/60 | ||||||
24 | Accepted | 3ms | 2400 KiB | ||||
25 | Accepted | 3ms | 2596 KiB | ||||
26 | Accepted | 3ms | 2916 KiB | ||||
27 | Accepted | 3ms | 2764 KiB | ||||
28 | Accepted | 3ms | 3020 KiB | ||||
29 | Accepted | 3ms | 2976 KiB | ||||
30 | Accepted | 3ms | 3236 KiB | ||||
31 | Accepted | 6ms | 3516 KiB | ||||
32 | Accepted | 6ms | 3764 KiB | ||||
33 | Accepted | 6ms | 3840 KiB | ||||
34 | Accepted | 6ms | 4048 KiB | ||||
35 | Accepted | 6ms | 4132 KiB | ||||
36 | Accepted | 6ms | 4156 KiB | ||||
37 | Accepted | 6ms | 4364 KiB | ||||
38 | Accepted | 179ms | 13740 KiB | ||||
39 | Accepted | 179ms | 13952 KiB | ||||
40 | Accepted | 172ms | 13920 KiB | ||||
41 | Accepted | 172ms | 14048 KiB | ||||
42 | Accepted | 172ms | 14052 KiB | ||||
43 | Accepted | 172ms | 13932 KiB | ||||
44 | Accepted | 178ms | 13952 KiB |