Submission #44053

# Submission time Handle Problem Language Result Execution time Memory
44053 2018-03-29T13:02:45 Z zadrga Worst Reporter 3 (JOI18_worst_reporter3) C++14
100 / 100
1054 ms 11556 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 500111

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll d[maxn], f[maxn];

ll CEIL(ll a, ll b){
	return (a + b - 1) / b;
}

ll find(ll t, ll mid){
	if(mid == 0){
		return -1234;
	}

	ll x = f[mid];
	ll cnt = t / x;
	ll pos = cnt * x - mid;
	//cout << t << " " << mid << ":  " << pos << endl;
	return pos;
}

int main(){
	int n, q;
	scanf("%d%d", &n, &q);
	for(int i = 1; i <= n; i++)
		scanf("%lld", d + i);

	f[1] = d[1];
	for(int i = 2; i <= n; i++)
		f[i] = f[i - 1] * CEIL(d[i], f[i - 1]);

	while(q--){
		ll t, i, j;
		scanf("%lld%lld%lld", &t, &i, &j);

		ll dod = 0;
		if(i <= t && t <= j)
			dod = 1;

		ll l = 1, d = n, mid, ans1 = 0, ans2 = 0;
		while(l <= d){
			mid = (l + d) / 2;
			ll pos = find(t, mid);
			if(pos >= i){
				l = mid + 1;
				ans1 = mid; 
			}
			else
				d = mid - 1;
		}

		l = 1; d = n;
		while(l <= d){
			mid = (l + d) / 2;
			ll pos = find(t, mid);
			if(pos <= j){
				d = mid - 1;
				ans2 = mid; 
			}
			else
				l = mid + 1;
		}

	//	cout << ans1 << "   " << find(t, ans1) << " |||| " << ans2 << "  " << find(t, ans2) << endl;

		ll all = 0;
		if(find(t, ans2) < i || find(t, ans1) > j || ans1 < ans2)
			all = 0;
		else
			all = ans1 - ans2 + 1;

		printf("%lld\n", all + dod);
	} 
	return 0;
}

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:37: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:39: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:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &t, &i, &j);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 952 ms 11256 KB Output is correct
2 Correct 953 ms 11288 KB Output is correct
3 Correct 1054 ms 11288 KB Output is correct
4 Correct 954 ms 11288 KB Output is correct
5 Correct 961 ms 11364 KB Output is correct
6 Correct 1012 ms 11364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 11364 KB Output is correct
2 Correct 3 ms 11364 KB Output is correct
3 Correct 3 ms 11364 KB Output is correct
4 Correct 3 ms 11364 KB Output is correct
5 Correct 3 ms 11364 KB Output is correct
6 Correct 3 ms 11364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 952 ms 11256 KB Output is correct
2 Correct 953 ms 11288 KB Output is correct
3 Correct 1054 ms 11288 KB Output is correct
4 Correct 954 ms 11288 KB Output is correct
5 Correct 961 ms 11364 KB Output is correct
6 Correct 1012 ms 11364 KB Output is correct
7 Correct 3 ms 11364 KB Output is correct
8 Correct 3 ms 11364 KB Output is correct
9 Correct 3 ms 11364 KB Output is correct
10 Correct 3 ms 11364 KB Output is correct
11 Correct 3 ms 11364 KB Output is correct
12 Correct 3 ms 11364 KB Output is correct
13 Correct 637 ms 11364 KB Output is correct
14 Correct 651 ms 11364 KB Output is correct
15 Correct 612 ms 11364 KB Output is correct
16 Correct 637 ms 11364 KB Output is correct
17 Correct 777 ms 11364 KB Output is correct
18 Correct 792 ms 11364 KB Output is correct
19 Correct 806 ms 11364 KB Output is correct
20 Correct 929 ms 11364 KB Output is correct
21 Correct 909 ms 11364 KB Output is correct
22 Correct 786 ms 11364 KB Output is correct
23 Correct 801 ms 11364 KB Output is correct
24 Correct 792 ms 11364 KB Output is correct
25 Correct 1008 ms 11556 KB Output is correct
26 Correct 984 ms 11556 KB Output is correct
27 Correct 894 ms 11556 KB Output is correct
28 Correct 828 ms 11556 KB Output is correct
29 Correct 870 ms 11556 KB Output is correct
30 Correct 900 ms 11556 KB Output is correct
31 Correct 815 ms 11556 KB Output is correct
32 Correct 747 ms 11556 KB Output is correct
33 Correct 2 ms 11556 KB Output is correct