Submission #1135822

#TimeUsernameProblemLanguageResultExecution timeMemory
1135822adaawfStrange Device (APIO19_strange_device)C++20
10 / 100
1096 ms282344 KiB
#include <iostream> #include <map> #include <vector> #include <algorithm> using namespace std; map<long long int, vector<pair<long long int, long long int>>> mm; vector<pair<long long int, long long int>> g, gg; long long int c[3000005], d[3000005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, a, b; cin >> n >> a >> b; for (int i = 1; i <= n; i++) { long long int x, y; cin >> x >> y; if (x / b == y / b) { mm[(x / b) % a].push_back({x % b, y % b}); } else { mm[(x / b) % a].push_back({x % b, b - 1}); mm[(y / b) % a].push_back({0, y % b}); x = (x - x % b + b) / b; y = (y - y % b - 1) / b; if (y - x + 1 >= a) { cout << a * b; return 0; } if (x > y) continue; if (x % a <= y % a) g.push_back({x % a, y % a}); else { g.push_back({x % a, a - 1}); g.push_back({0, y % a}); } } } for (auto w : g) { gg.push_back({w.first, 1}); gg.push_back({w.second + 1, -1}); } sort(gg.begin(), gg.end()); long long int res = 0; for (int i = 0; i < gg.size(); i++) { c[i + 1] = c[i] + gg[i].second; if (c[i + 1] > 0) res = res + (gg[i + 1].first - gg[i].first) * b; } for (auto w : mm) { int h = lower_bound(gg.begin(), gg.end(), make_pair(w.first + 1, -2ll)) - gg.begin() - 1; if (c[h + 1]) continue; g.clear(); for (auto ww : w.second) { g.push_back({ww.first, 1}); g.push_back({ww.second + 1, -1}); } sort(g.begin(), g.end()); for (int i = 0; i < g.size(); i++) { d[i + 1] = d[i] + g[i].second; if (d[i + 1] > 0) res = res + (g[i + 1].first - g[i].first); //cout << w.first << " " << g[i].second << " " << g[i].first << " " << res << '\n'; } } cout << res; }
#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...