#include <bits/stdc++.h>
using std::cin, std::cout, std::vector, std::set, std::endl, std::string, std::map,std::pair;
#ifdef LOCAL
#define file freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#else
#define file ;;
#endif
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using Tree = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include <random>
class psegt{
public:
class Node{
public:
int val = 0;
bool lazy = 0;
Node* left = nullptr;
Node* right = nullptr;
Node(){}
Node(int val, int lazy): val(val),lazy(lazy){}
int get(){
if(left!=nullptr && right!=nullptr) return val = right->val+left->val;
if(left!=nullptr) return val = left->val;
if(right!=nullptr) return val = right->val;
return val;
}
};
int len;
psegt(int len): len(len){}
Node root;
void update(Node* node, int l, int r, int x, int y){
if(node->val == r-l+1) return;
if(l>=x && r<=y){
node->val = r-l+1;
node->lazy = 1;
}
int mid = (l+r)/2;
if(node->left == nullptr){
node->left = new Node(node->lazy ? (mid-l+1):0, node->lazy);
node->right = new Node(node->lazy ? (r-mid):0, node->lazy);
node->lazy = 0;
}
if(mid<x) update(node->right, mid+1, r, x, y);
else if(mid>=y) update(node->left, l, mid, x, y);
else{
update(node->left, l, mid, x, y);
update(node->right, mid+1, r, x, y);
}
node->get();
}
void update(int l, int r){
update(&root, 0, len, l, r);
}
};
int main(){
file;
long long n,A,B;
cin >> n >> A >> B;
vector<long long> l(n),r(n);
set<pair<long long,long long>> s;
long long k = B;
if(B%A!=A-1){
if(A>std::numeric_limits<long long>::max()/k){
int ans = n;
for(int i=0;i<n;i++){
cin >> l[i] >> r[i];
ans += r[i]-l[i];
}
cout << ans << endl;
return 0;
}
k*=A;
}
psegt pst(k-1);
for(int i=0;i<n;i++){
cin >> l[i] >> r[i];
l[i]%=k;
r[i]%=k;
if(r[i]<l[i]){
pst.update(l[i],k-1);
pst.update(0,r[i]);
}
else
pst.update(l[i],r[i]);
}
cout << pst.root.val << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
12 ms |
5212 KB |
Output is correct |
3 |
Correct |
12 ms |
6404 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
4 ms |
1372 KB |
Output is correct |
3 |
Correct |
2 ms |
1372 KB |
Output is correct |
4 |
Correct |
2 ms |
1372 KB |
Output is correct |
5 |
Correct |
596 ms |
16084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
876 ms |
141184 KB |
Output is correct |
3 |
Runtime error |
274 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
876 ms |
141184 KB |
Output is correct |
3 |
Runtime error |
274 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
876 ms |
141184 KB |
Output is correct |
3 |
Runtime error |
274 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
163 ms |
84696 KB |
Output is correct |
3 |
Runtime error |
288 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
12 ms |
5212 KB |
Output is correct |
3 |
Correct |
12 ms |
6404 KB |
Output is correct |
4 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |