Submission #625922

#TimeUsernameProblemLanguageResultExecution timeMemory
625922tabrFish (IOI08_fish)C++17
0 / 100
565 ms23484 KiB
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif long long mod = 2; struct mint { long long value; mint(long long x = 0) { value = x % mod; if (value < 0) value += mod; } mint& operator+=(const mint& other) { if ((value += other.value) >= mod) value -= mod; return *this; } mint& operator-=(const mint& other) { if ((value -= other.value) < 0) value += mod; return *this; } mint& operator*=(const mint& other) { value = value * other.value % mod; return *this; } mint& operator/=(const mint& other) { long long a = 0, b = 1, c = other.value, m = mod; while (c != 0) { long long t = m / c; m -= t * c; swap(c, m); a -= t * b; swap(a, b); } a %= mod; if (a < 0) a += mod; value = value * a % mod; return *this; } friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; } friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; } friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; } friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; } mint& operator++() { return *this += 1; } mint& operator--() { return *this -= 1; } mint operator++(int) { mint result(*this); *this += 1; return result; } mint operator--(int) { mint result(*this); *this -= 1; return result; } mint operator-() const { return mint(-value); } bool operator==(const mint& rhs) const { return value == rhs.value; } bool operator!=(const mint& rhs) const { return value != rhs.value; } bool operator<(const mint& rhs) const { return value < rhs.value; } }; string to_string(const mint& x) { return to_string(x.value); } ostream& operator<<(ostream& stream, const mint& x) { return stream << x.value; } istream& operator>>(istream& stream, mint& x) { stream >> x.value; x.value %= mod; if (x.value < 0) x.value += mod; return stream; } mint power(mint a, long long n) { mint res = 1; while (n > 0) { if (n & 1) { res *= a; } a *= a; n >>= 1; } return res; } struct segtree { using T = mint; T e() { return 1; } T op(T x, T y) { return x * y; } int n; int size; vector<T> node; segtree() : segtree(0) {} segtree(int _n) { build(vector<T>(_n, e())); } segtree(const vector<T>& v) { build(v); } void build(const vector<T>& v) { n = (int) v.size(); if (n <= 1) { size = n; } else { size = 1 << (32 - __builtin_clz(n - 1)); } node.resize(2 * size, e()); for (int i = 0; i < n; i++) { node[i + size] = v[i]; } for (int i = size - 1; i > 0; i--) { node[i] = op(node[2 * i], node[2 * i + 1]); } } void set(int p, T v) { assert(0 <= p && p < n); p += size; node[p] = v; // update // node[p] += v; // add while (p > 1) { p >>= 1; node[p] = op(node[2 * p], node[2 * p + 1]); } } T get(int l, int r) { assert(0 <= l && l <= r && r <= n); T vl = e(); T vr = e(); l += size; r += size; while (l < r) { if (l & 1) { vl = op(vl, node[l++]); } if (r & 1) { vr = op(node[--r], vr); } l >>= 1; r >>= 1; } return op(vl, vr); } T get(int p) { assert(0 <= p && p < n); return node[p + size]; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k >> mod; vector<pair<int, int>> f(n); for (int i = 0; i < n; i++) { cin >> f[i].first >> f[i].second; f[i].second--; } sort(f.begin(), f.end()); vector<int> cnt(k); for (int i = 0; i < n; i++) { cnt[f[i].second]++; } vector<int> mx(k, -1); for (int i = 0; i < n; i++) { mx[f[i].second] = i; } segtree seg(n); for (int i = 0; i < k; i++) { if (mx[i] != -1) { seg.set(mx[i], cnt[i] + 1); } } mint ans = 0; set<int> done; for (int i = n - 1, j = n - 1; i >= 0; i--) { if (done.count(f[i].second)) { continue; } while (j >= 0 && f[j].first * 2 > f[i].first) { seg.set(mx[f[j].second], cnt[f[j].second]); cnt[f[j].second]--; j--; } seg.set(mx[f[i].second], 1); int lim = (int) (upper_bound(f.begin(), f.end(), make_pair(2 * f[i].first + 1, -1)) - f.begin()); ans += seg.node[1] + seg.get(0, lim) * cnt[f[i].second]; seg.set(mx[f[i].second], cnt[f[i].second] + 1); debug(ans); done.emplace(f[i].second); } cout << ans << '\n'; 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...