Submission #625909

#TimeUsernameProblemLanguageResultExecution timeMemory
625909tabrFish (IOI08_fish)C++17
9 / 100
755 ms23192 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; } 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]++; } map<int, int> freq0, freq1; auto Add = [&](map<int, int>& mp, int key, int val) { mp[key] += val; if (mp[key] == 0) { mp.erase(key); } }; auto Get = [&](map<int, int>& mp) { mint res = 1; for (auto [x, y] : mp) { res *= power(x + 1, y); } return res; }; for (int i = 0; i < k; i++) { Add(freq0, cnt[i], 1); } vector<int> mx(k); 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) { if (done.count(f[j].second)) { Add(freq1, cnt[f[j].second], -1); cnt[f[j].second]--; Add(freq1, cnt[f[j].second], +1); } else { Add(freq0, cnt[f[j].second], -1); cnt[f[j].second]--; Add(freq0, cnt[f[j].second], +1); } j--; } if (i == n - 1) { mx = cnt; } done.emplace(f[i].second); Add(freq0, cnt[f[i].second], -1); mint t0 = Get(freq0); mint t1 = Get(freq1); if (cnt[f[i].second] == mx[f[i].second]) { ans += t0 * (t1 - 1); } ans += t0 * (cnt[f[i].second] + 1); Add(freq1, cnt[f[i].second], +1); } 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...