# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
369928 | arnold518 | Fish (IOI08_fish) | C++14 | 616 ms | 22508 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |