Submission #200465

# Submission time Handle Problem Language Result Execution time Memory
200465 2020-02-06T22:56:57 Z Nucleist Worst Reporter 3 (JOI18_worst_reporter3) C++14
100 / 100
695 ms 29656 KB
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
ll dist[500011];
int main()
{
    flash;
	ll n,q;
	cin>>n>>q;
	ve fat;
	for (ll i = 0; i < n; ++i)
	{
		ll yo;
		cin>>yo;
		fat.pb(yo);
	}
	dist[0]=fat[0];
	for (ll i = 1; i < fat.size(); ++i)
	{
		ll k = dist[i-1];
		ll yo = (fat[i]-1)/k;
		yo++;
		ll b = yo*k;
		dist[i]=b;
	}
	while(q--)
	{
		ll t,l,r;
		cin>>t>>l>>r;
		ll low = 0,high=n-1;
		ll lowest=-1,highest=-1;
		ll ans=0;
		if(t>=l && t<=r)ans++;
		while(low<=high)
		{
			ll mid = (low+high)/2;
			//debug(mid);
			ll si = (t/dist[n-mid-1])*dist[n-mid-1];
			ll nowi = si-(n-mid);

			if(nowi>=l)
			{
				if(nowi<=r)
				{
					lowest=n-mid-1;
				}
				high=mid-1;
			}
			else
			{
				low=mid+1;
			}
		}
		low = 0;high=n-1;
		while(low<=high)
		{
			ll mid = (low+high)/2;
			ll si = (t/dist[n-mid-1])*dist[n-mid-1];
			ll nowi = si-(n-mid);
			//debugs(mid,nowi);
			if(nowi<=r)
			{
				if(nowi>=l)
				{
					highest=n-mid-1;
				}
				low=mid+1;
			}
			else
			{
				high=mid-1;
			}
		}
		//debugs(lowest,highest);
		if(highest!=-1)ans+=(lowest-highest+1);
		cout<<ans<<'\n';
	}
  return 0;
}
//code the AC sol !
// BS/queue/map

Compilation message

worst_reporter3.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
worst_reporter3.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:38:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (ll i = 1; i < fat.size(); ++i)
                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 675 ms 26820 KB Output is correct
2 Correct 695 ms 26844 KB Output is correct
3 Correct 670 ms 26800 KB Output is correct
4 Correct 668 ms 26820 KB Output is correct
5 Correct 676 ms 26868 KB Output is correct
6 Correct 669 ms 26724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 248 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 675 ms 26820 KB Output is correct
2 Correct 695 ms 26844 KB Output is correct
3 Correct 670 ms 26800 KB Output is correct
4 Correct 668 ms 26820 KB Output is correct
5 Correct 676 ms 26868 KB Output is correct
6 Correct 669 ms 26724 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 248 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 418 ms 25272 KB Output is correct
14 Correct 429 ms 25948 KB Output is correct
15 Correct 413 ms 24540 KB Output is correct
16 Correct 405 ms 25184 KB Output is correct
17 Correct 534 ms 29408 KB Output is correct
18 Correct 552 ms 29440 KB Output is correct
19 Correct 531 ms 29536 KB Output is correct
20 Correct 527 ms 29656 KB Output is correct
21 Correct 549 ms 29416 KB Output is correct
22 Correct 536 ms 29424 KB Output is correct
23 Correct 530 ms 29440 KB Output is correct
24 Correct 545 ms 29608 KB Output is correct
25 Correct 669 ms 26792 KB Output is correct
26 Correct 672 ms 26924 KB Output is correct
27 Correct 608 ms 28964 KB Output is correct
28 Correct 565 ms 29388 KB Output is correct
29 Correct 568 ms 28908 KB Output is correct
30 Correct 579 ms 29000 KB Output is correct
31 Correct 585 ms 29196 KB Output is correct
32 Correct 583 ms 25536 KB Output is correct
33 Correct 7 ms 376 KB Output is correct