이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll n,A,B,mod,ans;
int cnt;
set<pll> s; //(start, end)
void insert(pll a) {
if (s.empty()) {
s.insert(a);
ans+=(a.second-a.first+1);
} else {
auto it1=s.upper_bound(pll(a.first,LLONG_MAX));
auto it2=s.upper_bound(pll(a.second,LLONG_MAX));
ll mmin, mmax;
auto ed=it1,st=it1;
if (it1==s.begin()) mmin=a.first;
else {
auto h=it1; --h;
if ((*h).second>=a.first) mmin=(*h).first,st=h;
else mmin=a.first,st=it1;
}
ed=it2;
if (it2==s.begin()) mmax=a.second;
else {
--it2;
mmax=max(a.second,(*it2).second);
}
for (auto k=st; k!=ed; ++k) {
ans-=((*k).second-(*k).first+1);
//if (cnt==2) cout<<(*k).first<<" "<<(*k).second<<"\n";
//cout<<(*p).first<<" "<<(*p).second<<"\n";
//auto p=k; s.erase(p);
}
s.insert(pll(mmin,mmax));
ans+=(mmax-mmin+1);
}
++cnt;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>A>>B;
mod=(A*B)/__gcd(A,B+1);
while (n--) {
ll l,r;
cin>>l>>r;
if (r-l+1>=mod) {
cout<<mod;
return 0;
}
l%=mod;
r%=mod;
if (l<=r) insert(pll(l,r));
else insert(pll(l,mod-1)), insert(pll(0,r));
}
cout<<ans;
}
/*
2 3 3
7 9
17 18
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |