# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
369928 | 2021-02-22T18:41:07 Z | arnold518 | Fish (IOI08_fish) | C++14 | 616 ms | 22508 KB |
#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 SEGN = 524288; 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[SEGN*2+10]; void init() { for(int i=0; i<SEGN*2+10; i++) tree[i]=1; } void update(int p) { p+=SEGN; tree[p]++; tree[p]%=MOD; for(int node=p>>1; node; node>>=1) tree[node]=tree[node<<1]*tree[node<<1|1]%MOD; } ll query(int l, int r) { ll ret=1; r++; for(l+=SEGN, r+=SEGN; l<r; l>>=1, r>>=1) { if(l&1) ret=ret*tree[l++]%MOD; if(r&1) ret=ret*tree[--r]%MOD; } return ret; } }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; seg.init(); 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(B[j].second); if(B[j].second<B[i].second && V[B[j].second]==K+1) V[B[j].second]=B[i].second; } ans+=seg.query(1, B[i].second); ans%=MOD; } seg.init(); 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(B[j].second); } if(B[i].second+1<=V[B[i].second]-1) { ll t=(seg.query(B[i].second+1, V[B[i].second]-1)+MOD-1)%MOD; t*=seg.query(1, B[i].second-1); t%=MOD; ans+=t; ans%=MOD; } } printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 8556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8556 KB | Output is correct |
2 | Correct | 6 ms | 8556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8556 KB | Output is correct |
2 | Correct | 248 ms | 12524 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 8556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 105 ms | 10092 KB | Output is correct |
2 | Correct | 156 ms | 10580 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 8556 KB | Output is correct |
2 | Correct | 9 ms | 8684 KB | Output is correct |
3 | Correct | 10 ms | 8684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 146 ms | 11116 KB | Output is correct |
2 | Correct | 342 ms | 12656 KB | Output is correct |
3 | Correct | 259 ms | 12524 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 313 ms | 12524 KB | Output is correct |
2 | Correct | 252 ms | 12524 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 136 ms | 10988 KB | Output is correct |
2 | Correct | 251 ms | 12780 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 237 ms | 12268 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 257 ms | 12908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 204 ms | 12652 KB | Output is correct |
2 | Correct | 226 ms | 14444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 350 ms | 15100 KB | Output is correct |
2 | Correct | 267 ms | 14060 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 370 ms | 15072 KB | Output is correct |
2 | Correct | 337 ms | 14444 KB | Output is correct |
3 | Correct | 405 ms | 16364 KB | Output is correct |
4 | Correct | 338 ms | 14444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 462 ms | 16492 KB | Output is correct |
2 | Correct | 518 ms | 22508 KB | Output is correct |
3 | Correct | 412 ms | 22212 KB | Output is correct |
4 | Correct | 616 ms | 20460 KB | Output is correct |