#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define f first
#define s second
const int N = 100005;
struct BIT{
int bit[N];
void upd(int x){
for(; x<N; x = (x|(x+1)))
++bit[x];
}
int query(int x){
int res = 0;
for(; x>=0; x = (x&(x+1))-1)
res += bit[x];
return res;
}
} xt, yt, tt;
int n, q, xm, ym;
pii arr[N];
pair<pii, pii> qs[N];
map<int, int> xmp, ymp;
vector<int> xtmp, ytmp;
int ans[N];
int main(){
// freopen("a.in", "r", stdin);
cin.tie(0)->sync_with_stdio(0);
cin >> n >> q;
for(int i = 0; i<n; ++i)
cin >> arr[i].f >> arr[i].s, xtmp.push_back(arr[i].f), ytmp.push_back(arr[i].s);
sort(arr, arr+n, [&](pii a, pii b){return a.f+a.s<b.f+b.s;});
sort(xtmp.begin(), xtmp.end());
xtmp.erase(unique(xtmp.begin(), xtmp.end()), xtmp.end());
xm = xtmp.size();
for(int i = 0; i<xm; ++i)
xmp[xtmp[i]] = i;
sort(ytmp.begin(), ytmp.end());
ytmp.erase(unique(ytmp.begin(), ytmp.end()), ytmp.end());
ym = ytmp.size();
for(int i = 0; i<ym; ++i)
ymp[ytmp[i]] = i;
for(int i = 0; i<q; ++i)
cin >> qs[i].s.f >> qs[i].s.s >> qs[i].f.f, qs[i].f.s = i;
sort(qs, qs+q);
for(int i = q-1, j = n-1; i>=0; --i){
while(j>=0 && arr[j].f+arr[j].s>=qs[i].f.f)
xt.upd(xmp[arr[j].f]), yt.upd(ymp[arr[j].s]), --j;
if(qs[i].s.f+qs[i].s.s<=qs[i].f.f){
int xid = lower_bound(xtmp.begin(), xtmp.end(), qs[i].s.f)-xtmp.begin();
int yid = lower_bound(ytmp.begin(), ytmp.end(), qs[i].s.s)-ytmp.begin();
ans[qs[i].f.s] = (n-1-j)-xt.query(xid-1)-yt.query(yid-1);
}
}
sort(qs, qs+q, [&](pair<pii, pii> a, pair<pii, pii> b){return a.s.f<b.s.f;});
sort(arr, arr+n);
for(int i = q-1, j = n-1; i>=0; --i){
while(j>=0 && arr[j].f>=qs[i].s.f)
tt.upd(ym-1-ymp[arr[j].s]), --j;
if(qs[i].s.f+qs[i].s.s>qs[i].f.f){
int yid = lower_bound(ytmp.begin(), ytmp.end(), qs[i].s.s)-ytmp.begin();
ans[qs[i].f.s] = tt.query(ym-1-yid);
}
}
for(int i = 0; i<q; ++i)
cout << ans[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
5 ms |
844 KB |
Output is correct |
8 |
Correct |
5 ms |
844 KB |
Output is correct |
9 |
Correct |
5 ms |
844 KB |
Output is correct |
10 |
Correct |
3 ms |
588 KB |
Output is correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
844 KB |
Output is correct |
14 |
Correct |
7 ms |
844 KB |
Output is correct |
15 |
Correct |
5 ms |
844 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
233 ms |
11076 KB |
Output is correct |
2 |
Correct |
234 ms |
11048 KB |
Output is correct |
3 |
Correct |
185 ms |
11064 KB |
Output is correct |
4 |
Correct |
100 ms |
7612 KB |
Output is correct |
5 |
Correct |
114 ms |
7900 KB |
Output is correct |
6 |
Correct |
59 ms |
4632 KB |
Output is correct |
7 |
Correct |
187 ms |
11080 KB |
Output is correct |
8 |
Correct |
195 ms |
11064 KB |
Output is correct |
9 |
Correct |
178 ms |
11068 KB |
Output is correct |
10 |
Correct |
97 ms |
7656 KB |
Output is correct |
11 |
Correct |
86 ms |
7428 KB |
Output is correct |
12 |
Correct |
50 ms |
4276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
233 ms |
11076 KB |
Output is correct |
2 |
Correct |
234 ms |
11048 KB |
Output is correct |
3 |
Correct |
185 ms |
11064 KB |
Output is correct |
4 |
Correct |
100 ms |
7612 KB |
Output is correct |
5 |
Correct |
114 ms |
7900 KB |
Output is correct |
6 |
Correct |
59 ms |
4632 KB |
Output is correct |
7 |
Correct |
187 ms |
11080 KB |
Output is correct |
8 |
Correct |
195 ms |
11064 KB |
Output is correct |
9 |
Correct |
178 ms |
11068 KB |
Output is correct |
10 |
Correct |
97 ms |
7656 KB |
Output is correct |
11 |
Correct |
86 ms |
7428 KB |
Output is correct |
12 |
Correct |
50 ms |
4276 KB |
Output is correct |
13 |
Correct |
223 ms |
11284 KB |
Output is correct |
14 |
Correct |
230 ms |
11064 KB |
Output is correct |
15 |
Correct |
186 ms |
11008 KB |
Output is correct |
16 |
Correct |
121 ms |
7604 KB |
Output is correct |
17 |
Correct |
121 ms |
7872 KB |
Output is correct |
18 |
Correct |
67 ms |
4692 KB |
Output is correct |
19 |
Correct |
203 ms |
11060 KB |
Output is correct |
20 |
Correct |
210 ms |
11072 KB |
Output is correct |
21 |
Correct |
229 ms |
11056 KB |
Output is correct |
22 |
Correct |
96 ms |
7716 KB |
Output is correct |
23 |
Correct |
86 ms |
7500 KB |
Output is correct |
24 |
Correct |
54 ms |
4304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
5 ms |
844 KB |
Output is correct |
8 |
Correct |
5 ms |
844 KB |
Output is correct |
9 |
Correct |
5 ms |
844 KB |
Output is correct |
10 |
Correct |
3 ms |
588 KB |
Output is correct |
11 |
Correct |
4 ms |
588 KB |
Output is correct |
12 |
Correct |
4 ms |
460 KB |
Output is correct |
13 |
Correct |
5 ms |
844 KB |
Output is correct |
14 |
Correct |
7 ms |
844 KB |
Output is correct |
15 |
Correct |
5 ms |
844 KB |
Output is correct |
16 |
Correct |
5 ms |
588 KB |
Output is correct |
17 |
Correct |
5 ms |
588 KB |
Output is correct |
18 |
Correct |
3 ms |
460 KB |
Output is correct |
19 |
Correct |
233 ms |
11076 KB |
Output is correct |
20 |
Correct |
234 ms |
11048 KB |
Output is correct |
21 |
Correct |
185 ms |
11064 KB |
Output is correct |
22 |
Correct |
100 ms |
7612 KB |
Output is correct |
23 |
Correct |
114 ms |
7900 KB |
Output is correct |
24 |
Correct |
59 ms |
4632 KB |
Output is correct |
25 |
Correct |
187 ms |
11080 KB |
Output is correct |
26 |
Correct |
195 ms |
11064 KB |
Output is correct |
27 |
Correct |
178 ms |
11068 KB |
Output is correct |
28 |
Correct |
97 ms |
7656 KB |
Output is correct |
29 |
Correct |
86 ms |
7428 KB |
Output is correct |
30 |
Correct |
50 ms |
4276 KB |
Output is correct |
31 |
Correct |
223 ms |
11284 KB |
Output is correct |
32 |
Correct |
230 ms |
11064 KB |
Output is correct |
33 |
Correct |
186 ms |
11008 KB |
Output is correct |
34 |
Correct |
121 ms |
7604 KB |
Output is correct |
35 |
Correct |
121 ms |
7872 KB |
Output is correct |
36 |
Correct |
67 ms |
4692 KB |
Output is correct |
37 |
Correct |
203 ms |
11060 KB |
Output is correct |
38 |
Correct |
210 ms |
11072 KB |
Output is correct |
39 |
Correct |
229 ms |
11056 KB |
Output is correct |
40 |
Correct |
96 ms |
7716 KB |
Output is correct |
41 |
Correct |
86 ms |
7500 KB |
Output is correct |
42 |
Correct |
54 ms |
4304 KB |
Output is correct |
43 |
Correct |
292 ms |
14924 KB |
Output is correct |
44 |
Correct |
260 ms |
14924 KB |
Output is correct |
45 |
Correct |
243 ms |
14920 KB |
Output is correct |
46 |
Correct |
130 ms |
9548 KB |
Output is correct |
47 |
Correct |
141 ms |
9796 KB |
Output is correct |
48 |
Correct |
71 ms |
4628 KB |
Output is correct |
49 |
Correct |
263 ms |
14920 KB |
Output is correct |
50 |
Correct |
312 ms |
14920 KB |
Output is correct |
51 |
Correct |
262 ms |
14912 KB |
Output is correct |
52 |
Correct |
130 ms |
9612 KB |
Output is correct |
53 |
Correct |
97 ms |
9296 KB |
Output is correct |