제출 #1342226

#제출 시각아이디문제언어결과실행 시간메모리
1342226PieArmyWorst Reporter 3 (JOI18_worst_reporter3)C++20
100 / 100
310 ms5328 KiB
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define fr first
#define sc second
#define endl '\n'
using namespace std;
#define mid ((left+right)>>1)

int n,q;
int arr[500023];

signed main(){
	ios_base::sync_with_stdio(23^23);cin.tie(0);
	cin>>n>>q;
	arr[0]=1;
	for(int i=1;i<=n;i++){
		cin>>arr[i];
		arr[i]=arr[i-1]*((arr[i]-1)/arr[i-1]+1);
	}
	while(q--){
		int t,left,right;cin>>t>>left>>right;
		int l=0,r=n+1;
		while(l<r){
			int mi=(l+r)/2;
			if(arr[mi]*(t/arr[mi])-mi<=right)r=mi;
			else l=mi+1;
		}
		right=r;
		l=-1;r=n;
		while(l<r){
			int mi=(l+r+1)/2;
			if(arr[mi]*(t/arr[mi])-mi>=left)l=mi;
			else r=mi-1;
		}
		left=l;
		cout<<left-right+1<<endl;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...