This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(2e18);
const int MOD = 998244353;
const bool DEBUG = 0;
const int MAXN = 1000005;
bool cmp(ii a, ii b){
if(a.F!=b.F) return a.F<b.F;
return a.S>b.S;
}
ll n,A,B,P;
ii a[MAXN];
vii v,tmp;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>A>>B;
if(A/__gcd(A,B+1)>=INF/B) P=INF;
else P=A/__gcd(A,B+1)*B;
forn(i,0,n){
cin>>a[i].F>>a[i].S;
if(a[i].S-a[i].F+1>=P){
cout<<P<<'\n';
return 0;
}
a[i].F%=P;
a[i].S%=P;
if(a[i].F<=a[i].S){
v.pb({a[i].F,a[i].S});
}
else{
v.pb({a[i].F,P-1});
v.pb({0,a[i].S});
}
}
sort(v.begin(), v.end(), cmp);
forn(i,0,v.size()){
if(tmp.size() && tmp.back().F<=v[i].F && v[i].S<=tmp.back().S) continue;
tmp.pb(v[i]);
}
v = tmp;
tmp.clear();
ll ans=0, L=v[0].F;
forn(i,1,v.size())
{
if(v[i-1].S<v[i].F){
ans+=v[i-1].S-L+1;
L=v[i].F;
}
}
ans+=v[v.size()-1].S-L+1;
cout<<ans<<'\n';
return 0;
}
Compilation message (stderr)
strange_device.cpp: In function 'int main()':
strange_device.cpp:10:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define forn(i,a,b) for(int i=(a);i<(b);i++)
^
strange_device.cpp:69:2: note: in expansion of macro 'forn'
forn(i,0,v.size()){
^~~~
strange_device.cpp:10:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define forn(i,a,b) for(int i=(a);i<(b);i++)
^
strange_device.cpp:77:2: note: in expansion of macro 'forn'
forn(i,1,v.size())
^~~~
# | 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... |