10800 | 2024-04-14 11:47:24 | Ablablabla | Telefonközpont | cpp17 | Accepted 100/100 | 152ms | 8996 KiB |
#include <bits/stdc++.h>
using namespace std;
struct segTree{
int meret = 1;
vector<int> fa;
void meretez(int n){
while(meret < n){
meret *= 2;
}
fa.assign(2 * meret - 1, 0);
}
int epit(int a, int b, int ind){
if(a == b){
return fa[ind];
}
int k = (a + b) / 2;
return fa[ind] = max(epit(a, k, 2 * ind + 1), epit(k + 1, b, 2 * ind + 2));
}
int keres(int a, int b, int ind, int kezd, int veg){
if(veg < a || b < kezd){
return 0;
} else if(kezd <= a && b <= veg){
return fa[ind];
}
int k = (a + b) / 2;
return max(keres(a, k, 2 * ind + 1, kezd, veg), keres(k + 1, b, 2 * ind + 2, kezd, veg));
}
};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int m, n, q;
cin >> m >> n >> q;
vector<int> helyek(m + 1);
for(int i = 0; i < n; i++){
int a, b;
cin >> a >> b;
a--;
helyek[a]++;
helyek[b]--;
}
segTree fa;
fa.meretez(m);
int akt = 0;
for(int i = 0; i < m; i++){
akt += helyek[i];
fa.fa[i + fa.meret - 1] = akt;
}
fa.epit(0, fa.meret -1, 0);
while(q--){
int a, b;
cin >> a >> b;
a--; b--;
cout << fa.keres(0, fa.meret - 1, 0, a, b) << "\n";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1824 KiB | ||||
2 | Accepted | 3ms | 2052 KiB | ||||
subtask2 | 20/20 | ||||||
3 | Accepted | 3ms | 2148 KiB | ||||
4 | Accepted | 3ms | 2148 KiB | ||||
5 | Accepted | 3ms | 2276 KiB | ||||
6 | Accepted | 3ms | 2484 KiB | ||||
7 | Accepted | 3ms | 2808 KiB | ||||
8 | Accepted | 3ms | 2904 KiB | ||||
9 | Accepted | 3ms | 2888 KiB | ||||
subtask3 | 20/20 | ||||||
10 | Accepted | 3ms | 2148 KiB | ||||
11 | Accepted | 3ms | 2148 KiB | ||||
12 | Accepted | 3ms | 2276 KiB | ||||
13 | Accepted | 3ms | 2484 KiB | ||||
14 | Accepted | 3ms | 2808 KiB | ||||
15 | Accepted | 3ms | 2904 KiB | ||||
16 | Accepted | 3ms | 2888 KiB | ||||
17 | Accepted | 6ms | 2968 KiB | ||||
18 | Accepted | 6ms | 3228 KiB | ||||
19 | Accepted | 6ms | 3216 KiB | ||||
20 | Accepted | 6ms | 3232 KiB | ||||
21 | Accepted | 6ms | 3224 KiB | ||||
22 | Accepted | 6ms | 3508 KiB | ||||
23 | Accepted | 6ms | 3412 KiB | ||||
subtask4 | 60/60 | ||||||
24 | Accepted | 3ms | 2148 KiB | ||||
25 | Accepted | 3ms | 2148 KiB | ||||
26 | Accepted | 3ms | 2276 KiB | ||||
27 | Accepted | 3ms | 2484 KiB | ||||
28 | Accepted | 3ms | 2808 KiB | ||||
29 | Accepted | 3ms | 2904 KiB | ||||
30 | Accepted | 3ms | 2888 KiB | ||||
31 | Accepted | 6ms | 2968 KiB | ||||
32 | Accepted | 6ms | 3228 KiB | ||||
33 | Accepted | 6ms | 3216 KiB | ||||
34 | Accepted | 6ms | 3232 KiB | ||||
35 | Accepted | 6ms | 3224 KiB | ||||
36 | Accepted | 6ms | 3508 KiB | ||||
37 | Accepted | 6ms | 3412 KiB | ||||
38 | Accepted | 152ms | 8440 KiB | ||||
39 | Accepted | 151ms | 8444 KiB | ||||
40 | Accepted | 148ms | 8692 KiB | ||||
41 | Accepted | 146ms | 8676 KiB | ||||
42 | Accepted | 145ms | 8748 KiB | ||||
43 | Accepted | 146ms | 8988 KiB | ||||
44 | Accepted | 149ms | 8996 KiB |