// __builtin_popcount(x) broj bitova
// __builtin_popcountll(x)
// __builtin_clz(x) vodece nule
// __builtin_clzll(x)
// __builtin_ctz(x) nule na pocetku
// __builtin_ctzll(x)
// 2000000011
// 2000000033
#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 1000000000000000000LL // 10^18
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) ((ll)(a.size()))
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pi 3.14159265358979323846
#define here cerr<<"=============================================================================\n"
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define ceri2(a,l,r,n,m) {for(ll i = l;i<=r;i++){for(ll j = n;j<=m;j++) cerr<<a[i][j]<< " ";cerr<<endl;}}
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
using namespace __gnu_pbds;
template<typename T> using vc = vector<T>;
template<typename T> using vvc = vc<vc<T>>;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
return uniform_int_distribution<ll>(l,r)(rng);
}
void setIO(string inoutname)
{
freopen((inoutname+".in").c_str(),"r",stdin);
freopen((inoutname+".out").c_str(),"w",stdout);
}
#define mod 1
ll gcd(ll a, ll b)
{
if(b==0) return a;
if(a==0) return b;
if(a>=b) return gcd(a%b,b);
return gcd(a,b%a);
}
ll lcm(ll a,ll b){
return (a/gcd(a,b))*b;
}
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
if(x==mod) x = 0;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
ll po(ll x,ll y){
if(y==0) return 1LL;
ll ans = po(x,y/2);
ans = mul(ans,ans);
if(y&1) ans = mul(ans,x);
return ans;
}
ll inv(ll x){return po(x,mod-2);}
#define maxn 1000005
ll n;
pll a[maxn];
ll x,y;
void tc(){
daj_mi_malo_vremena
cin >> n >> x >> y;
for(ll i = 1;i<=n;i++) cin >> a[i].fi >> a[i].sc;
ll k = x/gcd(x,y+1);
ll ans = 0;
if(llinf/k<y){
for(ll i = 1;i<=n;i++) ans+= a[i].sc-a[i].fi+1;
cout<<ans<<endl;
return;
}
ll p = k*y;
vector<pll> v;
bool sve = 0;
for(ll i = 1;i<=n;i++){
ll &l = a[i].fi;
ll &r = a[i].sc;
if(r-l+1>=p) sve = 1;
l%=p;
r%=p;
if(r<l){
v.pb({0,1});
v.pb({p,-1});
}
v.pb({l,1});
v.pb({r+1,-1});
}
if(sve){
cout<<p<<endl;
return;
}
sort(all(v));
ll lst = -1;
ll cnt = 0;
for(pll p : v){
ll i = p.fi;
if(cnt) ans+=i-lst;
lst = i;
cnt+=p.sc;
}
cout<<ans<<endl;
return;
}
int main(){
daj_mi_malo_vremena
//setIO("lol");
int t; t = 1;
while(t--){
tc();
}
return 0;
}
Compilation message
strange_device.cpp: In function 'void setIO(std::string)':
strange_device.cpp:50:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | freopen((inoutname+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:51:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | freopen((inoutname+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1112 KB |
Output is correct |
3 |
Correct |
5 ms |
1112 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
1516 KB |
Output is correct |
17 |
Correct |
59 ms |
9864 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
356 ms |
74116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
484 ms |
48888 KB |
Output is correct |
3 |
Correct |
498 ms |
48960 KB |
Output is correct |
4 |
Correct |
528 ms |
86140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
484 ms |
48888 KB |
Output is correct |
3 |
Correct |
498 ms |
48960 KB |
Output is correct |
4 |
Correct |
528 ms |
86140 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
531 ms |
86096 KB |
Output is correct |
7 |
Correct |
514 ms |
86052 KB |
Output is correct |
8 |
Correct |
520 ms |
86236 KB |
Output is correct |
9 |
Correct |
617 ms |
86132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
484 ms |
48888 KB |
Output is correct |
3 |
Correct |
498 ms |
48960 KB |
Output is correct |
4 |
Correct |
528 ms |
86140 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
50 ms |
9796 KB |
Output is correct |
7 |
Correct |
51 ms |
9856 KB |
Output is correct |
8 |
Correct |
51 ms |
9760 KB |
Output is correct |
9 |
Correct |
52 ms |
9776 KB |
Output is correct |
10 |
Correct |
49 ms |
9796 KB |
Output is correct |
11 |
Correct |
52 ms |
9744 KB |
Output is correct |
12 |
Correct |
50 ms |
9848 KB |
Output is correct |
13 |
Correct |
54 ms |
9852 KB |
Output is correct |
14 |
Correct |
51 ms |
9740 KB |
Output is correct |
15 |
Correct |
58 ms |
9848 KB |
Output is correct |
16 |
Correct |
56 ms |
9800 KB |
Output is correct |
17 |
Correct |
67 ms |
9832 KB |
Output is correct |
18 |
Correct |
549 ms |
86036 KB |
Output is correct |
19 |
Correct |
504 ms |
86076 KB |
Output is correct |
20 |
Correct |
628 ms |
86056 KB |
Output is correct |
21 |
Correct |
57 ms |
9792 KB |
Output is correct |
22 |
Correct |
46 ms |
9744 KB |
Output is correct |
23 |
Correct |
144 ms |
34780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
56 ms |
9052 KB |
Output is correct |
3 |
Correct |
56 ms |
9136 KB |
Output is correct |
4 |
Correct |
615 ms |
49140 KB |
Output is correct |
5 |
Correct |
59 ms |
9156 KB |
Output is correct |
6 |
Correct |
55 ms |
9188 KB |
Output is correct |
7 |
Correct |
55 ms |
9148 KB |
Output is correct |
8 |
Correct |
62 ms |
9128 KB |
Output is correct |
9 |
Correct |
52 ms |
9156 KB |
Output is correct |
10 |
Correct |
57 ms |
9212 KB |
Output is correct |
11 |
Correct |
58 ms |
9080 KB |
Output is correct |
12 |
Correct |
49 ms |
9160 KB |
Output is correct |
13 |
Correct |
58 ms |
9796 KB |
Output is correct |
14 |
Correct |
632 ms |
85992 KB |
Output is correct |
15 |
Correct |
57 ms |
9748 KB |
Output is correct |
16 |
Correct |
504 ms |
86064 KB |
Output is correct |
17 |
Correct |
515 ms |
86004 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
5 ms |
1112 KB |
Output is correct |
3 |
Correct |
5 ms |
1112 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
6 ms |
1516 KB |
Output is correct |
17 |
Correct |
59 ms |
9864 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
356 ms |
74116 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
484 ms |
48888 KB |
Output is correct |
31 |
Correct |
498 ms |
48960 KB |
Output is correct |
32 |
Correct |
528 ms |
86140 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
531 ms |
86096 KB |
Output is correct |
35 |
Correct |
514 ms |
86052 KB |
Output is correct |
36 |
Correct |
520 ms |
86236 KB |
Output is correct |
37 |
Correct |
617 ms |
86132 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
50 ms |
9796 KB |
Output is correct |
40 |
Correct |
51 ms |
9856 KB |
Output is correct |
41 |
Correct |
51 ms |
9760 KB |
Output is correct |
42 |
Correct |
52 ms |
9776 KB |
Output is correct |
43 |
Correct |
49 ms |
9796 KB |
Output is correct |
44 |
Correct |
52 ms |
9744 KB |
Output is correct |
45 |
Correct |
50 ms |
9848 KB |
Output is correct |
46 |
Correct |
54 ms |
9852 KB |
Output is correct |
47 |
Correct |
51 ms |
9740 KB |
Output is correct |
48 |
Correct |
58 ms |
9848 KB |
Output is correct |
49 |
Correct |
56 ms |
9800 KB |
Output is correct |
50 |
Correct |
67 ms |
9832 KB |
Output is correct |
51 |
Correct |
549 ms |
86036 KB |
Output is correct |
52 |
Correct |
504 ms |
86076 KB |
Output is correct |
53 |
Correct |
628 ms |
86056 KB |
Output is correct |
54 |
Correct |
57 ms |
9792 KB |
Output is correct |
55 |
Correct |
46 ms |
9744 KB |
Output is correct |
56 |
Correct |
144 ms |
34780 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
56 ms |
9052 KB |
Output is correct |
59 |
Correct |
56 ms |
9136 KB |
Output is correct |
60 |
Correct |
615 ms |
49140 KB |
Output is correct |
61 |
Correct |
59 ms |
9156 KB |
Output is correct |
62 |
Correct |
55 ms |
9188 KB |
Output is correct |
63 |
Correct |
55 ms |
9148 KB |
Output is correct |
64 |
Correct |
62 ms |
9128 KB |
Output is correct |
65 |
Correct |
52 ms |
9156 KB |
Output is correct |
66 |
Correct |
57 ms |
9212 KB |
Output is correct |
67 |
Correct |
58 ms |
9080 KB |
Output is correct |
68 |
Correct |
49 ms |
9160 KB |
Output is correct |
69 |
Correct |
58 ms |
9796 KB |
Output is correct |
70 |
Correct |
632 ms |
85992 KB |
Output is correct |
71 |
Correct |
57 ms |
9748 KB |
Output is correct |
72 |
Correct |
504 ms |
86064 KB |
Output is correct |
73 |
Correct |
515 ms |
86004 KB |
Output is correct |
74 |
Correct |
0 ms |
212 KB |
Output is correct |
75 |
Correct |
0 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
0 ms |
212 KB |
Output is correct |
78 |
Correct |
0 ms |
212 KB |
Output is correct |
79 |
Correct |
6 ms |
1496 KB |
Output is correct |
80 |
Correct |
650 ms |
85884 KB |
Output is correct |
81 |
Correct |
660 ms |
85996 KB |
Output is correct |
82 |
Correct |
610 ms |
86016 KB |
Output is correct |
83 |
Correct |
589 ms |
85968 KB |
Output is correct |
84 |
Correct |
617 ms |
85972 KB |
Output is correct |
85 |
Correct |
599 ms |
86096 KB |
Output is correct |
86 |
Correct |
153 ms |
34740 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |