#include<bits/stdc++.h>
using namespace std;
#define int long long
int gcd(int x, int y)
{
while(x>0)
{
int r = y%x;
y=x;
x=r;
}
return y;
}
set<pair<__int128,__int128>> s;
void baga(__int128 le, __int128 ri)
{
if(s.empty())
{
s.insert({le,ri});
return;
}
auto it = s.lower_bound({le+1,-1});
if(it!=s.begin()) it--;
while(it!=s.end())
{
if((*it).first > ri)
break;
else if((*it).second < le)
{
it++;
}
else
{
le = min(le, (*it).first);
ri = max(ri, (*it).second);
it = s.erase(it);
}
}
s.insert({le,ri});
}
void afis(__int128 x)
{
vector<int> cif;
__int128 zece=10;
while(x>0)
{
cif.push_back(x%zece);
x/=zece;
}
reverse(cif.begin(),cif.end());
for(auto c:cif) cout<<c;
}
signed main()
{
int n,A,B;
cin>>n>>A>>B;
A = A / gcd(A,B+1);
__int128 le,ri;
__int128 copA=A,copB=B;
__int128 prod=copA*copB;
int cle,cri;
for(int i=1;i<=n;i++)
{
cin>>cle>>cri;
le=cle;
ri=cri;
if(le==ri)
{
baga(le%prod,le%prod);
continue;
}
le = le%prod;
ri = ri%prod;
if(le<ri)
{
baga(le,ri);
}
else
{
baga(le,prod-1);
baga(0,ri);
}
}
__int128 cnt=0;
for(auto it:s)
{
cnt += it.second-it.first+1;
}
afis(cnt);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
11 ms |
1160 KB |
Output is correct |
3 |
Correct |
19 ms |
1040 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
12 ms |
1104 KB |
Output is correct |
17 |
Correct |
131 ms |
8088 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
755 ms |
404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1298 ms |
78416 KB |
Output is correct |
3 |
Correct |
1182 ms |
78676 KB |
Output is correct |
4 |
Correct |
1373 ms |
78436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1298 ms |
78416 KB |
Output is correct |
3 |
Correct |
1182 ms |
78676 KB |
Output is correct |
4 |
Correct |
1373 ms |
78436 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1391 ms |
78620 KB |
Output is correct |
7 |
Correct |
1258 ms |
78500 KB |
Output is correct |
8 |
Correct |
1246 ms |
78560 KB |
Output is correct |
9 |
Correct |
1375 ms |
78664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1298 ms |
78416 KB |
Output is correct |
3 |
Correct |
1182 ms |
78676 KB |
Output is correct |
4 |
Correct |
1373 ms |
78436 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
174 ms |
8040 KB |
Output is correct |
7 |
Correct |
141 ms |
8016 KB |
Output is correct |
8 |
Correct |
128 ms |
8016 KB |
Output is correct |
9 |
Correct |
140 ms |
8136 KB |
Output is correct |
10 |
Correct |
106 ms |
8068 KB |
Output is correct |
11 |
Correct |
106 ms |
8016 KB |
Output is correct |
12 |
Correct |
108 ms |
8036 KB |
Output is correct |
13 |
Correct |
147 ms |
8204 KB |
Output is correct |
14 |
Correct |
112 ms |
8028 KB |
Output is correct |
15 |
Correct |
140 ms |
8116 KB |
Output is correct |
16 |
Correct |
113 ms |
8060 KB |
Output is correct |
17 |
Correct |
130 ms |
8024 KB |
Output is correct |
18 |
Correct |
1194 ms |
78420 KB |
Output is correct |
19 |
Correct |
1108 ms |
78468 KB |
Output is correct |
20 |
Correct |
1170 ms |
78472 KB |
Output is correct |
21 |
Correct |
105 ms |
8020 KB |
Output is correct |
22 |
Correct |
103 ms |
8020 KB |
Output is correct |
23 |
Correct |
287 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
108 ms |
8124 KB |
Output is correct |
3 |
Correct |
114 ms |
8220 KB |
Output is correct |
4 |
Correct |
1167 ms |
78476 KB |
Output is correct |
5 |
Correct |
108 ms |
8016 KB |
Output is correct |
6 |
Correct |
113 ms |
8052 KB |
Output is correct |
7 |
Correct |
114 ms |
8120 KB |
Output is correct |
8 |
Correct |
113 ms |
8020 KB |
Output is correct |
9 |
Correct |
108 ms |
8016 KB |
Output is correct |
10 |
Correct |
105 ms |
7988 KB |
Output is correct |
11 |
Correct |
105 ms |
8000 KB |
Output is correct |
12 |
Correct |
104 ms |
8020 KB |
Output is correct |
13 |
Correct |
108 ms |
8200 KB |
Output is correct |
14 |
Correct |
1188 ms |
78592 KB |
Output is correct |
15 |
Correct |
99 ms |
7248 KB |
Output is correct |
16 |
Correct |
1057 ms |
78416 KB |
Output is correct |
17 |
Correct |
1069 ms |
78500 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
11 ms |
1160 KB |
Output is correct |
3 |
Correct |
19 ms |
1040 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
12 ms |
1104 KB |
Output is correct |
17 |
Correct |
131 ms |
8088 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |