# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
369920 | arnold518 | Fish (IOI08_fish) | C++14 | 459 ms | 65540 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 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=dp3[i][i], t2=1;
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)
# | 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... |