# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
776576 | 2023-07-08T04:20:00 Z | salmon | Fish (IOI08_fish) | C++14 | 3000 ms | 12364 KB |
#include <bits/stdc++.h> using namespace std; int N,M; int mod; int l,h; vector<pair<int,int>> v; int main(){ scanf(" %d",&N); scanf(" %d",&M); scanf(" %d",&mod); int mep[500100]; int mepu[500100]; bool usable[M + 1]; for(int i = 1; i <= M; i++){ mep[i] = -1; mepu[i] = -1; } for(int i = 0; i <= M; i++) usable[i] = false; for(int i = 0; i < N; i++){ scanf(" %d",&l); scanf(" %d",&h); v.push_back(make_pair(l,h)); } sort(v.begin(),v.end(),greater<pair<int,int>>()); bool o[500100]; set<int> smol; vector<pair<int,int>> oh; for(int i = 0; i <= M; i++){ o[i] = true; } for(int i = 0; i < v.size(); i++){ if(o[v[i].second]){ oh.push_back(v[i]); o[v[i].second] = false; } } int it = 0; reverse(v.begin(),v.end()); int bigans = 0; vector<pair<int,int>> tempuse; for(int i = 0; i < N; i++){ while(it != N && v[i].first >= v[it].first * 2){ if(usable[v[it].second]){ if(mep[v[it].second] == -1){ mep[v[it].second] = 1; } else{ mep[v[it].second]++; } it++; } else{ if(mepu[v[it].second] == -1){ mepu[v[it].second] = 1; } else{ mepu[v[it].second]++; } it++; } } if(v[i] == oh.back()){ if(mepu[oh.back().second] != -1){ mep[oh.back().second] = mepu[oh.back().second]; } usable[oh.back().second] = true; long long int ans = 1; for(int i = 1; i <= M; i++){ if(mep[i] != -1){ ans = ans * (mep[i] + 1) % mod; } } bigans += ans; bigans %= mod; oh.pop_back(); long long int sub = 1; ans = 1; for(int j = 0; j < oh.size(); j++){ if(oh[j].first < v[i].first * 2){ bool flag = false; for(int k = it; k < i; k++){ if(oh[j].first >= v[k].first * 2 && v[k].second == v[i].second) flag = true; } if(flag) continue; if(mepu[oh[j].second] != -1){ ans *= (1 + mepu[oh[j].second]); ans %= mod; } } } ans %= mod; sub %= mod; for(int j = 1; j <= M; j++){ if(mep[j] != -1 && j != v[i].second){ ans = ans * (mep[j] + 1) % mod; sub = sub * (mep[j] + 1) % mod; } } ans -= sub; ans =(ans + mod) % mod; bigans += ans; bigans %= mod; //printf("%d %d %d %d\n",v[i].first,bigans,ans,sub); } } printf("%d",bigans); } /* * 5 3 700 8 3 7 2 4 1 2 3 2 2 * */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4692 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4692 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4736 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4692 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4700 KB | Output is correct |
2 | Correct | 2 ms | 4692 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4692 KB | Output is correct |
2 | Correct | 169 ms | 8928 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 4604 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 4720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2180 ms | 6808 KB | Output is correct |
2 | Correct | 1035 ms | 6856 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1380 ms | 4748 KB | Output is correct |
2 | Correct | 1279 ms | 4796 KB | Output is correct |
3 | Correct | 1173 ms | 4744 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3067 ms | 8824 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2666 ms | 8932 KB | Output is correct |
2 | Execution timed out | 3046 ms | 8892 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3041 ms | 8916 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3044 ms | 8868 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3044 ms | 9008 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3063 ms | 8976 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3053 ms | 11560 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3069 ms | 11556 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3044 ms | 12364 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |