#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
struct BIT{
int n;
vector<int> bt;
void init(int x){
n=x;
bt.resize(x+1);
}
void update(int x,int y){
x++;
for(;x<=n;x+=(x&-x)){
bt[x]+=y;
}
}
int query(int x){
x++;
int ans=0;
for(;x>0;x-=(x&-x)){
ans+=bt[x];
}
return ans;
}
}bt;
vector<int> g;
struct no{
int x,y,z;
int id;
no(int a,int b,int c,int d){
x=a;
y=b;
z=c;
id=d;
}
};
vector<no> v;
vector<int> ans;
void add(int a,int b,int c,int d){
v.push_back({-a,-b,-c,d});
g.push_back(-c);
}
bool cmp(no a,no b){
if(a.x==b.x){
return a.id<b.id;
}
return a.x<b.x;
}
bool cmp2(no a,no b){
if(a.y==b.y){
return a.id<b.id;
}
return a.y<b.y;
}
void dc(int l,int r){
if(l==r){
return;
}
int m=(l+r)/2;
dc(l,m);
dc(m+1,r);
sort(v.begin()+l,v.begin()+m+1,cmp2);
sort(v.begin()+m+1,v.begin()+r+1,cmp2);
int a=l,b=m+1;
while(a<=m || b<=r){
if(a>m || (b<=r && !cmp2(v[a],v[b]))){
if(v[b].id<0){
b++;
continue;
}
ans[v[b].id]+=bt.query(v[b].z);
b++;
}
else{
if(v[a].id>=0){
a++;
continue;
}
bt.update(v[a].z,1);
a++;
}
}
for(int i=l;i<=m;i++){
if(v[i].id<0){
bt.update(v[i].z,-1);
}
}
}
int main(){
AquA;
int n,q;
cin >> n >> q;
bt.init(n+q);
for(int i=0;i<n;i++){
int a,b;
cin >> a >> b;
int c=a+b;
add(a,b,c,-1);
}
ans.resize(q);
for(int i=0;i<q;i++){
int a,b,c;
cin >> a >> b >> c;
add(a,b,c,i);
}
sort(g.begin(),g.end());
g.erase(unique(g.begin(),g.end()),g.end());
sort(v.begin(),v.end(),cmp);
for(auto &h:v){
h.z=lower_bound(g.begin(),g.end(),h.z)-g.begin();
}
dc(0,n+q-1);
for(int i=0;i<q;i++){
cout << ans[i] << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
8 ms |
716 KB |
Output is correct |
8 |
Correct |
8 ms |
708 KB |
Output is correct |
9 |
Correct |
9 ms |
724 KB |
Output is correct |
10 |
Correct |
8 ms |
596 KB |
Output is correct |
11 |
Correct |
8 ms |
596 KB |
Output is correct |
12 |
Correct |
6 ms |
596 KB |
Output is correct |
13 |
Correct |
8 ms |
696 KB |
Output is correct |
14 |
Correct |
8 ms |
588 KB |
Output is correct |
15 |
Correct |
7 ms |
596 KB |
Output is correct |
16 |
Correct |
7 ms |
588 KB |
Output is correct |
17 |
Correct |
8 ms |
588 KB |
Output is correct |
18 |
Correct |
6 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
6580 KB |
Output is correct |
2 |
Correct |
374 ms |
8732 KB |
Output is correct |
3 |
Correct |
369 ms |
8776 KB |
Output is correct |
4 |
Correct |
312 ms |
8316 KB |
Output is correct |
5 |
Correct |
346 ms |
8332 KB |
Output is correct |
6 |
Correct |
268 ms |
7576 KB |
Output is correct |
7 |
Correct |
346 ms |
8740 KB |
Output is correct |
8 |
Correct |
376 ms |
8740 KB |
Output is correct |
9 |
Correct |
350 ms |
8736 KB |
Output is correct |
10 |
Correct |
335 ms |
8188 KB |
Output is correct |
11 |
Correct |
292 ms |
8176 KB |
Output is correct |
12 |
Correct |
215 ms |
7160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
367 ms |
6580 KB |
Output is correct |
2 |
Correct |
374 ms |
8732 KB |
Output is correct |
3 |
Correct |
369 ms |
8776 KB |
Output is correct |
4 |
Correct |
312 ms |
8316 KB |
Output is correct |
5 |
Correct |
346 ms |
8332 KB |
Output is correct |
6 |
Correct |
268 ms |
7576 KB |
Output is correct |
7 |
Correct |
346 ms |
8740 KB |
Output is correct |
8 |
Correct |
376 ms |
8740 KB |
Output is correct |
9 |
Correct |
350 ms |
8736 KB |
Output is correct |
10 |
Correct |
335 ms |
8188 KB |
Output is correct |
11 |
Correct |
292 ms |
8176 KB |
Output is correct |
12 |
Correct |
215 ms |
7160 KB |
Output is correct |
13 |
Correct |
393 ms |
9396 KB |
Output is correct |
14 |
Correct |
394 ms |
9432 KB |
Output is correct |
15 |
Correct |
383 ms |
9056 KB |
Output is correct |
16 |
Correct |
352 ms |
8700 KB |
Output is correct |
17 |
Correct |
368 ms |
8696 KB |
Output is correct |
18 |
Correct |
275 ms |
7580 KB |
Output is correct |
19 |
Correct |
394 ms |
9444 KB |
Output is correct |
20 |
Correct |
384 ms |
9480 KB |
Output is correct |
21 |
Correct |
378 ms |
9476 KB |
Output is correct |
22 |
Correct |
356 ms |
8172 KB |
Output is correct |
23 |
Correct |
317 ms |
8172 KB |
Output is correct |
24 |
Correct |
241 ms |
7160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
224 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
8 ms |
716 KB |
Output is correct |
8 |
Correct |
8 ms |
708 KB |
Output is correct |
9 |
Correct |
9 ms |
724 KB |
Output is correct |
10 |
Correct |
8 ms |
596 KB |
Output is correct |
11 |
Correct |
8 ms |
596 KB |
Output is correct |
12 |
Correct |
6 ms |
596 KB |
Output is correct |
13 |
Correct |
8 ms |
696 KB |
Output is correct |
14 |
Correct |
8 ms |
588 KB |
Output is correct |
15 |
Correct |
7 ms |
596 KB |
Output is correct |
16 |
Correct |
7 ms |
588 KB |
Output is correct |
17 |
Correct |
8 ms |
588 KB |
Output is correct |
18 |
Correct |
6 ms |
596 KB |
Output is correct |
19 |
Correct |
367 ms |
6580 KB |
Output is correct |
20 |
Correct |
374 ms |
8732 KB |
Output is correct |
21 |
Correct |
369 ms |
8776 KB |
Output is correct |
22 |
Correct |
312 ms |
8316 KB |
Output is correct |
23 |
Correct |
346 ms |
8332 KB |
Output is correct |
24 |
Correct |
268 ms |
7576 KB |
Output is correct |
25 |
Correct |
346 ms |
8740 KB |
Output is correct |
26 |
Correct |
376 ms |
8740 KB |
Output is correct |
27 |
Correct |
350 ms |
8736 KB |
Output is correct |
28 |
Correct |
335 ms |
8188 KB |
Output is correct |
29 |
Correct |
292 ms |
8176 KB |
Output is correct |
30 |
Correct |
215 ms |
7160 KB |
Output is correct |
31 |
Correct |
393 ms |
9396 KB |
Output is correct |
32 |
Correct |
394 ms |
9432 KB |
Output is correct |
33 |
Correct |
383 ms |
9056 KB |
Output is correct |
34 |
Correct |
352 ms |
8700 KB |
Output is correct |
35 |
Correct |
368 ms |
8696 KB |
Output is correct |
36 |
Correct |
275 ms |
7580 KB |
Output is correct |
37 |
Correct |
394 ms |
9444 KB |
Output is correct |
38 |
Correct |
384 ms |
9480 KB |
Output is correct |
39 |
Correct |
378 ms |
9476 KB |
Output is correct |
40 |
Correct |
356 ms |
8172 KB |
Output is correct |
41 |
Correct |
317 ms |
8172 KB |
Output is correct |
42 |
Correct |
241 ms |
7160 KB |
Output is correct |
43 |
Correct |
402 ms |
11448 KB |
Output is correct |
44 |
Correct |
408 ms |
11448 KB |
Output is correct |
45 |
Correct |
415 ms |
11388 KB |
Output is correct |
46 |
Correct |
331 ms |
9876 KB |
Output is correct |
47 |
Correct |
394 ms |
9868 KB |
Output is correct |
48 |
Correct |
265 ms |
7488 KB |
Output is correct |
49 |
Correct |
399 ms |
11304 KB |
Output is correct |
50 |
Correct |
387 ms |
11344 KB |
Output is correct |
51 |
Correct |
394 ms |
11196 KB |
Output is correct |
52 |
Correct |
361 ms |
9728 KB |
Output is correct |
53 |
Correct |
306 ms |
8952 KB |
Output is correct |