#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
struct D{
int x,y,id;
D(){}
D(int xx,int yy,int ii){
x = xx,y = yy,id = ii;
}
bool operator<(D b)const{
return (x+y==b.x+b.y?id>b.id:x+y<b.x+b.y);
}
};
const int inf = 1e9;
const int mxn = 2e5+10;
vector<int> allx,ally;
vector<D> req;
int N,Q;
int ans[mxn];
pii range[mxn];
gp_hash_table<int,int> bit[mxn];
int getval(int x,int y){
x = mxn-x-1,y = mxn-y-1;
int re = 0;
for(int tx = x;tx>0;tx-=tx&-tx){
for(int ty = y;ty>0;ty -= ty&-ty){
if(bit[tx].find(ty) == bit[tx].end())continue;
re += bit[tx][ty];
}
}
return re;
}
void modify(int x,int y){
x = mxn-1-x,y = mxn-1-y;
for(int i = x;i<mxn;i+=i&-i){
for(int j = y;j<mxn;j+=j&-j)bit[i][j]++;
}
return;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>Q;
allx.push_back(-inf);
ally.push_back(-inf);
for(int i = 0;i<N;i++){
int x,y;
cin>>x>>y;
req.push_back(D(x,y,-1));
allx.push_back(x);
ally.push_back(y);
}
for(int i = 1;i<=Q;i++){
int a,b,c;
cin>>a>>b>>c;
range[i] = {a,b};
allx.push_back(a);
ally.push_back(b);
req.push_back(D(c,0,i));
}
#define _all(T) T.begin(),T.end()
sort(_all(allx));allx.erase(unique(_all(allx)),allx.end());
sort(_all(ally));ally.erase(unique(_all(ally)),ally.end());
sort(req.begin(),req.end());
for(auto it = req.rbegin();it != req.rend();it++){
int x,y;
if(it->id != -1){
x = range[it->id].fs,y = range[it->id].sc;
}
else x = it->x,y = it->y;
x = lower_bound(_all(allx),x)-allx.begin();
y = lower_bound(_all(ally),y)-ally.begin();
if(it->id != -1)ans[it->id] = getval(x,y);
else modify(x,y);
}
for(int i = 1;i<=Q;i++){
cout<<ans[i]<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
42840 KB |
Output is correct |
2 |
Correct |
23 ms |
42844 KB |
Output is correct |
3 |
Correct |
24 ms |
42932 KB |
Output is correct |
4 |
Correct |
23 ms |
42840 KB |
Output is correct |
5 |
Correct |
24 ms |
42840 KB |
Output is correct |
6 |
Correct |
23 ms |
42844 KB |
Output is correct |
7 |
Correct |
39 ms |
45908 KB |
Output is correct |
8 |
Correct |
39 ms |
46084 KB |
Output is correct |
9 |
Correct |
40 ms |
45856 KB |
Output is correct |
10 |
Correct |
30 ms |
43508 KB |
Output is correct |
11 |
Correct |
31 ms |
43864 KB |
Output is correct |
12 |
Correct |
27 ms |
43356 KB |
Output is correct |
13 |
Correct |
47 ms |
46140 KB |
Output is correct |
14 |
Correct |
38 ms |
45916 KB |
Output is correct |
15 |
Correct |
38 ms |
45912 KB |
Output is correct |
16 |
Correct |
28 ms |
43444 KB |
Output is correct |
17 |
Correct |
28 ms |
43168 KB |
Output is correct |
18 |
Correct |
28 ms |
43108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1190 ms |
187624 KB |
Output is correct |
2 |
Correct |
1162 ms |
187568 KB |
Output is correct |
3 |
Correct |
1153 ms |
186800 KB |
Output is correct |
4 |
Correct |
265 ms |
58856 KB |
Output is correct |
5 |
Correct |
161 ms |
62452 KB |
Output is correct |
6 |
Correct |
120 ms |
50168 KB |
Output is correct |
7 |
Correct |
977 ms |
184544 KB |
Output is correct |
8 |
Correct |
1149 ms |
181028 KB |
Output is correct |
9 |
Correct |
941 ms |
179256 KB |
Output is correct |
10 |
Correct |
122 ms |
55216 KB |
Output is correct |
11 |
Correct |
153 ms |
50412 KB |
Output is correct |
12 |
Correct |
92 ms |
49388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1190 ms |
187624 KB |
Output is correct |
2 |
Correct |
1162 ms |
187568 KB |
Output is correct |
3 |
Correct |
1153 ms |
186800 KB |
Output is correct |
4 |
Correct |
265 ms |
58856 KB |
Output is correct |
5 |
Correct |
161 ms |
62452 KB |
Output is correct |
6 |
Correct |
120 ms |
50168 KB |
Output is correct |
7 |
Correct |
977 ms |
184544 KB |
Output is correct |
8 |
Correct |
1149 ms |
181028 KB |
Output is correct |
9 |
Correct |
941 ms |
179256 KB |
Output is correct |
10 |
Correct |
122 ms |
55216 KB |
Output is correct |
11 |
Correct |
153 ms |
50412 KB |
Output is correct |
12 |
Correct |
92 ms |
49388 KB |
Output is correct |
13 |
Correct |
1068 ms |
187988 KB |
Output is correct |
14 |
Correct |
1231 ms |
187740 KB |
Output is correct |
15 |
Correct |
1232 ms |
187640 KB |
Output is correct |
16 |
Correct |
235 ms |
59120 KB |
Output is correct |
17 |
Correct |
178 ms |
62712 KB |
Output is correct |
18 |
Correct |
111 ms |
49644 KB |
Output is correct |
19 |
Correct |
1087 ms |
189700 KB |
Output is correct |
20 |
Correct |
1206 ms |
188088 KB |
Output is correct |
21 |
Correct |
991 ms |
183036 KB |
Output is correct |
22 |
Correct |
123 ms |
55252 KB |
Output is correct |
23 |
Correct |
154 ms |
50392 KB |
Output is correct |
24 |
Correct |
77 ms |
49908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
42840 KB |
Output is correct |
2 |
Correct |
23 ms |
42844 KB |
Output is correct |
3 |
Correct |
24 ms |
42932 KB |
Output is correct |
4 |
Correct |
23 ms |
42840 KB |
Output is correct |
5 |
Correct |
24 ms |
42840 KB |
Output is correct |
6 |
Correct |
23 ms |
42844 KB |
Output is correct |
7 |
Correct |
39 ms |
45908 KB |
Output is correct |
8 |
Correct |
39 ms |
46084 KB |
Output is correct |
9 |
Correct |
40 ms |
45856 KB |
Output is correct |
10 |
Correct |
30 ms |
43508 KB |
Output is correct |
11 |
Correct |
31 ms |
43864 KB |
Output is correct |
12 |
Correct |
27 ms |
43356 KB |
Output is correct |
13 |
Correct |
47 ms |
46140 KB |
Output is correct |
14 |
Correct |
38 ms |
45916 KB |
Output is correct |
15 |
Correct |
38 ms |
45912 KB |
Output is correct |
16 |
Correct |
28 ms |
43444 KB |
Output is correct |
17 |
Correct |
28 ms |
43168 KB |
Output is correct |
18 |
Correct |
28 ms |
43108 KB |
Output is correct |
19 |
Correct |
1190 ms |
187624 KB |
Output is correct |
20 |
Correct |
1162 ms |
187568 KB |
Output is correct |
21 |
Correct |
1153 ms |
186800 KB |
Output is correct |
22 |
Correct |
265 ms |
58856 KB |
Output is correct |
23 |
Correct |
161 ms |
62452 KB |
Output is correct |
24 |
Correct |
120 ms |
50168 KB |
Output is correct |
25 |
Correct |
977 ms |
184544 KB |
Output is correct |
26 |
Correct |
1149 ms |
181028 KB |
Output is correct |
27 |
Correct |
941 ms |
179256 KB |
Output is correct |
28 |
Correct |
122 ms |
55216 KB |
Output is correct |
29 |
Correct |
153 ms |
50412 KB |
Output is correct |
30 |
Correct |
92 ms |
49388 KB |
Output is correct |
31 |
Correct |
1068 ms |
187988 KB |
Output is correct |
32 |
Correct |
1231 ms |
187740 KB |
Output is correct |
33 |
Correct |
1232 ms |
187640 KB |
Output is correct |
34 |
Correct |
235 ms |
59120 KB |
Output is correct |
35 |
Correct |
178 ms |
62712 KB |
Output is correct |
36 |
Correct |
111 ms |
49644 KB |
Output is correct |
37 |
Correct |
1087 ms |
189700 KB |
Output is correct |
38 |
Correct |
1206 ms |
188088 KB |
Output is correct |
39 |
Correct |
991 ms |
183036 KB |
Output is correct |
40 |
Correct |
123 ms |
55252 KB |
Output is correct |
41 |
Correct |
154 ms |
50392 KB |
Output is correct |
42 |
Correct |
77 ms |
49908 KB |
Output is correct |
43 |
Correct |
1417 ms |
228248 KB |
Output is correct |
44 |
Correct |
1409 ms |
228140 KB |
Output is correct |
45 |
Correct |
1567 ms |
228208 KB |
Output is correct |
46 |
Correct |
274 ms |
63212 KB |
Output is correct |
47 |
Correct |
214 ms |
71712 KB |
Output is correct |
48 |
Correct |
106 ms |
50168 KB |
Output is correct |
49 |
Correct |
1290 ms |
215796 KB |
Output is correct |
50 |
Correct |
1423 ms |
221824 KB |
Output is correct |
51 |
Correct |
1265 ms |
211928 KB |
Output is correct |
52 |
Correct |
147 ms |
60532 KB |
Output is correct |
53 |
Correct |
211 ms |
51112 KB |
Output is correct |