# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104280 | janchomath | Fish (IOI08_fish) | C++14 | 3088 ms | 13432 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>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,k,m,dp[500005],sum[500005],last[500005],ans,cur,raod[500005];
pair<ll,ll>a[500005];
ll pw(ll a,ll b){
ll xar = a;
ll ans = 1;
while(b>0){
if(b%2==1)ans=(ans*xar)%m;
b/=2;
xar=(xar*xar)%m;
}
return ans%m;
}
int main(){
cin >> n >> k >> m;
for(int i=2; i<m; i++){
if(m % i == 0){
while(true);
}
}
for(int i=1; i<=n; i++){
cin >> a[i].f >> a[i].s;
}
sort(a+1,a+n+1);
cur = 1LL;
for(int i=1; i<=n; i++){
ll l = 1,r = i - 1,mid,ind = 0;
while(r >= l){
mid = (l + r) / 2;
if(2 * a[mid].f <= a[i].f){
l = mid + 1;
ind = mid;
}
else {
r = mid - 1;
}
}
raod[a[i].s]++;
cur = cur * pw(raod[a[i].s],m - 2LL);
cur %= m;
dp[i] = cur - sum[a[i].s];
dp[i] += m;
dp[i] %= m;
ans += dp[i];
ans %= m;
sum[a[i].s] += dp[i];
sum[a[i].s] %= m;
cur *= (raod[a[i].s] + 1LL);
cur %= m;
}
cout << ans << endl;
return 0;
}
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... |