#include <bits/stdc++.h>
#define LL long long
LL INF =2e18;
using namespace std;
int main()
{
LL n,a,b;
cin>>n>>a>>b;
LL t = (a/__gcd(b+1,a));
if(t<0)t=1e18+5;
vector<pair<LL,LL>>v;
if(INF/t+1LL<=b)t=INF;
else t=t*b;
// printf("t=%lld\n",t);
for(LL a=1;a<=n;a++)
{
LL l,r;
cin>>l>>r;
LL temp=l,temp2=r;
l%=t ,r%=t;
if(l==r)
{
if(temp==temp2)
{
v.push_back(make_pair(l,0));
v.push_back(make_pair(r,1));
}
else
{
v.push_back(make_pair(0,0));
v.push_back(make_pair(t-1,1));
}
}
else if(l>r)
{
// printf("->%lld,%lld\n-> 0 %lld\n",l,t-1,r);
// v.push_back(make_pair(l,t-1));
v.push_back(make_pair(l,0));
v.push_back(make_pair(t-1,1));
// v.push_back(make_pair(0,r));
v.push_back(make_pair(0,0));
v.push_back(make_pair(r,1));
}
else
{
v.push_back(make_pair(l,0));
v.push_back(make_pair(r,1));
}
}
sort(v.begin(),v.end());
LL kanan=0,tot=0,kiri=0,cnt=0;
for(pair<LL,LL>x:v)
{
if(x.second==0)
{
cnt++;
if(cnt==1)kiri=x.first;
}
else
{
cnt--;
if(cnt==0)tot+=(x.first-kiri+1);
}
}
cout<<tot<<endl;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:52:6: warning: unused variable 'kanan' [-Wunused-variable]
52 | LL kanan=0,tot=0,kiri=0,cnt=0;
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
11 ms |
976 KB |
Output is correct |
3 |
Correct |
11 ms |
848 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 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 |
11 ms |
848 KB |
Output is correct |
17 |
Correct |
117 ms |
4504 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
731 ms |
33128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1077 ms |
33160 KB |
Output is correct |
3 |
Correct |
1091 ms |
33168 KB |
Output is correct |
4 |
Correct |
1070 ms |
33228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1077 ms |
33160 KB |
Output is correct |
3 |
Correct |
1091 ms |
33168 KB |
Output is correct |
4 |
Correct |
1070 ms |
33228 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1085 ms |
33248 KB |
Output is correct |
7 |
Correct |
1066 ms |
33240 KB |
Output is correct |
8 |
Correct |
1082 ms |
33156 KB |
Output is correct |
9 |
Correct |
1148 ms |
33188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1077 ms |
33160 KB |
Output is correct |
3 |
Correct |
1091 ms |
33168 KB |
Output is correct |
4 |
Correct |
1070 ms |
33228 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
104 ms |
4460 KB |
Output is correct |
7 |
Correct |
117 ms |
4560 KB |
Output is correct |
8 |
Correct |
104 ms |
4464 KB |
Output is correct |
9 |
Correct |
106 ms |
4492 KB |
Output is correct |
10 |
Correct |
110 ms |
4480 KB |
Output is correct |
11 |
Correct |
108 ms |
4424 KB |
Output is correct |
12 |
Correct |
120 ms |
4524 KB |
Output is correct |
13 |
Correct |
113 ms |
4440 KB |
Output is correct |
14 |
Correct |
111 ms |
4440 KB |
Output is correct |
15 |
Correct |
110 ms |
4432 KB |
Output is correct |
16 |
Correct |
131 ms |
4420 KB |
Output is correct |
17 |
Correct |
110 ms |
4472 KB |
Output is correct |
18 |
Correct |
1100 ms |
33152 KB |
Output is correct |
19 |
Correct |
1057 ms |
33176 KB |
Output is correct |
20 |
Correct |
1423 ms |
33252 KB |
Output is correct |
21 |
Correct |
119 ms |
4540 KB |
Output is correct |
22 |
Correct |
100 ms |
4412 KB |
Output is correct |
23 |
Correct |
331 ms |
16808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
109 ms |
4464 KB |
Output is correct |
3 |
Correct |
109 ms |
4496 KB |
Output is correct |
4 |
Correct |
1228 ms |
33196 KB |
Output is correct |
5 |
Correct |
109 ms |
4460 KB |
Output is correct |
6 |
Correct |
109 ms |
4496 KB |
Output is correct |
7 |
Correct |
116 ms |
4576 KB |
Output is correct |
8 |
Correct |
109 ms |
4532 KB |
Output is correct |
9 |
Correct |
109 ms |
4416 KB |
Output is correct |
10 |
Correct |
116 ms |
4472 KB |
Output is correct |
11 |
Correct |
114 ms |
4476 KB |
Output is correct |
12 |
Correct |
113 ms |
4524 KB |
Output is correct |
13 |
Correct |
112 ms |
4408 KB |
Output is correct |
14 |
Correct |
1131 ms |
33256 KB |
Output is correct |
15 |
Correct |
116 ms |
4536 KB |
Output is correct |
16 |
Correct |
1062 ms |
33172 KB |
Output is correct |
17 |
Correct |
1096 ms |
33216 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
11 ms |
976 KB |
Output is correct |
3 |
Correct |
11 ms |
848 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 |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 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 |
11 ms |
848 KB |
Output is correct |
17 |
Correct |
117 ms |
4504 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |