Submission #100887

# Submission time Handle Problem Language Result Execution time Memory
100887 2019-03-15T02:52:23 Z TAISA_ Worst Reporter 3 (JOI18_worst_reporter3) C++14
100 / 100
1398 ms 23672 KB
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<int,int>;
const ll MOD=1000000007LL;
const ll INF=(1<<30);
const ll LINF=(1LL<<60);
template<typename T> void chmax(T &a,T b){a=max(a,b);}
template<typename T> void chmin(T &a,T b){a=min(a,b);} 
int main(){
	ll n,q;cin>>n>>q;
	vector<ll> d(n+10),s(n+10);
	for(int i=1;i<=n;i++){
		scanf("%lld",&d[i]);
	}
	s[0]=1;
	s[1]=d[1];
	for(int i=2;i<=n;i++){
		if(s[i-1]>=INF){
			s[i]=INF;
		}else{
			s[i]=s[i-1]*((d[i]/s[i-1])+(d[i]%s[i-1]>0LL));
			chmin(s[i],INF);
		}
	}
	while(q--){
		ll t,l,r;scanf("%lld%lld%lld",&t,&l,&r);
		if((t/s[0])*s[0]<l||-n+(t/s[n])*s[n]>r){
			cout<<0<<endl;
			continue;
		}
		ll ok=n,ng=-1;
		while(ok-ng>1){
			ll mid=(ok+ng)/2;
			ll pos=-mid+(t/s[mid])*s[mid];
			if(pos<=r){
				ok=mid;
			}else{
				ng=mid;
			}
		}
		int vr=ok;
		ok=0,ng=n+1;
		while(ng-ok>1){
			ll mid=(ok+ng)/2;
			ll pos=-mid+(t/s[mid])*s[mid];
			if(pos>=l){
				ok=mid;
			}else{
				ng=mid;
			}
		}
		int vl=ok;
		printf("%d\n",vl-vr+1);
	}
}

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&d[i]);
   ~~~~~^~~~~~~~~~~~~~
worst_reporter3.cpp:28:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   ll t,l,r;scanf("%lld%lld%lld",&t,&l,&r);
            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1277 ms 11600 KB Output is correct
2 Correct 1398 ms 23672 KB Output is correct
3 Correct 1344 ms 23528 KB Output is correct
4 Correct 1331 ms 23564 KB Output is correct
5 Correct 1171 ms 23544 KB Output is correct
6 Correct 1125 ms 23564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 3 ms 356 KB Output is correct
6 Correct 3 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1277 ms 11600 KB Output is correct
2 Correct 1398 ms 23672 KB Output is correct
3 Correct 1344 ms 23528 KB Output is correct
4 Correct 1331 ms 23564 KB Output is correct
5 Correct 1171 ms 23544 KB Output is correct
6 Correct 1125 ms 23564 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 3 ms 356 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 717 ms 20632 KB Output is correct
14 Correct 785 ms 15480 KB Output is correct
15 Correct 734 ms 20600 KB Output is correct
16 Correct 811 ms 20344 KB Output is correct
17 Correct 929 ms 10740 KB Output is correct
18 Correct 967 ms 10920 KB Output is correct
19 Correct 930 ms 10792 KB Output is correct
20 Correct 907 ms 10832 KB Output is correct
21 Correct 936 ms 10788 KB Output is correct
22 Correct 945 ms 10784 KB Output is correct
23 Correct 918 ms 10744 KB Output is correct
24 Correct 909 ms 10744 KB Output is correct
25 Correct 1210 ms 22392 KB Output is correct
26 Correct 1220 ms 22008 KB Output is correct
27 Correct 950 ms 11384 KB Output is correct
28 Correct 909 ms 11300 KB Output is correct
29 Correct 1041 ms 11112 KB Output is correct
30 Correct 1038 ms 11380 KB Output is correct
31 Correct 1038 ms 11264 KB Output is correct
32 Correct 1014 ms 21620 KB Output is correct
33 Correct 2 ms 384 KB Output is correct