Submission #963349

#TimeUsernameProblemLanguageResultExecution timeMemory
963349fzyzzz_zFish (IOI08_fish)C++17
9 / 100
265 ms32372 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 500005; int m; struct seg { vector<int> t; seg(vector<int> f) { t = vector<int>(2 * f.size()); for (int i = 0; i < f.size(); ++i) t[i + f.size()] = f[i] + 1; for (int i = f.size() - 1; i >= 1; --i) t[i] = ((ll)t[2 * i] * t[2 * i + 1]) % m; } void upd(int p, int v) { p += t.size() / 2; if (t[p] == 1 && t[p] + v <= 1) return; t[p] += v; t[p] = max(t[p], 1); for (; p > 1; p /= 2) { t[p / 2] = ((ll)t[p] * t[p ^ 1]) % m; } } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, k; cin >> n >> k >> m; vector<int> f(k, 0); vector<pair<int, int>> a(n); for (auto & [x, y]: a) { cin >> x >> y; f[--y]++; } seg s(f), s2(f); sort(a.begin(), a.end(), greater<pair<int, int>>()); int ans = 0; f = vector<int>(k, 0); vector<int> bad(k, 0), mx(k, 0); for (int i = 0; i < n; ++i) if (a[i].first * 2 > a[0].first) bad[a[i].second]++; vector<vector<int>> s0(n + 1); for (int i = 0, j = 0; i < n; ++i) { for (auto x: s0[i]) s2.upd(x, -n); if (f[a[i].second]) continue; f[a[i].second] = 1; while (a[j].first * 2 > a[i].first && j < n) { s.upd(a[j].second, -1); s2.upd(a[j].second, -1); bad[a[j].second]--; j++; } // use 0 of prev type ans += s.t[1]; // cout << "A " << s.t[1] << '\n'; if (bad[a[i].second] >= 0) { int ov = s2.t[a[i].second + k]; // must use max of cur type s2.upd(a[i].second, -n); ans += s2.t[1]; // cout << "B " << s2.t[1] << '\n'; s2.upd(a[i].second, ov - 1); // must use max of cur and 0 of prev s.upd(a[i].second, -n); ans -= s.t[1]; // cout << "C " << s.t[1] << '\n'; } else { s.upd(a[i].second, -n); } s0[j].push_back(a[i].second); ans += m; ans %= m; // cout << ans << '\n'; } cout << ans << '\n'; return 0; }

Compilation message (stderr)

fish.cpp: In constructor 'seg::seg(std::vector<int>)':
fish.cpp:14:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |   for (int i = 0; i < f.size(); ++i) t[i + f.size()] = f[i] + 1;
      |                   ~~^~~~~~~~~~
#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...