이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/* in the name of allah */
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define F first
#define S second
#define mk make_pair
typedef long long ll;
const int N=5e5+7;
ll n,q,d[N],s[N],x[N];
ll pos(int i,ll t){
	return -i+(t/s[i])*x[i];
}
int main(){
	ios:: sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>d[i];
	}
	s[0]=1,x[0]=1;
	for(int i=1;i<=n;i++){
		ll f=d[i]/x[i-1]+(d[i]%x[i-1]!=0);
		s[i]=f*s[i-1];
		x[i]=f*x[i-1];
	}
	while(q--){
		ll t,s,e;
		cin>>t>>s>>e;
		int L,R=0;
		int l=-1,r=n;
		while(r-l>1){
			int m=(l+r)/2;
			if(pos(m,t)<=e)r=m;
			else l=m;
		}
		L=r;
		l=0,r=n+1;
		while(r-l>1){
			int m=(l+r)/2;
			//cout<<m<<endl;
			if(pos(m,t)>=s)l=m;
			else r=m;
		}
		
		R=l;
		if(pos(L,t)>e || pos(R,t)<s)L++;
		
		cout<<R-L+1<<endl;
		//cout<<L<<" "<<R<<endl;
	}
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |