#include<bits/stdc++.h>
using namespace std;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
//#define int ll
int n, m, k, a[300010], q, l, r;
struct n2{
n2 *l, *r;
int sum;
n2(){
this->l=this->r=NULL;
this->sum=0;
}
};
struct n1{
n1 *l, *r;
n2 *t2;
n1(){
this->l=this->r=NULL;
this->t2=NULL;
}
} *t1;
void update2( n2*&t, int l2, int r2, int y){
if(!t){
t=new n2();
}
if(l2==r2){
t->sum++;
return;
}
int mid=(l2+r2)>>1ll;
if(y<=mid){
update2(t->l, l2, mid, y);
}
else{
update2(t->r, mid+1, r2, y);
}
t->sum++;
}
void update1(n1 *&t, int l1, int r1, int l2, int r2, int x, int y){
if(!t){
t=new n1();
}
update2(t->t2, l2, r2, y);
if(l1==r1){
return;
}
int mid=(l1+r1)>>1ll;
if(x<=mid){
update1(t->l, l1, mid, l2, r2, x, y);
}
else{
update1(t->r, mid+1, r1, l2, r2, x, y);
}
return;
}
int query2(n2 *t, int l2, int r2, int y1, int y2){
if(!t){
return 0;
}
if(y1>y2){
return 0;
}
if( (y1==l2) && (y2==r2) ){
return t->sum;
}
int mid=(l2+r2)>>1ll;
return query2(t->l, l2, mid, y1, min(mid, y2))+query2(t->r, mid+1, r2, max(mid+1, y1), y2 );
}
int query1(n1 *t, int l1, int r1, int l2, int r2, int x1, int x2, int y1, int y2){
if(!t){
return 0;
}
if(x1>x2){
return 0;
}
if( (l1==x1) && (r1==x2) ){
return query2(t->t2, l2, r2, y1, y2);
}
int mid=(l1+r1)>>1ll;
return query1(t->l, l1, mid, l2, r2, x1, min(x2, mid), y1, y2)+query1(t->r, mid+1, r1, l2, r2, max(mid+1, x1), x2, y1, y2);
}
int s[100010], t[100010];
pair<int, pii> pr[100010];
pair<int, pair<int, pii>> qr[100010];
int res[100010];
map<int, int> ord1, ord2, ord3;
vector<int> v1, v2, v3;
int32_t main(){
INIT
cin>>n>>q;
for(int i=1; i<=n; i++){
cin>>s[i]>>t[i];
pr[i]={s[i]+t[i], {s[i], t[i]} };
v3.pb(s[i]+t[i]);
v1.pb(s[i]);
v2.pb(t[i]);
}
sort(pr+1, pr+1+n);
for(int i=1; i<=q; i++){
cin>>qr[i].sc.sc.ft>>qr[i].sc.sc.sc>>qr[i].ft;
qr[i].sc.ft=i;
v1.pb(qr[i].sc.sc.ft); v2.pb(qr[i].sc.sc.sc);
v3.pb(qr[i].ft);
}
sort(qr+1, qr+1+q);
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
sort(v3.begin(), v3.end());
int ord=1;
for(auto x:v1){
ord1[x]=ord; ord++;
}
ord=1;
for(auto x:v2){
ord2[x]=ord; ord++;
}
ord=1;
for(auto x:v3){
ord3[x]=ord; ord++;
}
int ind=n;
for(int i=q; i>=1; i--){
while( (ind>=1) && (pr[ind].ft>=qr[i].ft) ){
update1(t1, 1, 2*n, 1, 2*n, ord1[pr[ind].sc.ft], ord2[pr[ind].sc.sc]);
ind--;
}
res[qr[i].sc.ft ]=query1(t1, 1, n*2, 1, n*2, ord1[qr[i].sc.sc.ft], n*2, ord2[qr[i].sc.sc.sc], n*2);
}
for(int i=1; i<=q; i++){
cout<<res[i]<<"\n";
}
n++;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
32 ms |
12420 KB |
Output is correct |
8 |
Correct |
32 ms |
12324 KB |
Output is correct |
9 |
Correct |
32 ms |
12328 KB |
Output is correct |
10 |
Correct |
22 ms |
8064 KB |
Output is correct |
11 |
Correct |
22 ms |
7880 KB |
Output is correct |
12 |
Correct |
9 ms |
972 KB |
Output is correct |
13 |
Correct |
34 ms |
12236 KB |
Output is correct |
14 |
Correct |
32 ms |
12268 KB |
Output is correct |
15 |
Correct |
33 ms |
12280 KB |
Output is correct |
16 |
Correct |
15 ms |
4300 KB |
Output is correct |
17 |
Correct |
18 ms |
4972 KB |
Output is correct |
18 |
Correct |
6 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2613 ms |
658892 KB |
Output is correct |
2 |
Correct |
2653 ms |
658932 KB |
Output is correct |
3 |
Correct |
2564 ms |
658864 KB |
Output is correct |
4 |
Correct |
1261 ms |
324988 KB |
Output is correct |
5 |
Correct |
1083 ms |
316716 KB |
Output is correct |
6 |
Correct |
388 ms |
8104 KB |
Output is correct |
7 |
Correct |
2295 ms |
625308 KB |
Output is correct |
8 |
Correct |
2277 ms |
626480 KB |
Output is correct |
9 |
Correct |
2045 ms |
592148 KB |
Output is correct |
10 |
Correct |
671 ms |
137200 KB |
Output is correct |
11 |
Correct |
846 ms |
150976 KB |
Output is correct |
12 |
Correct |
315 ms |
6868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2613 ms |
658892 KB |
Output is correct |
2 |
Correct |
2653 ms |
658932 KB |
Output is correct |
3 |
Correct |
2564 ms |
658864 KB |
Output is correct |
4 |
Correct |
1261 ms |
324988 KB |
Output is correct |
5 |
Correct |
1083 ms |
316716 KB |
Output is correct |
6 |
Correct |
388 ms |
8104 KB |
Output is correct |
7 |
Correct |
2295 ms |
625308 KB |
Output is correct |
8 |
Correct |
2277 ms |
626480 KB |
Output is correct |
9 |
Correct |
2045 ms |
592148 KB |
Output is correct |
10 |
Correct |
671 ms |
137200 KB |
Output is correct |
11 |
Correct |
846 ms |
150976 KB |
Output is correct |
12 |
Correct |
315 ms |
6868 KB |
Output is correct |
13 |
Correct |
2648 ms |
661384 KB |
Output is correct |
14 |
Correct |
2790 ms |
660724 KB |
Output is correct |
15 |
Correct |
2705 ms |
659024 KB |
Output is correct |
16 |
Correct |
1156 ms |
322736 KB |
Output is correct |
17 |
Correct |
1125 ms |
324064 KB |
Output is correct |
18 |
Correct |
399 ms |
8124 KB |
Output is correct |
19 |
Correct |
2437 ms |
661604 KB |
Output is correct |
20 |
Correct |
2632 ms |
661264 KB |
Output is correct |
21 |
Correct |
2203 ms |
639720 KB |
Output is correct |
22 |
Correct |
695 ms |
144116 KB |
Output is correct |
23 |
Correct |
803 ms |
150692 KB |
Output is correct |
24 |
Correct |
314 ms |
6920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
32 ms |
12420 KB |
Output is correct |
8 |
Correct |
32 ms |
12324 KB |
Output is correct |
9 |
Correct |
32 ms |
12328 KB |
Output is correct |
10 |
Correct |
22 ms |
8064 KB |
Output is correct |
11 |
Correct |
22 ms |
7880 KB |
Output is correct |
12 |
Correct |
9 ms |
972 KB |
Output is correct |
13 |
Correct |
34 ms |
12236 KB |
Output is correct |
14 |
Correct |
32 ms |
12268 KB |
Output is correct |
15 |
Correct |
33 ms |
12280 KB |
Output is correct |
16 |
Correct |
15 ms |
4300 KB |
Output is correct |
17 |
Correct |
18 ms |
4972 KB |
Output is correct |
18 |
Correct |
6 ms |
716 KB |
Output is correct |
19 |
Correct |
2613 ms |
658892 KB |
Output is correct |
20 |
Correct |
2653 ms |
658932 KB |
Output is correct |
21 |
Correct |
2564 ms |
658864 KB |
Output is correct |
22 |
Correct |
1261 ms |
324988 KB |
Output is correct |
23 |
Correct |
1083 ms |
316716 KB |
Output is correct |
24 |
Correct |
388 ms |
8104 KB |
Output is correct |
25 |
Correct |
2295 ms |
625308 KB |
Output is correct |
26 |
Correct |
2277 ms |
626480 KB |
Output is correct |
27 |
Correct |
2045 ms |
592148 KB |
Output is correct |
28 |
Correct |
671 ms |
137200 KB |
Output is correct |
29 |
Correct |
846 ms |
150976 KB |
Output is correct |
30 |
Correct |
315 ms |
6868 KB |
Output is correct |
31 |
Correct |
2648 ms |
661384 KB |
Output is correct |
32 |
Correct |
2790 ms |
660724 KB |
Output is correct |
33 |
Correct |
2705 ms |
659024 KB |
Output is correct |
34 |
Correct |
1156 ms |
322736 KB |
Output is correct |
35 |
Correct |
1125 ms |
324064 KB |
Output is correct |
36 |
Correct |
399 ms |
8124 KB |
Output is correct |
37 |
Correct |
2437 ms |
661604 KB |
Output is correct |
38 |
Correct |
2632 ms |
661264 KB |
Output is correct |
39 |
Correct |
2203 ms |
639720 KB |
Output is correct |
40 |
Correct |
695 ms |
144116 KB |
Output is correct |
41 |
Correct |
803 ms |
150692 KB |
Output is correct |
42 |
Correct |
314 ms |
6920 KB |
Output is correct |
43 |
Correct |
2577 ms |
686088 KB |
Output is correct |
44 |
Correct |
2594 ms |
686420 KB |
Output is correct |
45 |
Correct |
2788 ms |
686116 KB |
Output is correct |
46 |
Correct |
1190 ms |
350152 KB |
Output is correct |
47 |
Correct |
1163 ms |
339784 KB |
Output is correct |
48 |
Correct |
367 ms |
7844 KB |
Output is correct |
49 |
Correct |
2495 ms |
653844 KB |
Output is correct |
50 |
Correct |
2321 ms |
655352 KB |
Output is correct |
51 |
Correct |
2213 ms |
622100 KB |
Output is correct |
52 |
Correct |
837 ms |
188996 KB |
Output is correct |
53 |
Correct |
897 ms |
192912 KB |
Output is correct |