// #pragma GCC target ("avx,avx2,fma")
// #pragma GCC optimize ("Ofast,inline") // O1 - O2 - O3 - Os - Ofast
// #pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b - 1); i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define debug(x) cout<<#x<<" = "<<x<<endl
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const int INF = 1'000'000'007;
struct Node {
ll sum=0,lo,hi,mset=INF;
Node *l=0,*r=0;
Node(ll L,ll R) : lo(L),hi(R) {}
void set(ll L,ll R,ll x) {
if(hi<=L||R<=lo) return;
if(L<=lo&&hi<=R) {
mset=x;
sum=(hi-lo)*mset;
} else {
push();
l->set(L,R,x),r->set(L,R,x);
sum=l->sum+r->sum;
}
}
void push() {
if(!l) {
ll mid=(lo+hi)/2;
l=new Node(lo,mid);
r=new Node(mid,hi);
}
if(mset!=INF) {
l->set(lo,hi,mset),r->set(lo,hi,mset);
mset=INF;
}
}
};
int n;
ll A,B,len;
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
cin>>n>>A>>B;
ll x=A/__gcd(A,B+1);
if(log10(x)+log10(B)>18) len=ll(1e18);
else len=B*x;
//debug(len);
Node segtree(0,len);
while(n--) {
ll lo,hi;
cin>>lo>>hi;
++hi;
if(hi-lo>=len) segtree.set(0,len,1);
else {
ll start=lo%len,take=min(hi-lo,(len-start)%len);
//cout<<"start = "<<start<<" stop = "<<start+take<<endl;
segtree.set(start,start+take,1);
start=0;
take=(hi-lo)-take;
//cout<<"start = "<<start<<" stop = "<<start+take<<endl;
segtree.set(start,start+take,1);
}
//cout<<endl;
}
cout<<segtree.sum<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
10 ms |
5844 KB |
Output is correct |
3 |
Correct |
11 ms |
6916 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
9 ms |
5324 KB |
Output is correct |
17 |
Correct |
59 ms |
17128 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
1872 KB |
Output is correct |
3 |
Correct |
3 ms |
1736 KB |
Output is correct |
4 |
Correct |
2 ms |
1748 KB |
Output is correct |
5 |
Correct |
374 ms |
8880 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
567 ms |
162740 KB |
Output is correct |
3 |
Runtime error |
674 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
567 ms |
162740 KB |
Output is correct |
3 |
Runtime error |
674 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
567 ms |
162740 KB |
Output is correct |
3 |
Runtime error |
674 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
132 ms |
88312 KB |
Output is correct |
3 |
Correct |
280 ms |
200988 KB |
Output is correct |
4 |
Runtime error |
588 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
10 ms |
5844 KB |
Output is correct |
3 |
Correct |
11 ms |
6916 KB |
Output is correct |
4 |
Correct |
1 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
316 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
9 ms |
5324 KB |
Output is correct |
17 |
Correct |
59 ms |
17128 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
260 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
1872 KB |
Output is correct |
26 |
Correct |
3 ms |
1736 KB |
Output is correct |
27 |
Correct |
2 ms |
1748 KB |
Output is correct |
28 |
Correct |
374 ms |
8880 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
567 ms |
162740 KB |
Output is correct |
31 |
Runtime error |
674 ms |
524288 KB |
Execution killed with signal 9 |
32 |
Halted |
0 ms |
0 KB |
- |