#include<bits/stdc++.h>
using namespace std;
#define foru(i,a,b) for(int i=(a); i<=(b); ++i)
#define ford(i,a,b) for(int i=(a); i>=(b); --i)
#define rep(i,a) for(int i=0; i<(a); ++i)
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define bit(s,i) (((s)>>(i))&1)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define fi first
#define se second
#define ll long long
#define eb emplace_back
#define pb push_back
#define __builtin_popcount __builtin_popcountll
#define _ << " " <<
template <class X, class Y> bool maxi(X &x, Y y){return x<y?x=y,true:false;}
template <class X, class Y> bool mini(X &x, Y y){return x>y?x=y,true:false;}
const int N=505050;
int n,q,d[N],e[N],cnt;
void solve(){
cin>>n>>q;
d[0]=1; foru(i,1,n) cin>>d[i];
foru(i,0,n){
if(cnt==0 || d[e[cnt]]<d[i]){
e[++cnt]=i;
}
}
e[cnt+1]=n+1;
foru(qq,1,q){
int t,l,r; cin>>t>>l>>r;
int x=t, y=1, res=0;
foru(i,1,cnt){
if(y==0 || x==0) break;
int nx=x/((d[e[i]]+y-1)/y),
ny=(d[e[i]]+y-1)/y*y;
int LL=i,RR=cnt,lst=i;
while(LL<=RR){
int M=(LL+RR)>>1;
if((d[e[M]]+y-1)/y==(d[e[i]]+y-1)/y){
LL=M+1;
lst=M;
}else{
RR=M-1;
}
}
int L=-(e[lst+1]-1), R=-e[i];
L=L+nx*ny, R=R+nx*ny;
res+=max(0,min(R,r)-max(L,l)+1);
x=nx, y=ny;
i=lst;
}
cout<<res<<'\n';
}
}
int32_t main(){
#define task "test"
if(fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
int tc=1; //cin>>tc;
foru(i,1,tc){
solve();
}
}
Compilation message (stderr)
worst_reporter3.cpp: In function 'int32_t main()':
worst_reporter3.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |