Submission #416066

#TimeUsernameProblemLanguageResultExecution timeMemory
416066AntekbFish (IOI08_fish)C++14
4 / 100
3098 ms9900 KiB
#include<bits/stdc++.h> #define st first #define nd second using namespace std; const int N=5e5+5; int tab[N], czy[N], ile[N]; int m; typedef long long ll; int main(){ int n, k; cin>>n>>k>>m; for(int i=0; i<k; i++)tab[i]=1; vector<pair<int, int> > V(n); for(auto &i:V)cin>>i.st>>i.nd, i.nd--; sort(V.begin(), V.end()); int wsk=0; while(V[wsk].st*2<=V.back().st){ tab[V[wsk].nd]++; ile[V[wsk].nd]++; wsk++; } int ans=0; for(int i=n-1; i>=0; i--){ if(czy[V[i].nd])continue; while(wsk && V[wsk-1].st*2>V[i].st){ tab[V[--wsk].nd]--; } //for(int j=0; j<k; j++)cout<<tab[j]<<" "; //cout<<"\n"; int t=1; for(int j=0; j<k; j++){ if(!czy[j])t=(t*1ll*tab[j])%m; } ans+=t; //cout<<t<<" "; if(i+1-n && tab[V[i].nd]>ile[V[i].nd]){ t=1; int u=1; for(int j=0; j<k; j++){ if(j!=V[i].nd && !czy[j])t=(t*1ll*tab[j])%m; if(czy[j])u=(u*1ll*tab[j])%m; } ans+=(t*1ll*(u-1))%m; //cout<<t*(u-1)<<" "; } czy[V[i].nd]=1; //cout<<"\n"; } cout<<((ans%m)+m)%m; }
#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...