#include<bits/stdc++.h>
#define inf 2000000000000000000
#define ll long long
using namespace std;
struct tre{
ll lazy,sum,L,R;
tre() {
lazy = sum = L = R = 0;
}
};
vector<tre>t(1);
void push(int v,int tl,int tr,int L,int R) {
int tm = (tl + tr)/2;
if (t[v].lazy) {
t[L].lazy = t[R].lazy = 1;
t[L].sum = tm - tl+1;
t[R].sum = tr - tm;
t[v].lazy = 0;
}
}
void upd(int v,int tl,int tr,int l,int r) {
if (l > tr || r < tl) return;
if (l <= tl && r >= tr) {
t[v].lazy = 1;
t[v].sum = tr - tl + 1;
return;
}
int tm = (tl + tr)/2;
if (t[v].L == 0) {
t[v].L = t.size();
t.push_back(tre());
}
if (t[v].R == 0) {
t[v].R = t.size();
t.push_back(tre());
}
push(v,tl,tr,t[v].L,t[v].R);
upd(t[v].L,tl,tm,l,r);
upd(t[v].R,tm+1,tr,l,r);
t[v].sum = t[ t[v].L ].sum + t[ t[v].R ].sum;
}
main() {
ll n,a,b;
cin >> n >> a >> b;
ll m = a/(__gcd(a,b+1));
if (m > inf/b) m = inf;
else m*=b;
for (int l,r;n--;) {
cin >> l >> r;
if (r - l + 1 >= m) {
cout << m <<'\n';
exit(0);
}
l%=m;
r%=m;
if ( l <= r) {
upd(0,0,m-1,l,r);
// cout << t[0].sum <<'\n';
}
else {
upd(0,0,m-1,l,m-1);
upd(0,0,m-1,0,r);
}
}
cout << t[0].sum;
}
Compilation message
strange_device.cpp:47:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main() {
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
7 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
566 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
566 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
566 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
93 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Incorrect |
7 ms |
384 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |