답안 #69769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69769 2018-08-21T13:12:24 Z yogahmad Worst Reporter 3 (JOI18_worst_reporter3) C++14
100 / 100
1383 ms 207200 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 500003
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;

long long n,a[mx],gerak[mx],setiap[mx],q,t,l,r;

long long cel(long long a,long long b){
	long long ret=a/b;
	if(a%b)ret++;
	return ret;
}

int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	setiap[0]=gerak[0]=1;
	gerak[1]=a[1];
	setiap[1]=a[1];
	for(int i=2;i<=n;i++){
		long long sem=cel(a[i],gerak[i-1]);
		setiap[i]=sem*setiap[i-1];
		gerak[i]=sem*gerak[i-1];
	}
	//for(int i=1;i<=n;i++)cout<<setiap[i]<<' '<<gerak[i]<<endl;
	while(q--){
		scanf("%lld%lld%lld",&t,&l,&r);
		int lo=0,hi=n,kiri=-1;
		while(lo<=hi){
			int mid=(lo+hi)>>1;
			long long brp=t/setiap[mid];
			brp=brp*gerak[mid];
			long long di=brp-mid;
			if(l<=di){
				lo=mid+1;
				kiri=mid;
			}
			else hi=mid-1;
		}
	//	debug(kiri);
		if(kiri==-1){
			puts("0");
			continue;
		}
		lo=0,hi=n;
		int kanan=-1;
		while(lo<=hi){
			int mid=(lo+hi)>>1;
			long long brp=t/setiap[mid];
			brp=brp*gerak[mid];
			long long di=brp-mid;
			if(di<=r){
				hi=mid-1;
				kanan=mid;
			}
			else lo=mid+1;
		}
		//debug(kanan);
		if(kanan==-1){
			puts("0");
			continue;
		}
		printf("%d\n",kiri-kanan+1);
	}
}



Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:29:20: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
  scanf("%d%d",&n,&q);
               ~~   ^
worst_reporter3.cpp:29:20: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
worst_reporter3.cpp:30:39: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
  for(int i=1;i<=n;i++)scanf("%d",&a[i]);
                                  ~~~~~^
worst_reporter3.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&q);
  ~~~~~^~~~~~~~~~~~~~
worst_reporter3.cpp:30:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++)scanf("%d",&a[i]);
                       ~~~~~^~~~~~~~~~~~
worst_reporter3.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld",&t,&l,&r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1086 ms 16432 KB Output is correct
2 Correct 1225 ms 16432 KB Output is correct
3 Correct 1182 ms 16584 KB Output is correct
4 Correct 1189 ms 16584 KB Output is correct
5 Correct 1383 ms 16584 KB Output is correct
6 Correct 1291 ms 16584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16584 KB Output is correct
2 Correct 3 ms 16584 KB Output is correct
3 Correct 3 ms 16584 KB Output is correct
4 Correct 3 ms 16584 KB Output is correct
5 Correct 4 ms 16584 KB Output is correct
6 Correct 4 ms 16584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1086 ms 16432 KB Output is correct
2 Correct 1225 ms 16432 KB Output is correct
3 Correct 1182 ms 16584 KB Output is correct
4 Correct 1189 ms 16584 KB Output is correct
5 Correct 1383 ms 16584 KB Output is correct
6 Correct 1291 ms 16584 KB Output is correct
7 Correct 3 ms 16584 KB Output is correct
8 Correct 3 ms 16584 KB Output is correct
9 Correct 3 ms 16584 KB Output is correct
10 Correct 3 ms 16584 KB Output is correct
11 Correct 4 ms 16584 KB Output is correct
12 Correct 4 ms 16584 KB Output is correct
13 Correct 635 ms 16584 KB Output is correct
14 Correct 691 ms 16584 KB Output is correct
15 Correct 596 ms 16584 KB Output is correct
16 Correct 642 ms 16584 KB Output is correct
17 Correct 757 ms 16584 KB Output is correct
18 Correct 882 ms 16584 KB Output is correct
19 Correct 870 ms 16584 KB Output is correct
20 Correct 972 ms 16584 KB Output is correct
21 Correct 1010 ms 16584 KB Output is correct
22 Correct 839 ms 34776 KB Output is correct
23 Correct 781 ms 53432 KB Output is correct
24 Correct 792 ms 72084 KB Output is correct
25 Correct 1236 ms 88144 KB Output is correct
26 Correct 1266 ms 103684 KB Output is correct
27 Correct 1016 ms 121064 KB Output is correct
28 Correct 1045 ms 139176 KB Output is correct
29 Correct 953 ms 156880 KB Output is correct
30 Correct 1029 ms 174864 KB Output is correct
31 Correct 931 ms 192976 KB Output is correct
32 Correct 987 ms 207200 KB Output is correct
33 Correct 3 ms 207200 KB Output is correct