#include <bits/stdc++.h>
using namespace std;
#define Baytoro_Mayrambekov void solve()
#define ios ios::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define int long long
#define endl '\n'
const int INF=1e18;
void fopn(string name){
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
int binpow(int a,int n){
if(n==0)
return 1;
if(n%2==1)
return binpow(a, n-1)*a;
else{
int b=binpow(a, n/2);
return b*b;
}
}
int a,b,c,n,m,i,j,k,x,y,cnt=0,sum=0,res=0;
Baytoro_Mayrambekov{
cin>>n>>a>>b;
int mx=a/(__gcd(a,b+1));
if(mx>INF/b)
mx=INF;
else
mx*=b;
bool check=1;
set<pair<int,int>> st;
for(i=0;i<n;i++){
int l,r;
cin>>l>>r;
if(r-l+1>=mx && check){
cout<<mx<<endl;
check=0;
}
if(!check)
continue;
l%=mx;
r%=mx;
if(l<=r){
st.insert({l,r});
}
else{
st.insert({l,mx-1});
st.insert({0,r});
}
}
if(!check){
return;
}
res=0;
int x=-1;
for(auto it: st){
if(x<it.fr)
res+=it.sc-it.fr+1;
else if(x<it.sc)
res+=it.sc-x;
x=max(x,it.sc);
}
cout<<res<<endl;
}
main(){
ios;
int T=1;
//cin>>T;
while(T--){
solve();
}
}
Compilation message
strange_device.cpp:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
70 | main(){
| ^~~~
strange_device.cpp: In function 'void fopn(std::string)':
strange_device.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | freopen((name+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:15:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
852 KB |
Output is correct |
3 |
Correct |
6 ms |
860 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
840 KB |
Output is correct |
17 |
Correct |
55 ms |
6468 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 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 |
257 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
591 ms |
62900 KB |
Output is correct |
3 |
Correct |
611 ms |
62824 KB |
Output is correct |
4 |
Correct |
680 ms |
99648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
591 ms |
62900 KB |
Output is correct |
3 |
Correct |
611 ms |
62824 KB |
Output is correct |
4 |
Correct |
680 ms |
99648 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
677 ms |
99996 KB |
Output is correct |
7 |
Correct |
647 ms |
99996 KB |
Output is correct |
8 |
Correct |
616 ms |
100036 KB |
Output is correct |
9 |
Correct |
732 ms |
99304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
591 ms |
62900 KB |
Output is correct |
3 |
Correct |
611 ms |
62824 KB |
Output is correct |
4 |
Correct |
680 ms |
99648 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
64 ms |
10172 KB |
Output is correct |
7 |
Correct |
56 ms |
10188 KB |
Output is correct |
8 |
Correct |
62 ms |
10236 KB |
Output is correct |
9 |
Correct |
58 ms |
10188 KB |
Output is correct |
10 |
Correct |
72 ms |
10196 KB |
Output is correct |
11 |
Correct |
67 ms |
10196 KB |
Output is correct |
12 |
Correct |
54 ms |
10188 KB |
Output is correct |
13 |
Correct |
60 ms |
10236 KB |
Output is correct |
14 |
Correct |
59 ms |
10332 KB |
Output is correct |
15 |
Correct |
84 ms |
10192 KB |
Output is correct |
16 |
Correct |
73 ms |
10156 KB |
Output is correct |
17 |
Correct |
58 ms |
10272 KB |
Output is correct |
18 |
Correct |
651 ms |
100048 KB |
Output is correct |
19 |
Correct |
662 ms |
99932 KB |
Output is correct |
20 |
Correct |
685 ms |
99940 KB |
Output is correct |
21 |
Correct |
62 ms |
10216 KB |
Output is correct |
22 |
Correct |
76 ms |
10264 KB |
Output is correct |
23 |
Correct |
134 ms |
12824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
62 ms |
6576 KB |
Output is correct |
3 |
Correct |
64 ms |
6756 KB |
Output is correct |
4 |
Correct |
629 ms |
63264 KB |
Output is correct |
5 |
Correct |
61 ms |
6604 KB |
Output is correct |
6 |
Correct |
68 ms |
6572 KB |
Output is correct |
7 |
Correct |
61 ms |
6620 KB |
Output is correct |
8 |
Correct |
57 ms |
6604 KB |
Output is correct |
9 |
Correct |
75 ms |
6640 KB |
Output is correct |
10 |
Correct |
61 ms |
6668 KB |
Output is correct |
11 |
Correct |
60 ms |
6676 KB |
Output is correct |
12 |
Correct |
73 ms |
6644 KB |
Output is correct |
13 |
Correct |
58 ms |
6684 KB |
Output is correct |
14 |
Correct |
693 ms |
63056 KB |
Output is correct |
15 |
Correct |
62 ms |
6576 KB |
Output is correct |
16 |
Correct |
619 ms |
63212 KB |
Output is correct |
17 |
Correct |
626 ms |
63304 KB |
Output is correct |
18 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
6 ms |
852 KB |
Output is correct |
3 |
Correct |
6 ms |
860 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
6 ms |
840 KB |
Output is correct |
17 |
Correct |
55 ms |
6468 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
2 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 |
257 ms |
308 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
591 ms |
62900 KB |
Output is correct |
31 |
Correct |
611 ms |
62824 KB |
Output is correct |
32 |
Correct |
680 ms |
99648 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
677 ms |
99996 KB |
Output is correct |
35 |
Correct |
647 ms |
99996 KB |
Output is correct |
36 |
Correct |
616 ms |
100036 KB |
Output is correct |
37 |
Correct |
732 ms |
99304 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
64 ms |
10172 KB |
Output is correct |
40 |
Correct |
56 ms |
10188 KB |
Output is correct |
41 |
Correct |
62 ms |
10236 KB |
Output is correct |
42 |
Correct |
58 ms |
10188 KB |
Output is correct |
43 |
Correct |
72 ms |
10196 KB |
Output is correct |
44 |
Correct |
67 ms |
10196 KB |
Output is correct |
45 |
Correct |
54 ms |
10188 KB |
Output is correct |
46 |
Correct |
60 ms |
10236 KB |
Output is correct |
47 |
Correct |
59 ms |
10332 KB |
Output is correct |
48 |
Correct |
84 ms |
10192 KB |
Output is correct |
49 |
Correct |
73 ms |
10156 KB |
Output is correct |
50 |
Correct |
58 ms |
10272 KB |
Output is correct |
51 |
Correct |
651 ms |
100048 KB |
Output is correct |
52 |
Correct |
662 ms |
99932 KB |
Output is correct |
53 |
Correct |
685 ms |
99940 KB |
Output is correct |
54 |
Correct |
62 ms |
10216 KB |
Output is correct |
55 |
Correct |
76 ms |
10264 KB |
Output is correct |
56 |
Correct |
134 ms |
12824 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
62 ms |
6576 KB |
Output is correct |
59 |
Correct |
64 ms |
6756 KB |
Output is correct |
60 |
Correct |
629 ms |
63264 KB |
Output is correct |
61 |
Correct |
61 ms |
6604 KB |
Output is correct |
62 |
Correct |
68 ms |
6572 KB |
Output is correct |
63 |
Correct |
61 ms |
6620 KB |
Output is correct |
64 |
Correct |
57 ms |
6604 KB |
Output is correct |
65 |
Correct |
75 ms |
6640 KB |
Output is correct |
66 |
Correct |
61 ms |
6668 KB |
Output is correct |
67 |
Correct |
60 ms |
6676 KB |
Output is correct |
68 |
Correct |
73 ms |
6644 KB |
Output is correct |
69 |
Correct |
58 ms |
6684 KB |
Output is correct |
70 |
Correct |
693 ms |
63056 KB |
Output is correct |
71 |
Correct |
62 ms |
6576 KB |
Output is correct |
72 |
Correct |
619 ms |
63212 KB |
Output is correct |
73 |
Correct |
626 ms |
63304 KB |
Output is correct |
74 |
Correct |
1 ms |
320 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
1 ms |
212 KB |
Output is correct |
77 |
Correct |
1 ms |
212 KB |
Output is correct |
78 |
Correct |
1 ms |
212 KB |
Output is correct |
79 |
Correct |
6 ms |
1236 KB |
Output is correct |
80 |
Correct |
698 ms |
100056 KB |
Output is correct |
81 |
Correct |
669 ms |
99956 KB |
Output is correct |
82 |
Correct |
718 ms |
99968 KB |
Output is correct |
83 |
Correct |
685 ms |
99988 KB |
Output is correct |
84 |
Correct |
741 ms |
99980 KB |
Output is correct |
85 |
Correct |
759 ms |
100112 KB |
Output is correct |
86 |
Correct |
122 ms |
12832 KB |
Output is correct |
87 |
Correct |
1 ms |
212 KB |
Output is correct |