#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
typedef int64_t llo;
#define a first
#define b second
#define endl "\n"
llo gcd(llo kk,llo ll){
if(ll==0){
return kk;
}
return gcd(ll,kk%ll);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
llo n,a,b;
cin>>n>>a>>b;
llo x;
pair<llo,llo> it;
x=b;
x*=(a/gcd(a,b+1));
/* if((b+1)%a==0){
x=b;
}
else{
x=a*b;
}*/
llo aa,bb;
llo s=0;
set<pair<llo,llo>> ac;
for(llo i=0;i<n;i++){
cin>>aa>>bb;
/*if(bb-aa+1>=x){
cout<<x<<endl;
return 0;
}*/
if(bb-aa+1>=x){
s=1;
}
aa%=x;
bb%=x;
if(bb<aa){
ac.insert(mp(aa,x-1));
ac.insert(mp(0,bb));
}
else{
ac.insert(mp(aa,bb));
}
}
vector<pair<llo,llo>> prev;
for(auto cc:ac){
if(prev.size()==0){
prev.pb(cc);
}
else{
if(cc.a>prev.back().b){
prev.pb(cc);
}
else{
prev[prev.size()-1].b=max(prev[prev.size()-1].b,cc.b);
}
}
}
llo tot=0;
for(llo i=0;i<prev.size();i++){
tot+=prev[i].b-prev[i].a+1;
}
if(s==1 and tot<x){
while(true){
int y=1;
}
}
cout<<tot<<endl;
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:71:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(llo i=0;i<prev.size();i++){
~^~~~~~~~~~~~
strange_device.cpp:76:8: warning: unused variable 'y' [-Wunused-variable]
int y=1;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
13 ms |
1400 KB |
Output is correct |
3 |
Correct |
11 ms |
1400 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
380 KB |
Output is correct |
16 |
Correct |
12 ms |
1400 KB |
Output is correct |
17 |
Correct |
82 ms |
8808 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Execution timed out |
5072 ms |
380 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
355 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
799 ms |
79544 KB |
Output is correct |
3 |
Correct |
822 ms |
79568 KB |
Output is correct |
4 |
Correct |
826 ms |
79724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
799 ms |
79544 KB |
Output is correct |
3 |
Correct |
822 ms |
79568 KB |
Output is correct |
4 |
Correct |
826 ms |
79724 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
798 ms |
79568 KB |
Output is correct |
7 |
Correct |
795 ms |
79440 KB |
Output is correct |
8 |
Correct |
802 ms |
79568 KB |
Output is correct |
9 |
Correct |
842 ms |
79568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
799 ms |
79544 KB |
Output is correct |
3 |
Correct |
822 ms |
79568 KB |
Output is correct |
4 |
Correct |
826 ms |
79724 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
78 ms |
8800 KB |
Output is correct |
7 |
Correct |
79 ms |
8812 KB |
Output is correct |
8 |
Correct |
78 ms |
8808 KB |
Output is correct |
9 |
Correct |
84 ms |
8808 KB |
Output is correct |
10 |
Correct |
79 ms |
8812 KB |
Output is correct |
11 |
Correct |
79 ms |
8816 KB |
Output is correct |
12 |
Correct |
77 ms |
8808 KB |
Output is correct |
13 |
Correct |
84 ms |
8812 KB |
Output is correct |
14 |
Correct |
80 ms |
8812 KB |
Output is correct |
15 |
Correct |
89 ms |
8812 KB |
Output is correct |
16 |
Correct |
84 ms |
8812 KB |
Output is correct |
17 |
Correct |
79 ms |
8768 KB |
Output is correct |
18 |
Correct |
807 ms |
79568 KB |
Output is correct |
19 |
Correct |
806 ms |
79696 KB |
Output is correct |
20 |
Correct |
839 ms |
79604 KB |
Output is correct |
21 |
Correct |
80 ms |
8808 KB |
Output is correct |
22 |
Correct |
83 ms |
8812 KB |
Output is correct |
23 |
Correct |
150 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
376 KB |
Output is correct |
2 |
Correct |
84 ms |
8808 KB |
Output is correct |
3 |
Correct |
82 ms |
8808 KB |
Output is correct |
4 |
Correct |
830 ms |
79696 KB |
Output is correct |
5 |
Correct |
85 ms |
8808 KB |
Output is correct |
6 |
Correct |
86 ms |
8812 KB |
Output is correct |
7 |
Correct |
85 ms |
8808 KB |
Output is correct |
8 |
Correct |
80 ms |
8812 KB |
Output is correct |
9 |
Correct |
83 ms |
8808 KB |
Output is correct |
10 |
Correct |
79 ms |
8812 KB |
Output is correct |
11 |
Correct |
82 ms |
8776 KB |
Output is correct |
12 |
Correct |
83 ms |
8808 KB |
Output is correct |
13 |
Correct |
84 ms |
8860 KB |
Output is correct |
14 |
Correct |
849 ms |
79596 KB |
Output is correct |
15 |
Correct |
80 ms |
8808 KB |
Output is correct |
16 |
Correct |
794 ms |
79520 KB |
Output is correct |
17 |
Correct |
781 ms |
79696 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
13 ms |
1400 KB |
Output is correct |
3 |
Correct |
11 ms |
1400 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
380 KB |
Output is correct |
16 |
Correct |
12 ms |
1400 KB |
Output is correct |
17 |
Correct |
82 ms |
8808 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Execution timed out |
5072 ms |
380 KB |
Time limit exceeded |
21 |
Halted |
0 ms |
0 KB |
- |