Submission #1011931

#TimeUsernameProblemLanguageResultExecution timeMemory
1011931thinknoexitFish (IOI08_fish)C++17
0 / 100
325 ms14384 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 500500; int MOD, n; pair<int, int> a[N]; int tree[4 * N]; void build(int now = 1, int l = 1, int r = n) { tree[now] = 1; if (l == r) return; int mid = (l + r) / 2; build(2 * now, l, mid), build(2 * now + 1, mid + 1, r); } void update(int v, int now = 1, int l = 1, int r = n) { if (l == r) { tree[now] = (tree[now] + 1) % MOD; return; } int mid = (l + r) / 2; if (v <= mid) update(v, 2 * now, l, mid); else update(v, 2 * now + 1, mid + 1, r); tree[now] = tree[2 * now] * tree[2 * now + 1] % MOD; } int query(int ql, int qr, int now = 1, int l = 1, int r = n) { if (ql > qr) return 1; if (l > qr || r < ql) return 1; if (ql <= l && r <= qr) return tree[now]; int mid = (l + r) / 2; return query(ql, qr, 2 * now, l, mid) * query(ql, qr, 2 * now + 1, mid + 1, r) % MOD; } int main() { cin.tie(nullptr)->sync_with_stdio(false); int m; cin >> m >> n >> MOD; for (int i = 1;i <= m;i++) { cin >> a[i].first >> a[i].second; } sort(a + 1, a + 1 + n); build(); int ans = n % MOD; int p = 0; for (int i = 1;i <= m;i++) { while (p < i && a[p + 1].first * 2 <= a[i].first) { p++; update(a[p].second); } if (p != 0) ans = (ans + query(1, a[i].second - 1) * query(a[i].second + 1, n)) % MOD; } cout << 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...