#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli test=1;
for(;test>0;--test)
{
lli n,a,b,g,p,f,s,cl,cr,ans=0,ch=1;
cin>>n>>a>>b;
g=__gcd(a,b+1);
g=a/g;
if(1.0*g*b>1000000000000000000)
p=1000000000500000000;
else
p=g*b;
vector<ii> v;
for(lli i=0;i<n;++i)
{
cin>>f>>s;
if(s-f+1>=p)
{
ch=0;
}
f%=p;
s%=p;
if(f<=s)
v.pb(mp(f,s));
else
{
v.pb(mp(0,s));
v.pb(mp(f,p-1));
}
}
if(ch==0)
{
cout<<p<<endl;
exit(0);
}
sort(all(v));
v.pb(mp(p,p));
cl=0;
cr=-1;
ans=0;
for(lli i=0;i<v.size();++i)
{
if(v[i].F<=cr)
{
if(v[i].S>=cr)
cr=v[i].S;
}
else
{
ans+=cr-cl+1;
cl=v[i].F;
cr=v[i].S;
}
}
cout<<ans<<endl;
}
return(0);
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:61:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(lli i=0;i<v.size();++i)
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
1152 KB |
Output is correct |
3 |
Correct |
10 ms |
1024 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
10 ms |
1152 KB |
Output is correct |
17 |
Correct |
62 ms |
5740 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
378 ms |
22484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
520 ms |
35880 KB |
Output is correct |
3 |
Correct |
527 ms |
53260 KB |
Output is correct |
4 |
Correct |
518 ms |
53440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
520 ms |
35880 KB |
Output is correct |
3 |
Correct |
527 ms |
53260 KB |
Output is correct |
4 |
Correct |
518 ms |
53440 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
519 ms |
53440 KB |
Output is correct |
7 |
Correct |
530 ms |
53300 KB |
Output is correct |
8 |
Correct |
540 ms |
53336 KB |
Output is correct |
9 |
Correct |
589 ms |
53620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
520 ms |
35880 KB |
Output is correct |
3 |
Correct |
527 ms |
53260 KB |
Output is correct |
4 |
Correct |
518 ms |
53440 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
54 ms |
5740 KB |
Output is correct |
7 |
Correct |
58 ms |
5736 KB |
Output is correct |
8 |
Correct |
56 ms |
5736 KB |
Output is correct |
9 |
Correct |
55 ms |
5868 KB |
Output is correct |
10 |
Correct |
53 ms |
5740 KB |
Output is correct |
11 |
Correct |
58 ms |
5736 KB |
Output is correct |
12 |
Correct |
55 ms |
5736 KB |
Output is correct |
13 |
Correct |
59 ms |
5740 KB |
Output is correct |
14 |
Correct |
59 ms |
5740 KB |
Output is correct |
15 |
Correct |
62 ms |
5740 KB |
Output is correct |
16 |
Correct |
59 ms |
5740 KB |
Output is correct |
17 |
Correct |
56 ms |
5736 KB |
Output is correct |
18 |
Correct |
535 ms |
53396 KB |
Output is correct |
19 |
Correct |
520 ms |
53184 KB |
Output is correct |
20 |
Correct |
592 ms |
53316 KB |
Output is correct |
21 |
Correct |
62 ms |
5736 KB |
Output is correct |
22 |
Correct |
54 ms |
5760 KB |
Output is correct |
23 |
Correct |
177 ms |
18700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
59 ms |
5740 KB |
Output is correct |
3 |
Correct |
60 ms |
5740 KB |
Output is correct |
4 |
Correct |
630 ms |
24920 KB |
Output is correct |
5 |
Correct |
58 ms |
5740 KB |
Output is correct |
6 |
Correct |
58 ms |
5740 KB |
Output is correct |
7 |
Correct |
59 ms |
5740 KB |
Output is correct |
8 |
Correct |
63 ms |
5736 KB |
Output is correct |
9 |
Correct |
62 ms |
5732 KB |
Output is correct |
10 |
Correct |
62 ms |
5736 KB |
Output is correct |
11 |
Correct |
62 ms |
5740 KB |
Output is correct |
12 |
Correct |
53 ms |
5740 KB |
Output is correct |
13 |
Correct |
61 ms |
5740 KB |
Output is correct |
14 |
Correct |
582 ms |
24788 KB |
Output is correct |
15 |
Correct |
59 ms |
5768 KB |
Output is correct |
16 |
Correct |
533 ms |
53360 KB |
Output is correct |
17 |
Correct |
525 ms |
53440 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
10 ms |
1152 KB |
Output is correct |
3 |
Correct |
10 ms |
1024 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
512 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
10 ms |
1152 KB |
Output is correct |
17 |
Correct |
62 ms |
5740 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
5 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
5 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
5 ms |
384 KB |
Output is correct |
28 |
Correct |
378 ms |
22484 KB |
Output is correct |
29 |
Correct |
5 ms |
384 KB |
Output is correct |
30 |
Correct |
520 ms |
35880 KB |
Output is correct |
31 |
Correct |
527 ms |
53260 KB |
Output is correct |
32 |
Correct |
518 ms |
53440 KB |
Output is correct |
33 |
Correct |
5 ms |
384 KB |
Output is correct |
34 |
Correct |
519 ms |
53440 KB |
Output is correct |
35 |
Correct |
530 ms |
53300 KB |
Output is correct |
36 |
Correct |
540 ms |
53336 KB |
Output is correct |
37 |
Correct |
589 ms |
53620 KB |
Output is correct |
38 |
Correct |
5 ms |
384 KB |
Output is correct |
39 |
Correct |
54 ms |
5740 KB |
Output is correct |
40 |
Correct |
58 ms |
5736 KB |
Output is correct |
41 |
Correct |
56 ms |
5736 KB |
Output is correct |
42 |
Correct |
55 ms |
5868 KB |
Output is correct |
43 |
Correct |
53 ms |
5740 KB |
Output is correct |
44 |
Correct |
58 ms |
5736 KB |
Output is correct |
45 |
Correct |
55 ms |
5736 KB |
Output is correct |
46 |
Correct |
59 ms |
5740 KB |
Output is correct |
47 |
Correct |
59 ms |
5740 KB |
Output is correct |
48 |
Correct |
62 ms |
5740 KB |
Output is correct |
49 |
Correct |
59 ms |
5740 KB |
Output is correct |
50 |
Correct |
56 ms |
5736 KB |
Output is correct |
51 |
Correct |
535 ms |
53396 KB |
Output is correct |
52 |
Correct |
520 ms |
53184 KB |
Output is correct |
53 |
Correct |
592 ms |
53316 KB |
Output is correct |
54 |
Correct |
62 ms |
5736 KB |
Output is correct |
55 |
Correct |
54 ms |
5760 KB |
Output is correct |
56 |
Correct |
177 ms |
18700 KB |
Output is correct |
57 |
Correct |
5 ms |
384 KB |
Output is correct |
58 |
Correct |
59 ms |
5740 KB |
Output is correct |
59 |
Correct |
60 ms |
5740 KB |
Output is correct |
60 |
Correct |
630 ms |
24920 KB |
Output is correct |
61 |
Correct |
58 ms |
5740 KB |
Output is correct |
62 |
Correct |
58 ms |
5740 KB |
Output is correct |
63 |
Correct |
59 ms |
5740 KB |
Output is correct |
64 |
Correct |
63 ms |
5736 KB |
Output is correct |
65 |
Correct |
62 ms |
5732 KB |
Output is correct |
66 |
Correct |
62 ms |
5736 KB |
Output is correct |
67 |
Correct |
62 ms |
5740 KB |
Output is correct |
68 |
Correct |
53 ms |
5740 KB |
Output is correct |
69 |
Correct |
61 ms |
5740 KB |
Output is correct |
70 |
Correct |
582 ms |
24788 KB |
Output is correct |
71 |
Correct |
59 ms |
5768 KB |
Output is correct |
72 |
Correct |
533 ms |
53360 KB |
Output is correct |
73 |
Correct |
525 ms |
53440 KB |
Output is correct |
74 |
Correct |
4 ms |
384 KB |
Output is correct |
75 |
Correct |
5 ms |
384 KB |
Output is correct |
76 |
Correct |
5 ms |
384 KB |
Output is correct |
77 |
Correct |
4 ms |
384 KB |
Output is correct |
78 |
Correct |
4 ms |
384 KB |
Output is correct |
79 |
Correct |
14 ms |
1048 KB |
Output is correct |
80 |
Correct |
600 ms |
36044 KB |
Output is correct |
81 |
Correct |
610 ms |
36080 KB |
Output is correct |
82 |
Correct |
584 ms |
36184 KB |
Output is correct |
83 |
Correct |
581 ms |
22496 KB |
Output is correct |
84 |
Correct |
566 ms |
22484 KB |
Output is correct |
85 |
Correct |
582 ms |
36032 KB |
Output is correct |
86 |
Correct |
169 ms |
18528 KB |
Output is correct |
87 |
Correct |
5 ms |
384 KB |
Output is correct |