#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
struct tree {
i64 tl, tr, sum;
tree *lc, *rc;
bool lazy;
tree(i64 l, i64 r) {
tl = l;
tr = r;
sum = 0;
lazy = 0;
lc = NULL;
rc = NULL;
}
void upt(i64 l, i64 r) {
if(lazy) return;
if(tl == l && r == tr) {
sum = r - l + 1;
lazy = 1;
return;
}
i64 tm = (tl + tr) / 2;
if(lc == NULL) lc = new tree(tl, tm);
if(rc == NULL) rc = new tree(tm + 1, tr);
if(r <= tm) lc-> upt(l, r);
else if(tm < l) rc-> upt(l, r);
else {
lc-> upt(l, tm);
rc-> upt(tm + 1, r);
}
sum = lc-> sum + rc-> sum;
if(lc-> lazy && rc-> lazy)
lazy = 1;
}
};
i64 gcd(i64 a, i64 b) {
if(a == 0) return b;
if(b == 0) return a;
return gcd(b % a, a);
}
int main() {
int n, gay = 0;
i64 A, B;
cin >> n >> A >> B;
i64 T = A / gcd(A, B - 1) * B;
cout << T << endl;
tree *root = new tree(0, T - 1);
for(int i = 0; i < n; i++) {
i64 l, r;
cin >> l >> r;
l %= T;
r %= T;
// cout << l << ' ' << r << endl;
if(gay) continue;
if(r - l + 1 >= T) {
gay = 1;
continue;
}
if(l <= r) {
// cout << " > " << l << ' ' << r << endl;
root-> upt(l, r);
}
else {
// cout << " > " << l << ' ' << T - 1 << endl;
// cout << " > " << 0 << ' ' << r << endl;
root-> upt(l, T - 1);
root-> upt(0, r);
}
}
if(gay) cout << T << endl;
else cout << root-> sum << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |