Submission #1019587

#TimeUsernameProblemLanguageResultExecution timeMemory
1019587boyliguanhanFish (IOI08_fish)C++17
100 / 100
822 ms36892 KiB
#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 (stderr)

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;
      |                     ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...