제출 #1135836

#제출 시각아이디문제언어결과실행 시간메모리
1135836adaawf이상한 기계 (APIO19_strange_device)C++20
100 / 100
440 ms79116 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<pair<long long int, long long int>> g, gg; long long int d[3000005], aa[1000005], bb[1000005]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, a, b, c = 0; cin >> n >> a >> b; a = a / __gcd(a, b + 1); for (int i = 1; i <= n; i++) { long long int x, y; cin >> x >> y; aa[i] = x; bb[i] = y; c += y - x + 1; } if (9e18 / b < a) { cout << c; return 0; } a *= b; for (int i = 1; i <= n; i++) { long long int x = aa[i], y = bb[i]; if (y - x + 1 >= a) { cout << a; return 0; } 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++) { d[i + 1] = d[i] + gg[i].second; if (d[i + 1] > 0) res = res + (gg[i + 1].first - gg[i].first); } 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...