#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
#define ih __int128
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9+7;
const ll inf = 1e18 + 1;
const int maxn = 1e6 + 1;
set<pair<ih, ih>> s;
ll ans;
void upd(ll l, ll r){
if(s.empty())return;
vt<pair<ih, ih>> del;
auto i = s.lower_bound({l, inf});
if(i != s.begin())i--;
if((*i).ss < l)i++;
while(i != s.end() && (*i).ff <= r){
if((*i).ff < l){
s.insert({(*i).ff, l - 1});
ans -= l - (*i).ff;
}
if((*i).ss > r){
s.insert({r + 1, (*i).ss});
ans -= (*i).ss - r;
}
del.pb(*i);
ans += (*i).ss - (*i).ff + 1;
i++;
}
for(auto i : del)s.erase(i);
}
void solve() {
int n;
ih a, b;
ll A, B;
cin >> n >> A >> B;
a = A, b = B;
ih md = a * b / __gcd(a, b + 1);
s.insert({0, md - 1});
for(int i = 0; i < n; i++){
ll l, r;
cin >> l >> r;
if(r - l + 1 >= md){
ans = md;
return;
}
l %= md, r %= md;
if(l <= r)upd(l, r);
else upd(0, r), upd(l, md - 1);
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int times = 1;
//cin >> times;
for(int i = 1; i <= times; i++) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |