#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
struct event{
int x;
int x2;
int y;
int y2;
int typ;
};
event pts[400003];
void init(int &n, int &q){
cin >> n >> q;
set<int> s;
map<int,int> mp;
for (int i = 1; i<=n; i++){
cin >> pts[i].x >> pts[i].y;
pts[i].x2=pts[i].x+pts[i].y;
s.insert(pts[i].y);
}
for (int i = n+1; i<=n+q; i++){
cin >> pts[i].x >> pts[i].y >> pts[i].y2;
pts[i].x2=max(pts[i].y2,pts[i].x+pts[i].y);
pts[i].y2=max(pts[i].y,pts[i].y2-pts[i].x);
pts[i].typ=1;
s.insert(pts[i].y);
s.insert(pts[i].y2);
}
int iter=0;
for (auto u : s){
mp[u]=iter++;
}
for (int i = 1; i<=n; i++)pts[i].y=mp[pts[i].y];
for (int i = n+1; i<=n+q; i++){
pts[i].y=mp[pts[i].y];
pts[i].y2=mp[pts[i].y2];
}
}
int ans[100002];
vector<pii> zap;
const int base=1<<19;
int tree[2*base];
void change(int v){
v+=base;
while(v){
tree[v]++;
v>>=1;
}
}
int sum(int a, int b){
a+=base-1;
b+=base+1;
int wyn=0;
while(a/2!=b/2){
if (!(a&1))wyn+=tree[a+1];
if (b&1)wyn+=tree[b-1];
a>>=1;
b>>=1;
}
return wyn;
}
bool sorting(pii a, pii b){
if (a.first==b.first)return a.second<b.second;
return a.first>b.first;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n,q;
init(n,q);
for (int i = 1; i<=n+q; i++){
zap.push_back({pts[i].x,i});
}
sort(zap.begin(),zap.end(),sorting);
for (auto [x0,ind] : zap){
if (pts[ind].typ==0)change(pts[ind].y);
else ans[ind-n]+=sum(pts[ind].y2+1,base-2);
}
fill(tree,tree+2*base,0);
zap.clear();
for (int i = 1; i<=n+q; i++){
zap.push_back({pts[i].x2,i});
}
sort(zap.begin(),zap.end(),sorting);
for (auto [x0,ind] : zap){
if (pts[ind].typ==0)change(pts[ind].y);
else ans[ind-n]+=sum(pts[ind].y,pts[ind].y2);
}
for (int i = 1; i<=q; i++)cout << ans[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
8 ms |
5468 KB |
Output is correct |
8 |
Correct |
7 ms |
5464 KB |
Output is correct |
9 |
Correct |
7 ms |
5456 KB |
Output is correct |
10 |
Correct |
5 ms |
4952 KB |
Output is correct |
11 |
Correct |
7 ms |
5468 KB |
Output is correct |
12 |
Correct |
4 ms |
4700 KB |
Output is correct |
13 |
Correct |
6 ms |
5212 KB |
Output is correct |
14 |
Correct |
6 ms |
5344 KB |
Output is correct |
15 |
Correct |
6 ms |
5212 KB |
Output is correct |
16 |
Correct |
6 ms |
5212 KB |
Output is correct |
17 |
Correct |
5 ms |
4728 KB |
Output is correct |
18 |
Correct |
4 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
19796 KB |
Output is correct |
2 |
Correct |
197 ms |
19828 KB |
Output is correct |
3 |
Correct |
196 ms |
19816 KB |
Output is correct |
4 |
Correct |
91 ms |
12744 KB |
Output is correct |
5 |
Correct |
194 ms |
19280 KB |
Output is correct |
6 |
Correct |
93 ms |
11968 KB |
Output is correct |
7 |
Correct |
206 ms |
19968 KB |
Output is correct |
8 |
Correct |
179 ms |
18000 KB |
Output is correct |
9 |
Correct |
176 ms |
17928 KB |
Output is correct |
10 |
Correct |
200 ms |
18960 KB |
Output is correct |
11 |
Correct |
89 ms |
12700 KB |
Output is correct |
12 |
Correct |
82 ms |
11624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
19796 KB |
Output is correct |
2 |
Correct |
197 ms |
19828 KB |
Output is correct |
3 |
Correct |
196 ms |
19816 KB |
Output is correct |
4 |
Correct |
91 ms |
12744 KB |
Output is correct |
5 |
Correct |
194 ms |
19280 KB |
Output is correct |
6 |
Correct |
93 ms |
11968 KB |
Output is correct |
7 |
Correct |
206 ms |
19968 KB |
Output is correct |
8 |
Correct |
179 ms |
18000 KB |
Output is correct |
9 |
Correct |
176 ms |
17928 KB |
Output is correct |
10 |
Correct |
200 ms |
18960 KB |
Output is correct |
11 |
Correct |
89 ms |
12700 KB |
Output is correct |
12 |
Correct |
82 ms |
11624 KB |
Output is correct |
13 |
Correct |
236 ms |
22704 KB |
Output is correct |
14 |
Correct |
202 ms |
20564 KB |
Output is correct |
15 |
Correct |
200 ms |
19904 KB |
Output is correct |
16 |
Correct |
131 ms |
16408 KB |
Output is correct |
17 |
Correct |
210 ms |
20048 KB |
Output is correct |
18 |
Correct |
94 ms |
11976 KB |
Output is correct |
19 |
Correct |
230 ms |
22608 KB |
Output is correct |
20 |
Correct |
221 ms |
21428 KB |
Output is correct |
21 |
Correct |
247 ms |
23376 KB |
Output is correct |
22 |
Correct |
202 ms |
19028 KB |
Output is correct |
23 |
Correct |
86 ms |
12484 KB |
Output is correct |
24 |
Correct |
76 ms |
11720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
8 ms |
5468 KB |
Output is correct |
8 |
Correct |
7 ms |
5464 KB |
Output is correct |
9 |
Correct |
7 ms |
5456 KB |
Output is correct |
10 |
Correct |
5 ms |
4952 KB |
Output is correct |
11 |
Correct |
7 ms |
5468 KB |
Output is correct |
12 |
Correct |
4 ms |
4700 KB |
Output is correct |
13 |
Correct |
6 ms |
5212 KB |
Output is correct |
14 |
Correct |
6 ms |
5344 KB |
Output is correct |
15 |
Correct |
6 ms |
5212 KB |
Output is correct |
16 |
Correct |
6 ms |
5212 KB |
Output is correct |
17 |
Correct |
5 ms |
4728 KB |
Output is correct |
18 |
Correct |
4 ms |
4700 KB |
Output is correct |
19 |
Correct |
205 ms |
19796 KB |
Output is correct |
20 |
Correct |
197 ms |
19828 KB |
Output is correct |
21 |
Correct |
196 ms |
19816 KB |
Output is correct |
22 |
Correct |
91 ms |
12744 KB |
Output is correct |
23 |
Correct |
194 ms |
19280 KB |
Output is correct |
24 |
Correct |
93 ms |
11968 KB |
Output is correct |
25 |
Correct |
206 ms |
19968 KB |
Output is correct |
26 |
Correct |
179 ms |
18000 KB |
Output is correct |
27 |
Correct |
176 ms |
17928 KB |
Output is correct |
28 |
Correct |
200 ms |
18960 KB |
Output is correct |
29 |
Correct |
89 ms |
12700 KB |
Output is correct |
30 |
Correct |
82 ms |
11624 KB |
Output is correct |
31 |
Correct |
236 ms |
22704 KB |
Output is correct |
32 |
Correct |
202 ms |
20564 KB |
Output is correct |
33 |
Correct |
200 ms |
19904 KB |
Output is correct |
34 |
Correct |
131 ms |
16408 KB |
Output is correct |
35 |
Correct |
210 ms |
20048 KB |
Output is correct |
36 |
Correct |
94 ms |
11976 KB |
Output is correct |
37 |
Correct |
230 ms |
22608 KB |
Output is correct |
38 |
Correct |
221 ms |
21428 KB |
Output is correct |
39 |
Correct |
247 ms |
23376 KB |
Output is correct |
40 |
Correct |
202 ms |
19028 KB |
Output is correct |
41 |
Correct |
86 ms |
12484 KB |
Output is correct |
42 |
Correct |
76 ms |
11720 KB |
Output is correct |
43 |
Correct |
321 ms |
37712 KB |
Output is correct |
44 |
Correct |
320 ms |
37576 KB |
Output is correct |
45 |
Correct |
291 ms |
34388 KB |
Output is correct |
46 |
Correct |
136 ms |
17236 KB |
Output is correct |
47 |
Correct |
310 ms |
36180 KB |
Output is correct |
48 |
Correct |
98 ms |
11976 KB |
Output is correct |
49 |
Correct |
322 ms |
36976 KB |
Output is correct |
50 |
Correct |
340 ms |
39804 KB |
Output is correct |
51 |
Correct |
334 ms |
41104 KB |
Output is correct |
52 |
Correct |
323 ms |
36028 KB |
Output is correct |
53 |
Correct |
100 ms |
13264 KB |
Output is correct |