Submission #369922

#TimeUsernameProblemLanguageResultExecution timeMemory
369922arnold518Fish (IOI08_fish)C++14
4 / 100
461 ms65540 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 5e5; const int MAXK = 7000; int N, K; ll MOD; pii B[MAXN+10]; int C[MAXN+10]; int cnt[MAXN+10]; pii P[MAXN+10]; int I[MAXN+10]; int A[MAXK+10][MAXK+10]; ll dp2[MAXK+10][MAXK+10]; ll dp3[MAXK+10][MAXK+10]; ll dp[MAXK+10]; int V[MAXN+10]; int main() { scanf("%d%d%lld", &N, &K, &MOD); for(int i=1; i<=N; i++) scanf("%d%d", &B[i].first, &B[i].second); sort(B+1, B+N+1); for(int i=1; i<=K; i++) P[i].second=i; for(int i=1; i<=N; i++) { P[B[i].second].first=B[i].first; } sort(P+1, P+K+1); for(int i=1; i<=K; i++) I[P[i].second]=i; for(int i=1; i<=N; i++) B[i].second=I[B[i].second]; for(int i=1; i<=N; i++) C[B[i].second]=i; //for(int i=1; i<=N; i++) printf("%d %d\n", B[i].first, B[i].second); for(int i=1; i<=K; i++) V[i]=K+1; for(int i=1, j=1; i<=N; i++) { if(C[B[i].second]!=i) continue; for(; j<=N && B[j].first*2<=B[i].first; j++) { cnt[B[j].second]++; if(B[j].second<B[i].second && V[B[j].second]==K+1) V[B[j].second]=B[i].second; } for(int k=1; k<=K; k++) A[B[i].second][k]=cnt[k]; } for(int i=1; i<=K; i++) { dp2[i][0]=dp3[i][0]=1; for(int j=1; j<=K; j++) { dp2[i][j]=dp2[i][j-1]*(A[i][j]+1)%MOD; if(i!=j) dp3[i][j]=dp3[i][j-1]*(A[i][j]+1)%MOD; else dp3[i][j]=dp3[i][j-1]; } } ll ans=0; for(int i=1; i<=K; i++) { ans+=dp2[i][i]; ans%=MOD; ll t=1, t2=1; for(int j=1; j<i; j++) { t=t*(A[i][j]+1)%MOD; } t=t*A[i][i]%MOD; for(int j=i+1; j<V[i]; j++) { t2=t2*(A[i][j]+1)%MOD; } t2=(t2+MOD-1)%MOD; ans+=t*t2%MOD; ans%=MOD; } printf("%lld\n", ans); }

Compilation message (stderr)

fish.cpp: In function 'int main()':
fish.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |  scanf("%d%d%lld", &N, &K, &MOD);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:30:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   30 |  for(int i=1; i<=N; i++) scanf("%d%d", &B[i].first, &B[i].second);
      |                          ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...