제출 #781908

#제출 시각아이디문제언어결과실행 시간메모리
781908makanhulia이상한 기계 (APIO19_strange_device)C++17
20 / 100
464 ms40656 KiB
#include<bits/stdc++.h> #define int long long #define pii pair<int, int> using namespace std; const int MAX=1e18; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, a, b; cin >> n >> a >> b; priority_queue<pii, vector<pii>, greater<pii>> pq; int S=0; bool cut=1; while(n--) { int l, r; cin >> l >> r; pq.push({l, r}); S+=r-l+1; if(S>(int)1e6) cut=0, S=0; } if(cut) { set<pair<int, int>> ans; while(!pq.empty()) { int i=pq.top().first, j=pq.top().second; pq.pop(); while(i<=j) { while(!pq.empty() && pq.top().first==i) j=max(j, pq.top().second); ans.insert({(i+i/b)%a, i%b}); i++; } } cout << ans.size() << '\n'; } else { priority_queue<pii, vector<pii>, greater<pii>> to_ans; int Mod; if(a>(MAX+b-1)/b) Mod=1e18+1; else Mod=a*b; while(!pq.empty()) { int l=pq.top().first, r=pq.top().second; pq.pop(); while(!pq.empty() && pq.top().first<=r) r=max(r, pq.top().second), pq.pop(); if((l+Mod-1)/Mod*Mod+Mod-1<=r) {cout << Mod << '\n'; return 0;} if((l+Mod-1)/Mod*Mod<=r && l%Mod) to_ans.push({l%Mod, Mod-1}), to_ans.push({0, r%Mod}); else to_ans.push({l%Mod, r%Mod}); } int ans=0; while(!to_ans.empty()) { int l=to_ans.top().first, r=to_ans.top().second; to_ans.pop(); while(!to_ans.empty() && to_ans.top().first<=r) r=max(r, to_ans.top().second), to_ans.pop(); ans+=r-l+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...