#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=200050;
const int M=N*60;
const int lim=1e9;
int a[N],b[N],x[N],y[N];
int uid[N],qid[N],ans[N];
int ls[M],rs[M],tsz,root[2],sum[M];
void Set(int &c, int ss, int se, int qi)
{
if(!c) c=++tsz;
sum[c]++;
if(ss==se) return;
int mid=ss+se>>1;
if(qi<=mid) Set(ls[c],ss,mid,qi);
else Set(rs[c],mid+1,se,qi);
}
int Get(int c, int ss, int se, int qs, int qe)
{
if(qs>qe || qs>se || ss>qe) return 0;
if(qs<=ss && qe>=se) return sum[c];
int mid=ss+se>>1;
return Get(ls[c],ss,mid,qs,qe)+Get(rs[c],mid+1,se,qs,qe);
}
int main()
{
int n,q;
scanf("%i %i",&n,&q);
for(int i=1;i<=n;i++) scanf("%i %i",&a[i],&b[i]),uid[i]=i;
for(int i=1;i<=q;i++) scanf("%i %i",&x[i],&y[i]),qid[i]=i;
sort(uid+1,uid+1+n,[&](int i, int j){ return a[i]>a[j] || (a[i]==a[j] && b[i]>b[j]);});
sort(qid+1,qid+1+q,[&](int i, int j){ return x[i]>x[j];});
multiset<int> st;
int k=1;
for(int i=1,j;i<=n;i=j)
{
while(k<=q && (x[qid[k]]>a[uid[i]]))
{
ans[qid[k]]=Get(root[0],0,lim,0,y[qid[k]])-Get(root[1],0,lim,0,y[qid[k]]);
k++;
}
vector<int> tmp;
for(j=i;j<=n && a[uid[i]]==a[uid[j]];j++)
{
auto it=st.upper_bound(b[uid[j]]);
if(it!=st.end())
{
Set(root[1],0,lim,*it);
st.erase(it);
}
Set(root[0],0,lim,b[uid[j]]);
tmp.pb(b[uid[j]]);
}
for(int l:tmp) st.insert(l);
}
while(k<=q)
{
ans[qid[k]]=Get(root[0],0,lim,0,y[qid[k]])-Get(root[1],0,lim,0,y[qid[k]]);
k++;
}
for(int i=1;i<=q;i++) printf("%i\n",ans[i]);
return 0;
}
Compilation message
matryoshka.cpp: In function 'void Set(int&, int, int, int)':
matryoshka.cpp:15:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=ss+se>>1;
~~^~~
matryoshka.cpp: In function 'int Get(int, int, int, int, int)':
matryoshka.cpp:23:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=ss+se>>1;
~~^~~
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%i %i",&n,&q);
~~~~~^~~~~~~~~~~~~~~
matryoshka.cpp:30:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=n;i++) scanf("%i %i",&a[i],&b[i]),uid[i]=i;
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
matryoshka.cpp:31:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=q;i++) scanf("%i %i",&x[i],&y[i]),qid[i]=i;
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
760 KB |
Output is correct |
23 |
Correct |
9 ms |
1536 KB |
Output is correct |
24 |
Correct |
8 ms |
1400 KB |
Output is correct |
25 |
Correct |
8 ms |
1400 KB |
Output is correct |
26 |
Correct |
7 ms |
888 KB |
Output is correct |
27 |
Correct |
8 ms |
1400 KB |
Output is correct |
28 |
Correct |
7 ms |
760 KB |
Output is correct |
29 |
Correct |
7 ms |
1360 KB |
Output is correct |
30 |
Correct |
6 ms |
504 KB |
Output is correct |
31 |
Correct |
8 ms |
1400 KB |
Output is correct |
32 |
Correct |
8 ms |
1400 KB |
Output is correct |
33 |
Correct |
8 ms |
1420 KB |
Output is correct |
34 |
Correct |
8 ms |
1428 KB |
Output is correct |
35 |
Correct |
8 ms |
1400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
348 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
760 KB |
Output is correct |
23 |
Correct |
9 ms |
1536 KB |
Output is correct |
24 |
Correct |
8 ms |
1400 KB |
Output is correct |
25 |
Correct |
8 ms |
1400 KB |
Output is correct |
26 |
Correct |
7 ms |
888 KB |
Output is correct |
27 |
Correct |
8 ms |
1400 KB |
Output is correct |
28 |
Correct |
7 ms |
760 KB |
Output is correct |
29 |
Correct |
7 ms |
1360 KB |
Output is correct |
30 |
Correct |
6 ms |
504 KB |
Output is correct |
31 |
Correct |
8 ms |
1400 KB |
Output is correct |
32 |
Correct |
8 ms |
1400 KB |
Output is correct |
33 |
Correct |
8 ms |
1420 KB |
Output is correct |
34 |
Correct |
8 ms |
1428 KB |
Output is correct |
35 |
Correct |
8 ms |
1400 KB |
Output is correct |
36 |
Correct |
696 ms |
18680 KB |
Output is correct |
37 |
Correct |
438 ms |
11348 KB |
Output is correct |
38 |
Correct |
250 ms |
36060 KB |
Output is correct |
39 |
Correct |
408 ms |
9592 KB |
Output is correct |
40 |
Correct |
418 ms |
11128 KB |
Output is correct |
41 |
Correct |
462 ms |
11384 KB |
Output is correct |
42 |
Correct |
338 ms |
10644 KB |
Output is correct |
43 |
Correct |
275 ms |
18252 KB |
Output is correct |
44 |
Correct |
968 ms |
77304 KB |
Output is correct |
45 |
Correct |
981 ms |
77308 KB |
Output is correct |
46 |
Correct |
998 ms |
77212 KB |
Output is correct |
47 |
Correct |
817 ms |
76680 KB |
Output is correct |
48 |
Correct |
794 ms |
76648 KB |
Output is correct |
49 |
Correct |
778 ms |
76672 KB |
Output is correct |
50 |
Correct |
799 ms |
76660 KB |
Output is correct |