#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef pair<pl,ll> tl;
vector<pl> w,qu,qp;
set<ll> bx,by;
map<ll,ll> mx,my;
class ST {
private:
vector<ll> st;
int n;
public:
ST(int n_) {
n = n_;
st.assign(2*n,0);
}
void up(ll p, ll val) {
p += n;
st[p] += val;
while(p > 1) {
st[p>>1] = st[p] + st[p^1];
p >>= 1;
}
}
ll get(ll l, ll r) {
l += n;r += n;
ll res = 0;
for(;l<r;l>>=1,r>>=1) {
if(l&1) {
res += st[l];
l++;
}
if(r&1) {
r--;
res += st[r];
}
}
return res;
}
ll size() {
return n;
}
};
int main() {
ios::sync_with_stdio(0);cin.tie(0);
ll n,q;
cin >> n >> q;
for(int i=0;i<n;i++) {
ll a,b;
cin >> a >> b;
w.push_back({a,b});
qp.push_back({a+b,(i+1)});
bx.insert(a);
by.insert(b);
}
for(int i=0;i<q;i++) {
ll a,b,c;
cin >> a >> b >> c;
c = max(c,a+b);
bx.insert(a);
by.insert(b);
qu.push_back({a,b});
qp.push_back({c,-(i+1)});
}
for(auto& it: bx) {
ll sz = mx.size();
mx[it] = sz;
}
for(auto& it: by) {
ll sz = my.size();
my[it] = sz;
}
sort(qp.begin(),qp.end());
ST sx(mx.size()),sy(my.size());
vector<ll> res(q,0);
for(int point = qp.size()-1;point >= 0;point--) {
ll idx = qp[point].second;
ll id = abs(idx)-1;
if(idx < 0) {
ll xv = mx[qu[id].first];
ll yv = my[qu[id].second];
ll vx = sx.get(xv,sx.size());
ll vy = sy.get(0,yv);
res[id] = vx-vy;
} else {
ll xv = mx[w[id].first];
ll yv = my[w[id].second];
sx.up(xv,1);
sy.up(yv,1);
}
}
for(int i=0;i<q;i++) {
cout << res[i] << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
16 ms |
2304 KB |
Output is correct |
8 |
Correct |
16 ms |
2432 KB |
Output is correct |
9 |
Correct |
16 ms |
2304 KB |
Output is correct |
10 |
Correct |
11 ms |
1536 KB |
Output is correct |
11 |
Correct |
11 ms |
1536 KB |
Output is correct |
12 |
Correct |
7 ms |
640 KB |
Output is correct |
13 |
Correct |
15 ms |
2176 KB |
Output is correct |
14 |
Correct |
15 ms |
2176 KB |
Output is correct |
15 |
Correct |
16 ms |
2304 KB |
Output is correct |
16 |
Correct |
10 ms |
1408 KB |
Output is correct |
17 |
Correct |
11 ms |
1408 KB |
Output is correct |
18 |
Correct |
8 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
581 ms |
32204 KB |
Output is correct |
2 |
Correct |
560 ms |
32204 KB |
Output is correct |
3 |
Correct |
580 ms |
32272 KB |
Output is correct |
4 |
Correct |
211 ms |
20556 KB |
Output is correct |
5 |
Correct |
221 ms |
20552 KB |
Output is correct |
6 |
Correct |
95 ms |
10320 KB |
Output is correct |
7 |
Correct |
467 ms |
29640 KB |
Output is correct |
8 |
Correct |
493 ms |
29640 KB |
Output is correct |
9 |
Correct |
408 ms |
27084 KB |
Output is correct |
10 |
Correct |
216 ms |
20424 KB |
Output is correct |
11 |
Correct |
206 ms |
20420 KB |
Output is correct |
12 |
Correct |
78 ms |
9940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
581 ms |
32204 KB |
Output is correct |
2 |
Correct |
560 ms |
32204 KB |
Output is correct |
3 |
Correct |
580 ms |
32272 KB |
Output is correct |
4 |
Correct |
211 ms |
20556 KB |
Output is correct |
5 |
Correct |
221 ms |
20552 KB |
Output is correct |
6 |
Correct |
95 ms |
10320 KB |
Output is correct |
7 |
Correct |
467 ms |
29640 KB |
Output is correct |
8 |
Correct |
493 ms |
29640 KB |
Output is correct |
9 |
Correct |
408 ms |
27084 KB |
Output is correct |
10 |
Correct |
216 ms |
20424 KB |
Output is correct |
11 |
Correct |
206 ms |
20420 KB |
Output is correct |
12 |
Correct |
78 ms |
9940 KB |
Output is correct |
13 |
Correct |
587 ms |
32612 KB |
Output is correct |
14 |
Correct |
561 ms |
32576 KB |
Output is correct |
15 |
Correct |
578 ms |
32208 KB |
Output is correct |
16 |
Correct |
264 ms |
21068 KB |
Output is correct |
17 |
Correct |
278 ms |
21168 KB |
Output is correct |
18 |
Correct |
92 ms |
10464 KB |
Output is correct |
19 |
Correct |
636 ms |
32628 KB |
Output is correct |
20 |
Correct |
593 ms |
32584 KB |
Output is correct |
21 |
Correct |
565 ms |
30792 KB |
Output is correct |
22 |
Correct |
206 ms |
20428 KB |
Output is correct |
23 |
Correct |
211 ms |
20360 KB |
Output is correct |
24 |
Correct |
76 ms |
9932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
16 ms |
2304 KB |
Output is correct |
8 |
Correct |
16 ms |
2432 KB |
Output is correct |
9 |
Correct |
16 ms |
2304 KB |
Output is correct |
10 |
Correct |
11 ms |
1536 KB |
Output is correct |
11 |
Correct |
11 ms |
1536 KB |
Output is correct |
12 |
Correct |
7 ms |
640 KB |
Output is correct |
13 |
Correct |
15 ms |
2176 KB |
Output is correct |
14 |
Correct |
15 ms |
2176 KB |
Output is correct |
15 |
Correct |
16 ms |
2304 KB |
Output is correct |
16 |
Correct |
10 ms |
1408 KB |
Output is correct |
17 |
Correct |
11 ms |
1408 KB |
Output is correct |
18 |
Correct |
8 ms |
640 KB |
Output is correct |
19 |
Correct |
581 ms |
32204 KB |
Output is correct |
20 |
Correct |
560 ms |
32204 KB |
Output is correct |
21 |
Correct |
580 ms |
32272 KB |
Output is correct |
22 |
Correct |
211 ms |
20556 KB |
Output is correct |
23 |
Correct |
221 ms |
20552 KB |
Output is correct |
24 |
Correct |
95 ms |
10320 KB |
Output is correct |
25 |
Correct |
467 ms |
29640 KB |
Output is correct |
26 |
Correct |
493 ms |
29640 KB |
Output is correct |
27 |
Correct |
408 ms |
27084 KB |
Output is correct |
28 |
Correct |
216 ms |
20424 KB |
Output is correct |
29 |
Correct |
206 ms |
20420 KB |
Output is correct |
30 |
Correct |
78 ms |
9940 KB |
Output is correct |
31 |
Correct |
587 ms |
32612 KB |
Output is correct |
32 |
Correct |
561 ms |
32576 KB |
Output is correct |
33 |
Correct |
578 ms |
32208 KB |
Output is correct |
34 |
Correct |
264 ms |
21068 KB |
Output is correct |
35 |
Correct |
278 ms |
21168 KB |
Output is correct |
36 |
Correct |
92 ms |
10464 KB |
Output is correct |
37 |
Correct |
636 ms |
32628 KB |
Output is correct |
38 |
Correct |
593 ms |
32584 KB |
Output is correct |
39 |
Correct |
565 ms |
30792 KB |
Output is correct |
40 |
Correct |
206 ms |
20428 KB |
Output is correct |
41 |
Correct |
211 ms |
20360 KB |
Output is correct |
42 |
Correct |
76 ms |
9932 KB |
Output is correct |
43 |
Correct |
978 ms |
62948 KB |
Output is correct |
44 |
Correct |
978 ms |
62964 KB |
Output is correct |
45 |
Correct |
920 ms |
62912 KB |
Output is correct |
46 |
Correct |
370 ms |
36296 KB |
Output is correct |
47 |
Correct |
393 ms |
36444 KB |
Output is correct |
48 |
Correct |
94 ms |
10188 KB |
Output is correct |
49 |
Correct |
907 ms |
62928 KB |
Output is correct |
50 |
Correct |
940 ms |
62924 KB |
Output is correct |
51 |
Correct |
914 ms |
62792 KB |
Output is correct |
52 |
Correct |
372 ms |
36272 KB |
Output is correct |
53 |
Correct |
328 ms |
35396 KB |
Output is correct |