# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
776574 | 2023-07-08T04:17:21 Z | salmon | Fish (IOI08_fish) | C++14 | 3000 ms | 19220 KB |
#include <bits/stdc++.h> using namespace std; int N,M; int mod; int l,h; const int sq = 200; 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>>()); set<int> o; set<int> smol; vector<pair<int,int>> oh; for(int i = 0; i < v.size(); i++){ if(o.find(v[i].second) == o.end()){ oh.push_back(v[i]); o.insert(v[i].second); } } 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 | 2 ms | 4180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 4180 KB | Output is correct |
2 | Correct | 3 ms | 4180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4180 KB | Output is correct |
2 | Correct | 186 ms | 8536 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 4180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 4180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1617 ms | 6304 KB | Output is correct |
2 | Correct | 756 ms | 6344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 945 ms | 4344 KB | Output is correct |
2 | Correct | 719 ms | 4308 KB | Output is correct |
3 | Correct | 738 ms | 4316 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3032 ms | 8344 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1847 ms | 8336 KB | Output is correct |
2 | Execution timed out | 3048 ms | 8376 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3056 ms | 8352 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3055 ms | 8384 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3074 ms | 9100 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3056 ms | 10072 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3067 ms | 16132 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3047 ms | 16216 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 3069 ms | 19220 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |