#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int mod=0,ans;
vector<int>S[1<<19];
inline int cntof(int i,int j){
return lower_bound(S[j].begin(),S[j].end(),S[i].back()+2>>1)-S[j].begin();
}
struct segtree{
int T[1<<20];
segtree(){for(auto&i:T)i=1;}
void upd(int i,int l,int r,int p,int x){
if(l==r)return void(T[i]=(T[i]+x)%mod);
if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
else upd(i*2+1,l+r+2>>1,r,p,x);
T[i]=T[i*2]*T[i*2+1]%mod;
}
int qry(int i,int l,int r,int ll,int rr){
if(l>rr||ll>r)return 1;
if(ll<=l&&r<=rr)return T[i];
return qry(i*2,l,l+r>>1,ll,rr)*
qry(i*2+1,l+r+2>>1,r,ll,rr)%mod;
}
} ST;
void dothestuf(int l,int r,int x,int k){
ans=(ans+mod+x*ST.qry(1,1,k,l,r))%mod;
}
vector<int>order;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n,k;
cin>>n>>k>>mod;
vector<pair<int,int>>anchovies;
for(int i=1;i<=n;i++){
int a,b;cin>>a>>b;
S[b].push_back(a);
}
for(int i=1;i<=k;i++)
sort(S[i].begin(),S[i].end());
sort(S+1,S+k+1,[](vector<int>a,vector<int>b){
return a.back()<b.back();
});
for(int i=1;i<=k;i++) for(auto j:S[i])
anchovies.push_back({j,i});
sort(anchovies.begin(),anchovies.end());
int ID=0;
for(int i=1;i<=k;i++){
while(ID<n&&anchovies[ID].first<=S[i].back()/2)
ST.upd(1,1,k,anchovies[ID++].second,1);
ST.upd(1,1,k,i,-1);
dothestuf(1,i,1,k);
int kv=S[i][cntof(i,i)];
int v2=k+1,l=1,r=k;
while(l<=r){
int mid=l+r>>1;
if(S[mid].back()>=2*kv)
r=mid-1,v2=mid;
else l=mid+1;
}
dothestuf(1,v2-1,-1,k);
ST.upd(1,1,k,i,1);
dothestuf(1,v2-1,1,k);
}
cout<<ans;
}
Compilation message
fish.cpp: In function 'int cntof(int, int)':
fish.cpp:7:59: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
7 | return lower_bound(S[j].begin(),S[j].end(),S[i].back()+2>>1)-S[j].begin();
| ~~~~~~~~~~~^~
fish.cpp: In member function 'void segtree::upd(int, int, int, int, int)':
fish.cpp:14:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
14 | if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
| ~^~
fish.cpp:14:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
14 | if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
| ~^~
fish.cpp:15:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
15 | else upd(i*2+1,l+r+2>>1,r,p,x);
| ~~~^~
fish.cpp: In member function 'int segtree::qry(int, int, int, int, int)':
fish.cpp:21:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
21 | return qry(i*2,l,l+r>>1,ll,rr)*
| ~^~
fish.cpp:22:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
22 | qry(i*2+1,l+r+2>>1,r,ll,rr)%mod;
| ~~~^~
fish.cpp: In function 'int main()':
fish.cpp:55:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int mid=l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
16732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
16728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16732 KB |
Output is correct |
2 |
Correct |
7 ms |
16732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16728 KB |
Output is correct |
2 |
Correct |
127 ms |
23556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
16728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
16728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
20360 KB |
Output is correct |
2 |
Correct |
76 ms |
20348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
16988 KB |
Output is correct |
2 |
Correct |
10 ms |
16828 KB |
Output is correct |
3 |
Correct |
10 ms |
16788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
22904 KB |
Output is correct |
2 |
Correct |
186 ms |
23696 KB |
Output is correct |
3 |
Correct |
209 ms |
24488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
124 ms |
24080 KB |
Output is correct |
2 |
Correct |
149 ms |
24072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
23232 KB |
Output is correct |
2 |
Correct |
153 ms |
23752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
154 ms |
23748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
24516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
23868 KB |
Output is correct |
2 |
Correct |
253 ms |
25796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
388 ms |
26096 KB |
Output is correct |
2 |
Correct |
303 ms |
26056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
351 ms |
27348 KB |
Output is correct |
2 |
Correct |
306 ms |
25756 KB |
Output is correct |
3 |
Correct |
445 ms |
30252 KB |
Output is correct |
4 |
Correct |
357 ms |
25900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
486 ms |
27336 KB |
Output is correct |
2 |
Correct |
822 ms |
36544 KB |
Output is correct |
3 |
Correct |
778 ms |
36892 KB |
Output is correct |
4 |
Correct |
783 ms |
33476 KB |
Output is correct |