Submission #1108754

#TimeUsernameProblemLanguageResultExecution timeMemory
1108754kyaruruFish (IOI08_fish)C++17
16 / 100
207 ms22248 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll a, b, c; void update(vector<ll>& seg, int idx, ll value) { seg[idx] += value; for (idx /= 2; idx >= 1; idx /= 2) seg[idx] = seg[2 * idx] * seg[2 * idx + 1]; } ll query(vector<ll>& seg, int l, int r) { ll v = 1; while (l <= r) { if (l % 2 == 1) v *= seg[l++] % c; if (r % 2 == 0) v *= seg[r--] % c; l /= 2, r /= 2; } return v; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); 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); 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 g = 1, ans = 0; for (int i = 1; i <= a; i++) { while (2 * k[g].first <= k[i].first) update(sega, k[g++].second + n, 1); if (ed[k[i].second] == i) { ans += query(sega, 1 + n, k[i].second + n); int v = u[k[i].second] == -1 ? b : lower_bound(ka.begin(), ka.end(), 2 * u[k[i].second]) - ka.begin(); ll t = query(sega, k[i].second + 1 + n, v + n) - 1; ll tt = query(sega, 1 + n, k[i].second - 1 + n); ans += t * tt; } } 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...