#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define int ll
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define INF INT_MAX
#define MOD 1000000007
#define all(x) x.begin(), x.end()
namespace DST {
struct node {
int sum{}, lazy{}, tot{};
node *l = NULL, *r = NULL;
};
auto root = new node;
void upd(node *n, int l, int r){
if(!n) return;
if(n->sum) n->tot = r-l+1;
else{
n->tot = 0;
if(n->l) n->tot += n->l->tot;
if(n->r) n->tot += n->r->tot;
}
return;
}
void update(node *n, int l, int r, int L, int R, int val){
if(r < L or R < l) return;
if(L <= l and r <= R){
n->sum += val;
upd(n, l, r);
return;
}
if(!n->l) n->l = new node;
if(!n->r) n->r = new node;
int m = (l+r)/2;
update(n->l, l, m, L, R, val);
update(n->r, m+1, r, L, R, val);
upd(n, l, r);
}
void update(int L, int R, int val){
update(root, 0, 1e18+10, L, R, val);
}
int query(){
return root->tot;
}
};
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int Q, A, B; cin >> Q >> A >> B;
int A1 = A/__gcd(A, B+1);
if(A1 <= int(1e18)/B) A1 *= B;
else A1 = 1e18+10;
while(Q--){
int l, r; cin >> l >> r;
if(r-l+1 >= A1) DST::update(0, A1-1, 1);
else{
int lm = l%A1, rm = r%A1;
if(lm <= rm) DST::update(lm, rm, 1);
else DST::update(lm, A1-1, 1), DST::update(0, rm, 1);
}
}
cout << DST::query() << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
20 ms |
4120 KB |
Output is correct |
3 |
Correct |
23 ms |
4808 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
20 ms |
3624 KB |
Output is correct |
17 |
Correct |
163 ms |
10044 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
4 ms |
1356 KB |
Output is correct |
3 |
Correct |
4 ms |
1356 KB |
Output is correct |
4 |
Correct |
4 ms |
1356 KB |
Output is correct |
5 |
Correct |
1621 ms |
296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1624 ms |
94248 KB |
Output is correct |
3 |
Runtime error |
1176 ms |
524292 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1624 ms |
94248 KB |
Output is correct |
3 |
Runtime error |
1176 ms |
524292 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1624 ms |
94248 KB |
Output is correct |
3 |
Runtime error |
1176 ms |
524292 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
249 ms |
63692 KB |
Output is correct |
3 |
Correct |
326 ms |
147700 KB |
Output is correct |
4 |
Runtime error |
1053 ms |
524292 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
20 ms |
4120 KB |
Output is correct |
3 |
Correct |
23 ms |
4808 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
460 KB |
Output is correct |
16 |
Correct |
20 ms |
3624 KB |
Output is correct |
17 |
Correct |
163 ms |
10044 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
4 ms |
1356 KB |
Output is correct |
26 |
Correct |
4 ms |
1356 KB |
Output is correct |
27 |
Correct |
4 ms |
1356 KB |
Output is correct |
28 |
Correct |
1621 ms |
296 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1624 ms |
94248 KB |
Output is correct |
31 |
Runtime error |
1176 ms |
524292 KB |
Execution killed with signal 9 |
32 |
Halted |
0 ms |
0 KB |
- |