Submission #369918

#TimeUsernameProblemLanguageResultExecution timeMemory
369918arnold518Fish (IOI08_fish)C++14
4 / 100
754 ms24044 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; 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]; ll ans; struct SEG { ll tree[MAXN*4+10]; void init() { for(int i=0; i<MAXN*4+10; i++) tree[i]=0; } void update(int node, int tl, int tr, int p, int k) { if(tl==tr) { tree[node]+=k; tree[node]%=MOD; return; } int mid=tl+tr>>1; if(p<=mid) update(node*2, tl, mid, p, k); else update(node*2+1, mid+1, tr, p, k); tree[node]=tree[node*2]*tree[node*2+1]%MOD; } ll query(int node, int tl, int tr, int l, int r) { if(l<=tl && tr<=r) return tree[node]; if(r<tl || tr<l) return 1; int mid=tl+tr>>1; return query(node*2, tl, mid, l, r)*query(node*2+1, mid+1, tr, l, r)%MOD; } }seg; 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); seg.init(); for(int i=1; i<=K; i++) seg.update(1, 1, K, i, 1); 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++) { seg.update(1, 1, K, B[j].second, 1); if(B[j].second<B[i].second && V[B[j].second]==K+1) V[B[j].second]=B[i].second; } ans+=seg.query(1, 1, K, 1, B[i].second); ans%=MOD; } seg.init(); for(int i=1; i<=K; i++) seg.update(1, 1, K, i, 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++) { seg.update(1, 1, K, B[j].second, 1); } if(B[i].second+1<=V[B[i].second]-1) { ll t=(seg.query(1, 1, K, B[i].second+1, V[B[i].second]-1)+MOD-1)%MOD; t*=seg.query(1, 1, K, 1, B[i].second-1); t%=MOD; t*=(seg.query(1, 1, K, B[i].second, B[i].second)+MOD-1)%MOD; t%=MOD; ans+=t; ans%=MOD; } } printf("%lld\n", ans); }

Compilation message (stderr)

fish.cpp: In member function 'void SEG::update(int, int, int, int, int)':
fish.cpp:36:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |   int mid=tl+tr>>1;
      |           ~~^~~
fish.cpp: In member function 'll SEG::query(int, int, int, int, int)':
fish.cpp:45:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |   int mid=tl+tr>>1;
      |           ~~^~~
fish.cpp: In function 'int main()':
fish.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |  scanf("%d%d%lld", &N, &K, &MOD);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:55:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |  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...