Submission #1108755

#TimeUsernameProblemLanguageResultExecution timeMemory
1108755kyaruruFish (IOI08_fish)C++17
100 / 100
424 ms47816 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int a, b, c; cin >> a >> b >> c; pll k[a + 1]; for (int i = 1; i <= a; i++) { ll x, y; cin >> x >> y; k[i] = {x, y}; } int h = ceil(log2(b)); int n = (1 << h) - 1; vector<ll> seg(1 << (h + 1), 1), sega(1 << (h + 1), 1); sort(k + 1, k + a + 1); ll ed[b + 1], sv[b + 1], u[b + 1]; memset(ed, -1, sizeof(ed)); memset(u, -1, sizeof(u)); memset(sv, 0, sizeof(sv)); int m = b; for (int i = a; i >= 1; i--) { if (ed[k[i].second] == -1) ed[k[i].second] = m--; k[i].second = ed[k[i].second]; } vector<int> ka; memset(ed, -1, sizeof(ed)); for (int i = a; i >= 1; i--) { if (ed[k[i].second] == -1) ed[k[i].second] = i, ka.push_back(k[i].first),u[k[i].second]=k[i].first; else if (2 * k[i].first > k[ed[k[i].second]].first) u[k[i].second] = k[i].first; } sort(ka.begin(), ka.end()); ll r = 1, ans = 0; for (int i = 1; i <= a; i++) { while (2 * k[r].first <= k[i].first) { if (ed[k[r].second] < i) { int j = k[r].second + n; seg[j]++; for (j /= 2; j >= 1; j /= 2) seg[j] = seg[2 * j] * seg[2 * j + 1] % c; } else sv[k[r].second]++; int j = k[r].second + n; sega[j]++; for (j /= 2; j >= 1; j /= 2) sega[j] = sega[2 * j] * sega[2 * j + 1] % c; r++; } if (ed[k[i].second] == i) { int j = k[i].second + n; seg[j] += sv[k[i].second]; for (j /= 2; j >= 1; j /= 2) seg[j] = seg[2 * j] * seg[2 * j + 1] % c; ans = (ans + seg[1]) % c; j = k[i].second + n; ll p = sega[j]; sega[j] = seg[j] = 1; for (j /= 2; j >= 1; j /= 2) { sega[j] = sega[2 * j] * sega[2 * j + 1] % c; seg[j] = seg[2 * j] * seg[2 * j + 1] % c; } int v = u[k[i].second] == -1 ? b : lower_bound(ka.begin(), ka.end(), 2 * u[k[i].second]) - ka.begin(); ll l = 1 + n, r = v + n, t = 1, tt = 1; while (l <= r) { if (l % 2 == 1) { t = t * sega[l] % c; tt = tt * seg[l] % c; l++; } if (r % 2 == 0) { t = t * sega[r] % c; tt = tt * seg[r] % c; r--; } l /= 2, r /= 2; } ans += t - tt; j = k[i].second + n; sega[j] = seg[j] = p; for (j /= 2; j >= 1; j /= 2) { sega[j] = sega[2 * j] * sega[2 * j + 1] % c; seg[j] = seg[2 * j] * seg[2 * j + 1] % c; } } } cout << (ans % c + c) % c; }
#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...