Submission #501876

#TimeUsernameProblemLanguageResultExecution timeMemory
501876600MihneaFish (IOI08_fish)C++17
70 / 100
3090 ms41172 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct Fish { int sz; int tp; }; bool operator < (Fish a, Fish b) { return a.sz < b.sz; } const int N = (int) 5e5 + 7; int n, k, mod; Fish a[N]; vector<int> aux[N], oftp[N]; int caneat(int f, int s) { int low = 0, high = (int) oftp[s].size() - 1, sol = 0; while (low <= high) { int mid = (low + high) / 2; if (a[oftp[f].back()].sz >= 2 * a[oftp[s][mid]].sz) { sol = mid + 1; low = mid + 1; } else { high = mid - 1; } } return sol; } int aux_order[N]; bool cmp(int i, int j) { return aux[i].back() < aux[j].back(); } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> mod; for (int i = 1; i <= n; i++) { cin >> a[i].sz >> a[i].tp; } sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) { aux[a[i].tp].push_back(i); } n = k; for (int i = 1; i <= n; i++) { aux_order[i] = i; } sort(aux_order + 1, aux_order + n + 1, cmp); for (int i = 1; i <= n; i++) oftp[i] = aux[aux_order[i]]; for (int i = 1; i <= n; i++) aux[i] = oftp[i]; int print = 0; for (int i = n; i >= 1; i--) { int full = 1, semi = caneat(i, i); int last = i, low = i + 1, high = n; while (low <= high) { int j = (low + high) / 2; if (caneat(j, i) == caneat(i, i)) { last = j; low = j + 1; } else { high = j - 1; } } for (int j = i + 1; j <= last; j++) { full = full * (ll) (caneat(i, j) + 1) % mod; } int sol = 1; for (int j = 1; j < i; j++) { sol = sol * (ll) (caneat(i, j) + 1) % mod; } full = full * (ll) sol % mod; semi = semi * (ll) sol % mod; print = (print + full) % mod; print = (print + semi) % mod; } cout << print << "\n"; return 0; } /** **/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...