Submission #254827

#TimeUsernameProblemLanguageResultExecution timeMemory
254827imeimi2000Fish (IOI08_fish)C++17
0 / 100
386 ms21368 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; const int sz = 1 << 19; int n, k, mod; pii L[500001]; int cnt[500001]; int seg1[sz << 1], seg2[sz << 1]; bool used[500001]; void update(int seg[], int i, int x) { seg[i += sz] += x; while (i /= 2) seg[i] = seg[i + i] * seg[i + i + 1] % mod; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k >> mod; for (int i = 1; i <= n; ++i) { cin >> L[i].first >> L[i].second; } sort(L + 1, L + (n + 1)); int j; for (j = 1; j <= n; ++j) { if (L[j].first * 2 > L[n].first) break; ++cnt[L[j].second]; } fill(seg1, seg1 + (sz << 1), 1); fill(seg2, seg2 + (sz << 1), 1); for (int i = 1; i <= k; ++i) { update(seg1, i, cnt[i]); update(seg2, i, cnt[i]); } int ans = 0; for (int i = n; i > 0; --i) { if (used[L[i].second]) continue; used[L[i].second] = 1; while (j > 1 && L[j - 1].first * 2 > L[i].first) { int c = L[--j].second; update(seg2, c, -1); if (seg1[c + sz] == 1) continue; update(seg1, c, -1); } ans = (ans + seg1[1]) % mod; int p = seg1[L[i].second + sz] - 1; update(seg1, L[i].second, -p); if (i < n && p == cnt[L[i].second]) { update(seg2, L[i].second, -p); ans = (ans + seg2[1]) % mod; update(seg2, L[i].second, p); } } printf("%d\n", ans); 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...