Submission #627391

# Submission time Handle Problem Language Result Execution time Memory
627391 2022-08-12T14:17:46 Z MilosMilutinovic Worst Reporter 3 (JOI18_worst_reporter3) C++14
19 / 100
682 ms 20656 KB
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

int n, q, d[500005];
int calc(int i, int T)
{
	int coeff = T / d[i];
	return coeff * d[i] - i - 1;
}
int main()
{
	scanf("%d%d", &n, &q);
	rep(i, n) scanf("%d", &d[i]);
	rep(i, n) {
		if(i == 0) continue;
		d[i] = d[i - 1] * ((d[i] + d[i - 1] - 1) / d[i - 1]);
	}
	while(q--) {
		int T, L, R;
		scanf("%d%d%d", &T, &L, &R);
		int l = -1, r = -1;
		{
			int low = 0, high = n - 1;
			while(low <= high) {
				int mid = low + high >> 1;
				if(calc(mid, T) <= R) l = mid, high = mid - 1;
				else low = mid + 1;
			}
		}
		{
			int low = 0, high = n - 1;
			while(low <= high) {
				int mid = low + high >> 1;
				if(calc(mid, T) >= L) r = mid, low = mid + 1;
				else high = mid - 1;
			}
		}
		int ans;
		if(l == -1 || calc(l, T) > R) ans = 0;
		else ans = r - l + 1;
		if(L <= T && T <= R) ans ++;
		printf("%d\n", ans);
	}
	return 0;
}

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:31:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |     int mid = low + high >> 1;
      |               ~~~~^~~~~~
worst_reporter3.cpp:39:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |     int mid = low + high >> 1;
      |               ~~~~^~~~~~
worst_reporter3.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%d%d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~
worst_reporter3.cpp:19:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  rep(i, n) scanf("%d", &d[i]);
      |            ~~~~~^~~~~~~~~~~~~
worst_reporter3.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   scanf("%d%d%d", &T, &L, &R);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 579 ms 20588 KB Output is correct
2 Correct 655 ms 20624 KB Output is correct
3 Correct 682 ms 20612 KB Output is correct
4 Correct 578 ms 20656 KB Output is correct
5 Correct 580 ms 20580 KB Output is correct
6 Correct 562 ms 20636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 579 ms 20588 KB Output is correct
2 Correct 655 ms 20624 KB Output is correct
3 Correct 682 ms 20612 KB Output is correct
4 Correct 578 ms 20656 KB Output is correct
5 Correct 580 ms 20580 KB Output is correct
6 Correct 562 ms 20636 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Runtime error 61 ms 9336 KB Execution killed with signal 8
14 Halted 0 ms 0 KB -