제출 #364277

#제출 시각아이디문제언어결과실행 시간메모리
364277dolphingarlicFish (IOI08_fish)C++14
0 / 100
445 ms20588 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; int n, k, m, segtree[2000000]; tuple<int, int, int> f[500000]; pair<int, int> mx[500000]; int ord[500000], idx[500000]; void increment(int pos, int node = 1, int l = 0, int r = k - 1) { if (l == r) segtree[node] = (segtree[node] + 1) % m; else { int mid = (l + r) / 2; if (pos > mid) increment(pos, node * 2 + 1, mid + 1, r); else increment(pos, node * 2, l, mid); segtree[node] = (segtree[node * 2] * segtree[node * 2 + 1]) % m; } } int query(int pos, int node = 1, int l = 0, int r = k - 1) { if (l > pos) return 1; if (r <= pos) return segtree[node]; int mid = (l + r) / 2; return (query(pos, node * 2, l, mid) * query(pos, node * 2 + 1, mid + 1, r)) % m; } int main() { cin.tie(0)->sync_with_stdio(0); cin >> n >> k >> m; fill(segtree, segtree + 4 * k, 1); for (int i = 0; i < n; i++) { int l, t; cin >> l >> t; t--; mx[t] = max(mx[t], {l, i}); f[i] = {l, t, i}; } sort(f, f + n); iota(ord, ord + k, 0); sort(ord, ord + k, [](int A, int B) { return mx[A] < mx[B]; }); for (int i = 0; i < k; i++) idx[ord[i]] = i; int ans = 0; for (int i = 0, j = 0; i < n; i++) { while (get<0>(f[i]) >= get<0>(f[j]) * 2) increment(idx[get<1>(f[j++])]); if (get<2>(f[i]) == mx[get<1>(f[i])].second) ans = (ans + query(idx[get<1>(f[i])])) % m; } 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...