#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(f-s+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)
~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
9 ms |
768 KB |
Output is correct |
3 |
Correct |
10 ms |
1152 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 |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 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 |
60 ms |
5740 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
383 ms |
41500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
520 ms |
16852 KB |
Output is correct |
3 |
Correct |
502 ms |
36032 KB |
Output is correct |
4 |
Correct |
516 ms |
36456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
520 ms |
16852 KB |
Output is correct |
3 |
Correct |
502 ms |
36032 KB |
Output is correct |
4 |
Correct |
516 ms |
36456 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
505 ms |
36160 KB |
Output is correct |
7 |
Correct |
536 ms |
36616 KB |
Output is correct |
8 |
Correct |
512 ms |
36564 KB |
Output is correct |
9 |
Correct |
563 ms |
36564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
520 ms |
16852 KB |
Output is correct |
3 |
Correct |
502 ms |
36032 KB |
Output is correct |
4 |
Correct |
516 ms |
36456 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
55 ms |
5748 KB |
Output is correct |
7 |
Correct |
57 ms |
5736 KB |
Output is correct |
8 |
Correct |
54 ms |
5736 KB |
Output is correct |
9 |
Correct |
57 ms |
5740 KB |
Output is correct |
10 |
Correct |
53 ms |
5740 KB |
Output is correct |
11 |
Correct |
57 ms |
5868 KB |
Output is correct |
12 |
Correct |
56 ms |
5736 KB |
Output is correct |
13 |
Correct |
60 ms |
5736 KB |
Output is correct |
14 |
Correct |
57 ms |
5740 KB |
Output is correct |
15 |
Correct |
59 ms |
5740 KB |
Output is correct |
16 |
Correct |
59 ms |
5740 KB |
Output is correct |
17 |
Correct |
61 ms |
5740 KB |
Output is correct |
18 |
Correct |
539 ms |
36756 KB |
Output is correct |
19 |
Correct |
521 ms |
36692 KB |
Output is correct |
20 |
Correct |
571 ms |
36688 KB |
Output is correct |
21 |
Correct |
61 ms |
5736 KB |
Output is correct |
22 |
Correct |
52 ms |
5740 KB |
Output is correct |
23 |
Correct |
169 ms |
18672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
60 ms |
2544 KB |
Output is correct |
3 |
Correct |
60 ms |
5740 KB |
Output is correct |
4 |
Correct |
613 ms |
53372 KB |
Output is correct |
5 |
Correct |
58 ms |
5736 KB |
Output is correct |
6 |
Correct |
60 ms |
5740 KB |
Output is correct |
7 |
Correct |
59 ms |
5736 KB |
Output is correct |
8 |
Correct |
60 ms |
5740 KB |
Output is correct |
9 |
Correct |
62 ms |
5744 KB |
Output is correct |
10 |
Correct |
60 ms |
5740 KB |
Output is correct |
11 |
Correct |
62 ms |
5740 KB |
Output is correct |
12 |
Correct |
52 ms |
5740 KB |
Output is correct |
13 |
Correct |
59 ms |
5740 KB |
Output is correct |
14 |
Correct |
605 ms |
53432 KB |
Output is correct |
15 |
Correct |
60 ms |
5756 KB |
Output is correct |
16 |
Correct |
534 ms |
36544 KB |
Output is correct |
17 |
Correct |
538 ms |
36564 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
9 ms |
768 KB |
Output is correct |
3 |
Correct |
10 ms |
1152 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 |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 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 |
60 ms |
5740 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |