#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define pll pair<long long,long long>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
const int maxn=5e5+9;
long long a[maxn];
long long jump[maxn];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen(".OUT","w",stdout);
int n,q;
cin>>n>>q;
for1(i,1,n){
cin>>a[i];
}
jump[1]=1;
for1(i,2,n){
jump[i]=jump[i-1];
long long l=1,r=(1e15)/(jump[i-1]*a[1]);
while (l<=r){
long long mid=(l+r)/2;
if (a[1]*(jump[i-1])*mid>=a[i]){
jump[i]=mid*jump[i-1];
r=mid-1;
}
else l=mid+1;
}
}
vector<pll>line;
line.pb({0,0});
for1(i,1,n){
if (jump[i]>jump[i-1]){
line.pb({-i,-i});
}
else line.back().se=-i;
}
//for (auto v:line)cout<<v.fi<<" "<<v.se<<'\n';
//for1(i,1,n)cout<<jump[i]<<'\n';
for1(i,1,q){
long long ans=0;
int l,r,t;
cin>>t>>l>>r;
vector<pll>cop=line;
cop[0].fi+=t;
cop[0].se+=t;
//cout<<sz(cop)<<'\n';
for1(j,1,sz(cop)-1){
//cout<<cop[j].fi<<" "<<cop[j].se<<'\n';
long long dis=(cop[j-1].se-cop[j].fi)-1;
dis/=(a[1]*jump[abs(cop[j].fi)]);
//cout<<dis<<'\n';
dis*=(a[1]*jump[abs(cop[j].fi)]);
cop[j].fi+=dis;
cop[j].se+=dis;
//cout<<cop[j].fi<<" "<<cop[j].se<<'\n';
}
for (auto v:cop){
if (v.fi<l)continue;
if (v.se>r)continue;
long long l1=max(1ll*l,v.se),r1=min(1ll*r,v.fi);
ans+=1ll*(r1-l1+1);
//cout<<v.fi<<" "<<v.se<<'\n';
}
cout<<ans<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
26624 KB |
Output is correct |
2 |
Correct |
236 ms |
26572 KB |
Output is correct |
3 |
Correct |
211 ms |
26584 KB |
Output is correct |
4 |
Correct |
211 ms |
26512 KB |
Output is correct |
5 |
Correct |
215 ms |
26524 KB |
Output is correct |
6 |
Correct |
216 ms |
26552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
219 ms |
26624 KB |
Output is correct |
2 |
Correct |
236 ms |
26572 KB |
Output is correct |
3 |
Correct |
211 ms |
26584 KB |
Output is correct |
4 |
Correct |
211 ms |
26512 KB |
Output is correct |
5 |
Correct |
215 ms |
26524 KB |
Output is correct |
6 |
Correct |
216 ms |
26552 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
225 ms |
25120 KB |
Output is correct |
14 |
Correct |
207 ms |
25676 KB |
Output is correct |
15 |
Correct |
189 ms |
24344 KB |
Output is correct |
16 |
Correct |
207 ms |
24964 KB |
Output is correct |
17 |
Correct |
283 ms |
29096 KB |
Output is correct |
18 |
Correct |
291 ms |
29184 KB |
Output is correct |
19 |
Correct |
297 ms |
29160 KB |
Output is correct |
20 |
Correct |
294 ms |
29108 KB |
Output is correct |
21 |
Correct |
284 ms |
29148 KB |
Output is correct |
22 |
Correct |
293 ms |
29152 KB |
Output is correct |
23 |
Correct |
279 ms |
29096 KB |
Output is correct |
24 |
Correct |
285 ms |
29228 KB |
Output is correct |
25 |
Correct |
226 ms |
26532 KB |
Output is correct |
26 |
Correct |
225 ms |
26736 KB |
Output is correct |
27 |
Correct |
294 ms |
28752 KB |
Output is correct |
28 |
Correct |
315 ms |
29024 KB |
Output is correct |
29 |
Correct |
313 ms |
28548 KB |
Output is correct |
30 |
Correct |
313 ms |
28644 KB |
Output is correct |
31 |
Correct |
312 ms |
28968 KB |
Output is correct |
32 |
Correct |
207 ms |
25192 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |