#include<bits/stdc++.h>
using namespace std;
struct st {
int x, y, z, i;
};
vector<st> v;
struct fenwick {
int t[400010];
void upd(int n, int x) {
for(;n<=4e5;n+=n&-n)
t[n]+=x;
}
int q(int n) {
int x = 0;
for(;n;n-=n&-n)
x+=t[n];
return x;
}
int Q(int x) {
return q(4e5)-q(x-1);
}
} A,B;
int ans[100100];
map<int,int> mp;
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
for(int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
mp[a], mp[b];
v.push_back({a,b,a+b,0});
}
for(int i = 1; i <= q; i++) {
int x,y,z;
cin >> x >> y>> z;
mp[x],mp[y];
v.push_back({x,y,max(z,x+y),i});
}
sort(v.begin(),v.end(),[](st a, st b) {
return (a.z-b.z?a.z>b.z:a.i<b.i);
});
int cnt = 0;
for(auto &i: mp)
i.second=++cnt;
cnt=0;
for(auto i: v)
if(i.i)
ans[i.i]=A.Q(mp[i.x])+B.Q(mp[i.y])-cnt;
else
A.upd(mp[i.x],1),B.upd(mp[i.y],1),cnt++;
for(int i = 1; i <= q; i++)
cout << ans[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2508 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
6 ms |
1440 KB |
Output is correct |
8 |
Correct |
6 ms |
1460 KB |
Output is correct |
9 |
Correct |
6 ms |
1372 KB |
Output is correct |
10 |
Correct |
4 ms |
856 KB |
Output is correct |
11 |
Correct |
4 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
7 ms |
1416 KB |
Output is correct |
14 |
Correct |
6 ms |
3164 KB |
Output is correct |
15 |
Correct |
6 ms |
3272 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
11188 KB |
Output is correct |
2 |
Correct |
203 ms |
14008 KB |
Output is correct |
3 |
Correct |
208 ms |
12468 KB |
Output is correct |
4 |
Correct |
117 ms |
12108 KB |
Output is correct |
5 |
Correct |
118 ms |
11960 KB |
Output is correct |
6 |
Correct |
53 ms |
7616 KB |
Output is correct |
7 |
Correct |
200 ms |
13160 KB |
Output is correct |
8 |
Correct |
195 ms |
13240 KB |
Output is correct |
9 |
Correct |
176 ms |
12984 KB |
Output is correct |
10 |
Correct |
114 ms |
11400 KB |
Output is correct |
11 |
Correct |
113 ms |
12008 KB |
Output is correct |
12 |
Correct |
44 ms |
6608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
11188 KB |
Output is correct |
2 |
Correct |
203 ms |
14008 KB |
Output is correct |
3 |
Correct |
208 ms |
12468 KB |
Output is correct |
4 |
Correct |
117 ms |
12108 KB |
Output is correct |
5 |
Correct |
118 ms |
11960 KB |
Output is correct |
6 |
Correct |
53 ms |
7616 KB |
Output is correct |
7 |
Correct |
200 ms |
13160 KB |
Output is correct |
8 |
Correct |
195 ms |
13240 KB |
Output is correct |
9 |
Correct |
176 ms |
12984 KB |
Output is correct |
10 |
Correct |
114 ms |
11400 KB |
Output is correct |
11 |
Correct |
113 ms |
12008 KB |
Output is correct |
12 |
Correct |
44 ms |
6608 KB |
Output is correct |
13 |
Correct |
223 ms |
12728 KB |
Output is correct |
14 |
Correct |
207 ms |
13892 KB |
Output is correct |
15 |
Correct |
207 ms |
12384 KB |
Output is correct |
16 |
Correct |
129 ms |
13240 KB |
Output is correct |
17 |
Correct |
128 ms |
10904 KB |
Output is correct |
18 |
Correct |
54 ms |
7616 KB |
Output is correct |
19 |
Correct |
211 ms |
13236 KB |
Output is correct |
20 |
Correct |
205 ms |
14000 KB |
Output is correct |
21 |
Correct |
203 ms |
12980 KB |
Output is correct |
22 |
Correct |
111 ms |
12584 KB |
Output is correct |
23 |
Correct |
125 ms |
11488 KB |
Output is correct |
24 |
Correct |
43 ms |
7120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
2508 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
460 KB |
Output is correct |
7 |
Correct |
6 ms |
1440 KB |
Output is correct |
8 |
Correct |
6 ms |
1460 KB |
Output is correct |
9 |
Correct |
6 ms |
1372 KB |
Output is correct |
10 |
Correct |
4 ms |
856 KB |
Output is correct |
11 |
Correct |
4 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
2652 KB |
Output is correct |
13 |
Correct |
7 ms |
1416 KB |
Output is correct |
14 |
Correct |
6 ms |
3164 KB |
Output is correct |
15 |
Correct |
6 ms |
3272 KB |
Output is correct |
16 |
Correct |
4 ms |
860 KB |
Output is correct |
17 |
Correct |
4 ms |
860 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
205 ms |
11188 KB |
Output is correct |
20 |
Correct |
203 ms |
14008 KB |
Output is correct |
21 |
Correct |
208 ms |
12468 KB |
Output is correct |
22 |
Correct |
117 ms |
12108 KB |
Output is correct |
23 |
Correct |
118 ms |
11960 KB |
Output is correct |
24 |
Correct |
53 ms |
7616 KB |
Output is correct |
25 |
Correct |
200 ms |
13160 KB |
Output is correct |
26 |
Correct |
195 ms |
13240 KB |
Output is correct |
27 |
Correct |
176 ms |
12984 KB |
Output is correct |
28 |
Correct |
114 ms |
11400 KB |
Output is correct |
29 |
Correct |
113 ms |
12008 KB |
Output is correct |
30 |
Correct |
44 ms |
6608 KB |
Output is correct |
31 |
Correct |
223 ms |
12728 KB |
Output is correct |
32 |
Correct |
207 ms |
13892 KB |
Output is correct |
33 |
Correct |
207 ms |
12384 KB |
Output is correct |
34 |
Correct |
129 ms |
13240 KB |
Output is correct |
35 |
Correct |
128 ms |
10904 KB |
Output is correct |
36 |
Correct |
54 ms |
7616 KB |
Output is correct |
37 |
Correct |
211 ms |
13236 KB |
Output is correct |
38 |
Correct |
205 ms |
14000 KB |
Output is correct |
39 |
Correct |
203 ms |
12980 KB |
Output is correct |
40 |
Correct |
111 ms |
12584 KB |
Output is correct |
41 |
Correct |
125 ms |
11488 KB |
Output is correct |
42 |
Correct |
43 ms |
7120 KB |
Output is correct |
43 |
Correct |
453 ms |
31284 KB |
Output is correct |
44 |
Correct |
454 ms |
31416 KB |
Output is correct |
45 |
Correct |
456 ms |
31668 KB |
Output is correct |
46 |
Correct |
172 ms |
19672 KB |
Output is correct |
47 |
Correct |
170 ms |
18004 KB |
Output is correct |
48 |
Correct |
58 ms |
6352 KB |
Output is correct |
49 |
Correct |
455 ms |
31348 KB |
Output is correct |
50 |
Correct |
469 ms |
31072 KB |
Output is correct |
51 |
Correct |
415 ms |
30904 KB |
Output is correct |
52 |
Correct |
184 ms |
18716 KB |
Output is correct |
53 |
Correct |
149 ms |
19192 KB |
Output is correct |