#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
// #pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
const int maxn = 2e5 + 5;
const int INF = 1e9;
int n, Q;
int ans[maxn];
struct info{
int x, y, ttl, id;
info(int _a, int _b, int _ttl, int _id = 0) : x(_a), y(_b), ttl(_ttl), id(_id){}
bool operator < (const info& other) const{
return ttl < other.ttl;
}
};
vector<int> val, val2;
int getid(int x){
return lower_bound(val.begin(), val.end(), x) - val.begin();
}
int getid2(int x){
return lower_bound(val2.begin(), val2.end(), x) - val2.begin();
}
struct SGT{
struct node{
int val;
node *l, *r;
node() : val(0), l(nullptr), r(nullptr){}
} *rt;
void init(){rt = new node();}
void upd(int pos, int val, node *&nd, int l, int r){
if(!nd) nd = new node();
nd->val += val;
if(l == r) return;
int m = (l + r) / 2;
if(pos <= m) upd(pos, val, nd->l, l, m);
else upd(pos, val, nd->r, m + 1, r);
}
void upd(int pos, int val){ upd(pos, val, rt, 0, maxn - 1);}
int qry(int l, int r, node *nd, int L, int R){
if(!nd) return 0;
if(l > R || r < L) return 0;
if(l <= L && r >= R) return nd->val;
int m = (L + R) / 2;
return qry(l, r, nd->l, L, m) + qry(l, r, nd->r, m + 1, R);
}
int qry(int l, int r){ return qry(l, r, rt, 0, maxn - 1);}
} BIT[maxn];
void upd(int x, int y, int val){
x++, y++;
while(x < maxn){
BIT[x].upd(y, val);
x += lowbit(x);
}
}
int qry(int x, int y){
x++, y++;
int ret = 0;
while(x > 0){
ret += BIT[x].qry(0, y);
x -= lowbit(x);
}
return ret;
}
int main(void){
fastio;
cin>>n>>Q;
vector<info> a, q;
for(int i = 0; i < n; i++){
int x, y;
cin>>x>>y;
val.pb(x), val2.pb(y);
a.pb(info(x, y, x + y));
}
for(int i = 0; i < Q; i++){
int x, y, z;
cin>>x>>y>>z;
val.pb(x), val2.pb(y);
q.pb(info(x, y, z, i));
}
sort(val.begin(), val.end());
val.erase(unique(val.begin(), val.end()), val.end());
sort(val2.begin(), val2.end());
val2.erase(unique(val2.begin(), val2.end()), val2.end());
sort(a.begin(), a.end());
sort(q.begin(), q.end());
for(int i = 0; i < maxn; i++) BIT[i].init();
for(int i = 0; i < n; i++){
a[i].x = getid(a[i].x), a[i].y = getid2(a[i].y);
upd(a[i].x, a[i].y, 1);
}
int pos = 0;
for(int i = 0; i < Q; i++){
auto [x, y, z, id] = q[i];
while(a[pos].ttl < z && pos < n) upd(a[pos].x, a[pos].y, -1), pos++;
if(pos == n) break;
x = getid(x), y = getid2(y);
ans[id] = n - pos - qry(x - 1, maxn - 1) - qry(maxn - 1, y - 1) + qry(x - 1, y - 1);
}
for(int i = 0; i < Q; i++) cout<<ans[i]<<"\n";
cout<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8796 KB |
Output is correct |
2 |
Correct |
6 ms |
8796 KB |
Output is correct |
3 |
Correct |
6 ms |
9048 KB |
Output is correct |
4 |
Correct |
5 ms |
8796 KB |
Output is correct |
5 |
Correct |
6 ms |
8796 KB |
Output is correct |
6 |
Correct |
5 ms |
8796 KB |
Output is correct |
7 |
Correct |
23 ms |
16208 KB |
Output is correct |
8 |
Correct |
23 ms |
16360 KB |
Output is correct |
9 |
Correct |
23 ms |
16472 KB |
Output is correct |
10 |
Correct |
15 ms |
11816 KB |
Output is correct |
11 |
Correct |
19 ms |
13788 KB |
Output is correct |
12 |
Correct |
11 ms |
9052 KB |
Output is correct |
13 |
Correct |
21 ms |
16476 KB |
Output is correct |
14 |
Correct |
23 ms |
16476 KB |
Output is correct |
15 |
Correct |
21 ms |
16460 KB |
Output is correct |
16 |
Correct |
15 ms |
13660 KB |
Output is correct |
17 |
Correct |
14 ms |
11356 KB |
Output is correct |
18 |
Correct |
10 ms |
9052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1070 ms |
275168 KB |
Output is correct |
2 |
Correct |
1044 ms |
275116 KB |
Output is correct |
3 |
Correct |
1030 ms |
275140 KB |
Output is correct |
4 |
Correct |
340 ms |
67336 KB |
Output is correct |
5 |
Correct |
347 ms |
103188 KB |
Output is correct |
6 |
Correct |
125 ms |
15196 KB |
Output is correct |
7 |
Correct |
749 ms |
264344 KB |
Output is correct |
8 |
Correct |
835 ms |
265664 KB |
Output is correct |
9 |
Correct |
638 ms |
256072 KB |
Output is correct |
10 |
Correct |
286 ms |
97952 KB |
Output is correct |
11 |
Correct |
270 ms |
56516 KB |
Output is correct |
12 |
Correct |
110 ms |
14784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1070 ms |
275168 KB |
Output is correct |
2 |
Correct |
1044 ms |
275116 KB |
Output is correct |
3 |
Correct |
1030 ms |
275140 KB |
Output is correct |
4 |
Correct |
340 ms |
67336 KB |
Output is correct |
5 |
Correct |
347 ms |
103188 KB |
Output is correct |
6 |
Correct |
125 ms |
15196 KB |
Output is correct |
7 |
Correct |
749 ms |
264344 KB |
Output is correct |
8 |
Correct |
835 ms |
265664 KB |
Output is correct |
9 |
Correct |
638 ms |
256072 KB |
Output is correct |
10 |
Correct |
286 ms |
97952 KB |
Output is correct |
11 |
Correct |
270 ms |
56516 KB |
Output is correct |
12 |
Correct |
110 ms |
14784 KB |
Output is correct |
13 |
Correct |
1321 ms |
273728 KB |
Output is correct |
14 |
Correct |
1173 ms |
277084 KB |
Output is correct |
15 |
Correct |
1036 ms |
276016 KB |
Output is correct |
16 |
Correct |
396 ms |
68348 KB |
Output is correct |
17 |
Correct |
420 ms |
104384 KB |
Output is correct |
18 |
Correct |
155 ms |
15276 KB |
Output is correct |
19 |
Correct |
1315 ms |
276204 KB |
Output is correct |
20 |
Correct |
1271 ms |
276532 KB |
Output is correct |
21 |
Correct |
1127 ms |
269892 KB |
Output is correct |
22 |
Correct |
267 ms |
98968 KB |
Output is correct |
23 |
Correct |
288 ms |
57204 KB |
Output is correct |
24 |
Correct |
138 ms |
15064 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
8796 KB |
Output is correct |
2 |
Correct |
6 ms |
8796 KB |
Output is correct |
3 |
Correct |
6 ms |
9048 KB |
Output is correct |
4 |
Correct |
5 ms |
8796 KB |
Output is correct |
5 |
Correct |
6 ms |
8796 KB |
Output is correct |
6 |
Correct |
5 ms |
8796 KB |
Output is correct |
7 |
Correct |
23 ms |
16208 KB |
Output is correct |
8 |
Correct |
23 ms |
16360 KB |
Output is correct |
9 |
Correct |
23 ms |
16472 KB |
Output is correct |
10 |
Correct |
15 ms |
11816 KB |
Output is correct |
11 |
Correct |
19 ms |
13788 KB |
Output is correct |
12 |
Correct |
11 ms |
9052 KB |
Output is correct |
13 |
Correct |
21 ms |
16476 KB |
Output is correct |
14 |
Correct |
23 ms |
16476 KB |
Output is correct |
15 |
Correct |
21 ms |
16460 KB |
Output is correct |
16 |
Correct |
15 ms |
13660 KB |
Output is correct |
17 |
Correct |
14 ms |
11356 KB |
Output is correct |
18 |
Correct |
10 ms |
9052 KB |
Output is correct |
19 |
Correct |
1070 ms |
275168 KB |
Output is correct |
20 |
Correct |
1044 ms |
275116 KB |
Output is correct |
21 |
Correct |
1030 ms |
275140 KB |
Output is correct |
22 |
Correct |
340 ms |
67336 KB |
Output is correct |
23 |
Correct |
347 ms |
103188 KB |
Output is correct |
24 |
Correct |
125 ms |
15196 KB |
Output is correct |
25 |
Correct |
749 ms |
264344 KB |
Output is correct |
26 |
Correct |
835 ms |
265664 KB |
Output is correct |
27 |
Correct |
638 ms |
256072 KB |
Output is correct |
28 |
Correct |
286 ms |
97952 KB |
Output is correct |
29 |
Correct |
270 ms |
56516 KB |
Output is correct |
30 |
Correct |
110 ms |
14784 KB |
Output is correct |
31 |
Correct |
1321 ms |
273728 KB |
Output is correct |
32 |
Correct |
1173 ms |
277084 KB |
Output is correct |
33 |
Correct |
1036 ms |
276016 KB |
Output is correct |
34 |
Correct |
396 ms |
68348 KB |
Output is correct |
35 |
Correct |
420 ms |
104384 KB |
Output is correct |
36 |
Correct |
155 ms |
15276 KB |
Output is correct |
37 |
Correct |
1315 ms |
276204 KB |
Output is correct |
38 |
Correct |
1271 ms |
276532 KB |
Output is correct |
39 |
Correct |
1127 ms |
269892 KB |
Output is correct |
40 |
Correct |
267 ms |
98968 KB |
Output is correct |
41 |
Correct |
288 ms |
57204 KB |
Output is correct |
42 |
Correct |
138 ms |
15064 KB |
Output is correct |
43 |
Correct |
1421 ms |
334812 KB |
Output is correct |
44 |
Correct |
1421 ms |
334804 KB |
Output is correct |
45 |
Correct |
1371 ms |
334528 KB |
Output is correct |
46 |
Correct |
505 ms |
104660 KB |
Output is correct |
47 |
Correct |
512 ms |
171120 KB |
Output is correct |
48 |
Correct |
172 ms |
15272 KB |
Output is correct |
49 |
Correct |
1081 ms |
314596 KB |
Output is correct |
50 |
Correct |
1193 ms |
319328 KB |
Output is correct |
51 |
Correct |
864 ms |
299308 KB |
Output is correct |
52 |
Correct |
462 ms |
171972 KB |
Output is correct |
53 |
Correct |
386 ms |
93204 KB |
Output is correct |