답안 #73517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73517 2018-08-28T11:21:48 Z mraron Worst Reporter 3 (JOI18_worst_reporter3) C++14
100 / 100
1611 ms 191608 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
/*
vector<int> get(int ti, vector<int>& t, int& n) {
	vector<int> akt(n);
	for(int i=0;i<n;++i) {
		akt[i]=-i-1;
	}
	
	vector<int> ans;
	for(int i=0;i<ti;++i) {
		for(int j=0;j<n;++j) {
			if(j==0) {
				if(abs(i-akt[j])>=t[j]+1) {
					akt[j]=i-1;
				}
			}else {
				if(abs(akt[j-1]-akt[j])>=t[j]+1) {
					akt[j]=akt[j-1]-1;
				}
			}
		}
		
		if(i==ti-1) {
			for(int j=n-1;j>=0;--j) {
				ans.push_back(akt[j]);
			}
		}
		
	}
	
	return ans;
}*/
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,q;
	cin>>n>>q;
	vector<int> t(n);
	for(int i=0;i<n;++i) {
		cin>>t[i];
	}
	
	vector<ll> tt(n), mennyi(n);
	tt[0]=t[0];
	mennyi[0]=t[0];
	for(int i=1;i<n;++i) {
		if(t[i]>t[i-1]) {
			tt[i]=tt[i-1]*((t[i]+mennyi[i-1]-1)/mennyi[i-1]);
			mennyi[i]=tt[i];
		}else {
			tt[i]=tt[i-1];
			mennyi[i]=mennyi[i-1];
		}
	}
	
	for(int i=1;i<=q;++i) {
		ll ti,a,b;
		cin>>ti>>a>>b;
		//ti=i;
/*		for(int j=n-1;j>=0;--j) {
			cerr<<(-j-1+mennyi[j]*(ti/tt[j]))<<" ";
		}cerr<<ti<<"\n";
		
		for(auto j:get(ti, t, n)) {
			cerr<<j<<" ";
		}cerr<<ti<<"\n";*/
		
		
		//continue ;
		ll legelso, legutolso;
		
		ll L=0, R=n; //legelső a range előtt
		while(L<R) {
			
			ll mid=(L+R)/2;
			ll pos;
			if(mid<n) {
				assert(mid>=0&&mid<n);
				pos=-mid-1+mennyi[mid]*(ti/tt[mid]);	
			}else pos=-1e9;
		//cerr<<L<<" "<<R<<" "<<mid<<"LR\n";
			//cerr<<mid<<" "<<pos<<"\n";
		//	cerr<<ti<<"time "<<mid<<" "<<pos<<"\n";
			if(pos<a) {
				R=mid;
			}else {
				L=mid+1;
			}
		}
		
	//	cerr<<L<<"!!\n";
		legelso=L;
		L=-1;R=n-1; //legelső a range után
		while(L<R) {
			ll mid=(L+R+1)/2;
			ll pos;
			if(mid==-1) {
				pos=1e9;
			}else {
				assert(mid>=0&&mid<n);
				pos=-mid-1+mennyi[mid]*(ti/tt[mid]);
			}
	//		cerr<<L<<" "<<R<<"\n";
			if(pos>b) {
				L=mid;
			}else {
				R=mid-1;
			}
		}
		
		//cerr<<L<<" "<<R<<"can we hit 1212 lieks?\n";
		legutolso=L;
		
		//cerr<<legutolso<<" "<<legelso<<"\n";
		assert(legelso>=legutolso);

		cout<<legelso-legutolso-1+(a<=ti&&ti<=b)<<"\n";
	}
	
	/*for(int i=0;i<300;++i) {
		for(auto j:get(i, t, n)) {
			cerr<<j<<" ";
		}cerr<<i<<"\n";
	}
	
	for(auto i:tt) {
		cerr<<i<<" ";
	}cerr<<"\n";
	
	for(auto i:mennyi) {
		cerr<<i<<" ";
	}cerr<<"\n";
	*/
	
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1222 ms 16948 KB Output is correct
2 Correct 1172 ms 19648 KB Output is correct
3 Correct 1175 ms 19772 KB Output is correct
4 Correct 1160 ms 19804 KB Output is correct
5 Correct 1162 ms 19804 KB Output is correct
6 Correct 1178 ms 19860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 19860 KB Output is correct
2 Correct 3 ms 19860 KB Output is correct
3 Correct 5 ms 19860 KB Output is correct
4 Correct 3 ms 19860 KB Output is correct
5 Correct 5 ms 19860 KB Output is correct
6 Correct 3 ms 19860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1222 ms 16948 KB Output is correct
2 Correct 1172 ms 19648 KB Output is correct
3 Correct 1175 ms 19772 KB Output is correct
4 Correct 1160 ms 19804 KB Output is correct
5 Correct 1162 ms 19804 KB Output is correct
6 Correct 1178 ms 19860 KB Output is correct
7 Correct 4 ms 19860 KB Output is correct
8 Correct 3 ms 19860 KB Output is correct
9 Correct 5 ms 19860 KB Output is correct
10 Correct 3 ms 19860 KB Output is correct
11 Correct 5 ms 19860 KB Output is correct
12 Correct 3 ms 19860 KB Output is correct
13 Correct 604 ms 19860 KB Output is correct
14 Correct 601 ms 19860 KB Output is correct
15 Correct 618 ms 19860 KB Output is correct
16 Correct 688 ms 19860 KB Output is correct
17 Correct 921 ms 19860 KB Output is correct
18 Correct 860 ms 19860 KB Output is correct
19 Correct 910 ms 19860 KB Output is correct
20 Correct 870 ms 19860 KB Output is correct
21 Correct 888 ms 19860 KB Output is correct
22 Correct 897 ms 19860 KB Output is correct
23 Correct 923 ms 37880 KB Output is correct
24 Correct 982 ms 56660 KB Output is correct
25 Correct 1611 ms 72616 KB Output is correct
26 Correct 1574 ms 88236 KB Output is correct
27 Correct 954 ms 105688 KB Output is correct
28 Correct 875 ms 123888 KB Output is correct
29 Correct 941 ms 141744 KB Output is correct
30 Correct 971 ms 159516 KB Output is correct
31 Correct 886 ms 177408 KB Output is correct
32 Correct 882 ms 191608 KB Output is correct
33 Correct 3 ms 191608 KB Output is correct