#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define orta ((bas+son)/2)
#define mod 1000000007
#define inf 1000000009
#define LOGN 30
#define N 100005
#define M N * LOGN * LOGN
using namespace std;
typedef long long ll;
typedef pair < int , int > ii;
int n, m, k, q, say1 = 1, say2, seg1[N * LOGN], sol1[N * LOGN], sag1[N * LOGN], seg2[M], sol2[M], sag2[M], bs[M], sn[M], ans[N];
pair < int , ii > a[N];
pair < ii , ii > b[N];
int ver(int k){return seg1[k] = (!seg1[k])?++say2:seg1[k];}
int solver1(int k){return sol1[k] = (!sol1[k])?++say1:sol1[k];}
int sagver1(int k){return sag1[k] = (!sag1[k])?++say1:sag1[k];}
int solver2(int k){return sol2[k] = (!sol2[k])?++say2:sol2[k];}
int sagver2(int k){return sag2[k] = (!sag2[k])?++say2:sag2[k];}
void up2(int k, int bas, int son, int x){
if(bas == son){
seg2[k]++;
return;
}
if(x <= orta)
up2(solver2(k), bas, orta, x);
else
up2(sagver2(k), orta + 1, son, x);
seg2[k] = seg2[sol2[k]] + seg2[sag2[k]];
}
void up1(int k, int bas, int son, int x, int y){
if(bas == son){
up2(ver(k), 1, m, y);
// cout << bas << " " << son << " " << ver(k) << " a " << y << " artti" << endl;
return;
}
if(x <= orta)
up1(solver1(k), bas, orta, x, y);
else
up1(sagver1(k), orta + 1, son, x, y);
// cout << bas << " " << son << " " << ver(k) << " a " << y << " artti" << endl;
up2(ver(k), 1, m, y);
}
int qu2(int k, int bas, int son, int x){
if(!k or son < x)
return 0;
if(bas >= x)
return seg2[k];
return qu2(sol2[k], bas, orta, x) + qu2(sag2[k], orta + 1, son, x);
}
int qu1(int k, int bas, int son, int x, int y){
if(!k or son < x)
return 0;
if(bas >= x){
// cout << bas << " " << son << " " << seg1[k] << " " << y << " = " << qu2(seg1[k], 1, m, y) << endl;
return qu2(seg1[k], 1, m, y);
}
return qu1(sol1[k], bas, orta, x, y) + qu1(sag1[k], orta + 1, son, x, y);
}
map < int , int > h, hh, x, xx;
map < int , int > :: iterator it;
int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%d %d",&k ,&q);
for(int i = 1; i <= k; i++){
scanf("%d %d",&a[i].nd.st ,&a[i].nd.nd);
a[i].st = a[i].nd.st + a[i].nd.nd;
h[a[i].nd.st] = 1;
hh[a[i].nd.nd] = 1;
}
sort(a + 1, a + k + 1);
for(int i = 1; i <= q; i++){
scanf("%d %d %d" ,&b[i].nd.st ,&b[i].nd.nd,&b[i].st.st);
h[b[i].nd.st] = 1;
hh[b[i].nd.nd] = 1;
b[i].st.nd = i;
}
for(it = h.begin(); it != h.end(); it++)
x[it->st] = ++n;
for(it = hh.begin(); it != hh.end(); it++)
xx[it->st] = ++m;
// cout << n << " " << m << endl;
sort(b + 1, b + q + 1);
reverse(b + 1, b + q + 1);
for(int i = 1; i <= q; i++){
while(k >= 1 and a[k].st >= b[i].st.st){
// cout << ne[a[k].nd.st] << " " << nee[a[k].nd.nd] << " geldi" << endl << endl;
up1(1, 1, n, x[a[k].nd.st], xx[a[k].nd.nd]);
k--;
}
// cout << b[i].st.nd << " icin bul " << n << " " << m << endl;
ans[b[i].st.nd] = qu1(1, 1, n, x[b[i].nd.st], xx[b[i].nd.nd] );
}
for(int i = 1; i <= q; i++)
printf("%d\n", ans[i]);
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&k ,&q);
~~~~~^~~~~~~~~~~~~~~~
examination.cpp:79:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&a[i].nd.st ,&a[i].nd.nd);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d" ,&b[i].nd.st ,&b[i].nd.nd,&b[i].st.st);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
28 ms |
5752 KB |
Output is correct |
8 |
Correct |
28 ms |
5752 KB |
Output is correct |
9 |
Correct |
27 ms |
5752 KB |
Output is correct |
10 |
Correct |
12 ms |
1784 KB |
Output is correct |
11 |
Correct |
12 ms |
1784 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
28 ms |
5752 KB |
Output is correct |
14 |
Correct |
28 ms |
5752 KB |
Output is correct |
15 |
Correct |
30 ms |
5752 KB |
Output is correct |
16 |
Correct |
9 ms |
1272 KB |
Output is correct |
17 |
Correct |
10 ms |
1272 KB |
Output is correct |
18 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2390 ms |
210664 KB |
Output is correct |
2 |
Correct |
2550 ms |
210624 KB |
Output is correct |
3 |
Correct |
2443 ms |
210580 KB |
Output is correct |
4 |
Correct |
477 ms |
29380 KB |
Output is correct |
5 |
Correct |
463 ms |
27664 KB |
Output is correct |
6 |
Correct |
97 ms |
4088 KB |
Output is correct |
7 |
Correct |
2162 ms |
200080 KB |
Output is correct |
8 |
Correct |
2267 ms |
200568 KB |
Output is correct |
9 |
Correct |
1892 ms |
190328 KB |
Output is correct |
10 |
Correct |
306 ms |
15480 KB |
Output is correct |
11 |
Correct |
356 ms |
16032 KB |
Output is correct |
12 |
Correct |
72 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2390 ms |
210664 KB |
Output is correct |
2 |
Correct |
2550 ms |
210624 KB |
Output is correct |
3 |
Correct |
2443 ms |
210580 KB |
Output is correct |
4 |
Correct |
477 ms |
29380 KB |
Output is correct |
5 |
Correct |
463 ms |
27664 KB |
Output is correct |
6 |
Correct |
97 ms |
4088 KB |
Output is correct |
7 |
Correct |
2162 ms |
200080 KB |
Output is correct |
8 |
Correct |
2267 ms |
200568 KB |
Output is correct |
9 |
Correct |
1892 ms |
190328 KB |
Output is correct |
10 |
Correct |
306 ms |
15480 KB |
Output is correct |
11 |
Correct |
356 ms |
16032 KB |
Output is correct |
12 |
Correct |
72 ms |
3704 KB |
Output is correct |
13 |
Correct |
2144 ms |
210680 KB |
Output is correct |
14 |
Correct |
2438 ms |
210704 KB |
Output is correct |
15 |
Correct |
2504 ms |
210556 KB |
Output is correct |
16 |
Correct |
456 ms |
29476 KB |
Output is correct |
17 |
Correct |
446 ms |
27748 KB |
Output is correct |
18 |
Correct |
109 ms |
4088 KB |
Output is correct |
19 |
Correct |
2191 ms |
210824 KB |
Output is correct |
20 |
Correct |
2250 ms |
210736 KB |
Output is correct |
21 |
Correct |
1919 ms |
203276 KB |
Output is correct |
22 |
Correct |
363 ms |
15532 KB |
Output is correct |
23 |
Correct |
345 ms |
16284 KB |
Output is correct |
24 |
Correct |
74 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
28 ms |
5752 KB |
Output is correct |
8 |
Correct |
28 ms |
5752 KB |
Output is correct |
9 |
Correct |
27 ms |
5752 KB |
Output is correct |
10 |
Correct |
12 ms |
1784 KB |
Output is correct |
11 |
Correct |
12 ms |
1784 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
28 ms |
5752 KB |
Output is correct |
14 |
Correct |
28 ms |
5752 KB |
Output is correct |
15 |
Correct |
30 ms |
5752 KB |
Output is correct |
16 |
Correct |
9 ms |
1272 KB |
Output is correct |
17 |
Correct |
10 ms |
1272 KB |
Output is correct |
18 |
Correct |
4 ms |
504 KB |
Output is correct |
19 |
Correct |
2390 ms |
210664 KB |
Output is correct |
20 |
Correct |
2550 ms |
210624 KB |
Output is correct |
21 |
Correct |
2443 ms |
210580 KB |
Output is correct |
22 |
Correct |
477 ms |
29380 KB |
Output is correct |
23 |
Correct |
463 ms |
27664 KB |
Output is correct |
24 |
Correct |
97 ms |
4088 KB |
Output is correct |
25 |
Correct |
2162 ms |
200080 KB |
Output is correct |
26 |
Correct |
2267 ms |
200568 KB |
Output is correct |
27 |
Correct |
1892 ms |
190328 KB |
Output is correct |
28 |
Correct |
306 ms |
15480 KB |
Output is correct |
29 |
Correct |
356 ms |
16032 KB |
Output is correct |
30 |
Correct |
72 ms |
3704 KB |
Output is correct |
31 |
Correct |
2144 ms |
210680 KB |
Output is correct |
32 |
Correct |
2438 ms |
210704 KB |
Output is correct |
33 |
Correct |
2504 ms |
210556 KB |
Output is correct |
34 |
Correct |
456 ms |
29476 KB |
Output is correct |
35 |
Correct |
446 ms |
27748 KB |
Output is correct |
36 |
Correct |
109 ms |
4088 KB |
Output is correct |
37 |
Correct |
2191 ms |
210824 KB |
Output is correct |
38 |
Correct |
2250 ms |
210736 KB |
Output is correct |
39 |
Correct |
1919 ms |
203276 KB |
Output is correct |
40 |
Correct |
363 ms |
15532 KB |
Output is correct |
41 |
Correct |
345 ms |
16284 KB |
Output is correct |
42 |
Correct |
74 ms |
3704 KB |
Output is correct |
43 |
Correct |
2725 ms |
285860 KB |
Output is correct |
44 |
Correct |
2763 ms |
290636 KB |
Output is correct |
45 |
Execution timed out |
3037 ms |
290596 KB |
Time limit exceeded |
46 |
Halted |
0 ms |
0 KB |
- |