이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
long long n,q,a[500005],sttime[500005],t,l,r,mid,ll,rr;
long long f(long long tt,long long k){
	return ((tt)/sttime[k])*sttime[k]-k;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin>>n>>q;
	for (int i=1;i<=n;i++) cin>>a[i];
	sttime[1] = a[1];
	for (int i=2;i<=n;i++){
		sttime[i] = ((a[i]+sttime[i-1]-1)/sttime[i-1])*sttime[i-1];
	}
	while (q--){
		cin>>t>>l>>r;
		long long ans=0;
		
		long long ansl=1; long long ansr=n;
		if (f(t,1)<l) goto skip;
		if (r<f(t,n)) goto skip;		
		ll=1; rr=n;
		
		while (ll<=rr){
			mid=(ll+rr)/2;
			if (l<=f(t,mid)){
				ansl=max(ansl,mid);
				ll=mid+1;
			}
			else rr=mid-1;
		}
		
		ll=1; rr=n;
		while (ll<=rr){
			mid=(ll+rr)/2;
			if (f(t,mid)<=r){
				ansr=min(ansr,mid);
				rr=mid-1;
			}
			else ll=mid+1;
		}
		
		if (ansl>=ansr) ans=ansl-ansr+1;
		skip:;
		
		/*
		for (int i=1;i<=n;i++){
			if (l<=f(t,i)&&f(t,i)<=r) ans++;
		}
		*/
		if (l<=t && t<=r) ans++;
		
		cout<<ans<<endl;
	}
}
/*
6 1
11
36
28
80
98
66
190 171 210
*/
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |