#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int N=1e6+6;
struct Node{
ll l;
ll r;
int vl=-1;
int vr=-1;
ll val=0;
};
Node tree[15*N];
int K;
ll GCD(ll x, ll y){
while(x*y!=0){
if(x>y) x%=y;
else y%=x;
}
return x+y;
}
void update(int v, ll ql, ll qr){
if(tree[v].val==tree[v].r-tree[v].l+1){
return;
}
if(qr<tree[v].l && tree[v].r<ql){
return;
}
if(ql<=tree[v].l && tree[v].r<=qr){
tree[v].val=tree[v].r-tree[v].l+1;
return;
}
ll mid=(tree[v].l+tree[v].r)/2;
if(qr<=mid){
if(tree[v].vl==-1){
K++;
tree[v].vl=K;
tree[tree[v].vl].l=tree[v].l;
tree[tree[v].vl].r=mid;
update(tree[v].vl, ql, qr);
}
else if(tree[tree[v].vl].val!=mid-tree[v].l+1){
update(tree[v].vl, ql, qr);
}
}
else if(mid+1<=ql){
if(tree[v].vr==-1){
K++;
tree[v].vr=K;
tree[tree[v].vr].l=mid+1;
tree[tree[v].vr].r=tree[v].r;
update(tree[v].vr, ql, qr);
}
else if(tree[tree[v].vr].val!=tree[v].r-mid){
update(tree[v].vr, ql, qr);
}
}
else{
if(tree[v].vl==-1){
K++;
tree[v].vl=K;
tree[tree[v].vl].l=tree[v].l;
tree[tree[v].vl].r=mid;
update(tree[v].vl, ql, qr);
}
else if(tree[tree[v].vl].val!=mid-tree[v].l+1){
update(tree[v].vl, ql, qr);
}
if(tree[v].vr==-1){
K++;
tree[v].vr=K;
tree[tree[v].vr].l=mid+1;
tree[tree[v].vr].r=tree[v].r;
update(tree[v].vr, ql, qr);
}
else if(tree[tree[v].vr].val!=tree[v].r-mid){
update(tree[v].vr, ql, qr);
}
}
tree[v].val=tree[tree[v].vl].val+tree[tree[v].vr].val;
// cout<<v<<" "<<ql<<" "<<qr<<" "<<tree[v].l<<" "<<tree[v].r<<" "<<tree[v].val<<endl;
}
ll query(int v, ll l, ll r){
return tree[v].val;
}
int main(){
ll n, i, A, B, l, r, k, m, ma;
scanf("%lld",&n);
scanf("%lld",&A);
scanf("%lld",&B);
m=GCD(B+1, A);
A/=m;
ma=1000000000000000002;
if(ma/A<B){
k=ma;
}
else{
k=A*B;
}
// cout<<k<<endl;
tree[0].l=0;
tree[0].r=k-1;
K=0;
l=1;
for(i=1; i<=n; i++){
l=i;
r=l;
// scanf("%lld",&l);
// scanf("%lld",&r);
if(r-l+1>=k) update(0, 0, k-1);
else{
if(l%k<=r%k){
update(0, l%k, r%k);
}
else{
update(0, l%k, k-1);
update(0, 0, r%k);
}
}
l+=2;
}
printf("%lld\n", query(0, 0, k-1));
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:98:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
strange_device.cpp:99:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | scanf("%lld",&A);
| ~~~~~^~~~~~~~~~~
strange_device.cpp:100:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
100 | scanf("%lld",&B);
| ~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
469840 KB |
Output is correct |
2 |
Incorrect |
114 ms |
470096 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
469844 KB |
Output is correct |
2 |
Incorrect |
114 ms |
469844 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
469940 KB |
Output is correct |
2 |
Incorrect |
111 ms |
470096 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
469844 KB |
Output is correct |
2 |
Incorrect |
265 ms |
470100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
469844 KB |
Output is correct |
2 |
Incorrect |
265 ms |
470100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
469844 KB |
Output is correct |
2 |
Incorrect |
265 ms |
470100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
470036 KB |
Output is correct |
2 |
Incorrect |
131 ms |
470100 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
217 ms |
469840 KB |
Output is correct |
2 |
Incorrect |
114 ms |
470096 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |