답안 #242212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242212 2020-06-27T06:05:58 Z jamielim Worst Reporter 3 (JOI18_worst_reporter3) C++14
100 / 100
723 ms 11384 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007; //998244353; //
const ld PI=3.1415926535898;
const ld EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

int n,q;
ll d[500005],c[500005];

ll dist(ll t,int x){
	return (t/c[x])*c[x]-x;
}

int main(){
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)scanf("%lld",&d[i]);
	d[0]=c[0]=1;
	for(int i=1;i<=n;i++){
		c[i]=ceil((double)(d[i])/(double)(c[i-1]))*c[i-1];
	}
	//period of entire thing is c[n]
	ll t,l,r;
	for(int i=0;i<q;i++){
		scanf("%lld%lld%lld",&t,&l,&r);
		if(dist(t,0)<l||dist(t,n)>r){printf("0\n");continue;}
		//for(int j=0;j<=n;j++)printf("%lld ",dist(t,j));
		int bl=0,br=n;
		while(bl<br){
			int m=(bl+br)/2;
			//printf("%d %d %d %lld %lld\n",bl,m,br,dist(t,m),r);
			if(dist(t,m)<=r)br=m;
			else bl=m+1;
		}
		int right=bl;
		bl=0;br=n;
		while(bl<br){
			int m=(bl+br+1)/2;
			if(dist(t,m)>=l)bl=m;
			else br=m-1;
		}
		int left=bl;
		//printf("%d %d\n",left,right);
		printf("%d\n",left-right+1);
	}
}

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:31: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:32: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("%lld",&d[i]);
                       ~~~~~^~~~~~~~~~~~~~
worst_reporter3.cpp:40: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 702 ms 11256 KB Output is correct
2 Correct 722 ms 11128 KB Output is correct
3 Correct 714 ms 11336 KB Output is correct
4 Correct 722 ms 11256 KB Output is correct
5 Correct 713 ms 11256 KB Output is correct
6 Correct 716 ms 11384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 702 ms 11256 KB Output is correct
2 Correct 722 ms 11128 KB Output is correct
3 Correct 714 ms 11336 KB Output is correct
4 Correct 722 ms 11256 KB Output is correct
5 Correct 713 ms 11256 KB Output is correct
6 Correct 716 ms 11384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 484 ms 9336 KB Output is correct
14 Correct 492 ms 9208 KB Output is correct
15 Correct 461 ms 9184 KB Output is correct
16 Correct 472 ms 9336 KB Output is correct
17 Correct 584 ms 10592 KB Output is correct
18 Correct 576 ms 10744 KB Output is correct
19 Correct 574 ms 10488 KB Output is correct
20 Correct 597 ms 10744 KB Output is correct
21 Correct 578 ms 10616 KB Output is correct
22 Correct 581 ms 10744 KB Output is correct
23 Correct 588 ms 10744 KB Output is correct
24 Correct 577 ms 10616 KB Output is correct
25 Correct 710 ms 11256 KB Output is correct
26 Correct 723 ms 11336 KB Output is correct
27 Correct 631 ms 11128 KB Output is correct
28 Correct 603 ms 10876 KB Output is correct
29 Correct 621 ms 11000 KB Output is correct
30 Correct 630 ms 11128 KB Output is correct
31 Correct 622 ms 11000 KB Output is correct
32 Correct 561 ms 10744 KB Output is correct
33 Correct 4 ms 384 KB Output is correct