Submission #528887

# Submission time Handle Problem Language Result Execution time Memory
528887 2022-02-21T16:39:43 Z LucaDantas Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
570 ms 31768 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

constexpr int maxn = 5e5+10;

int d[maxn], qtd[maxn];

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

	vector<int> st; st.push_back(0);
	for(int i = 1; i <= n; i++) {
		if(d[st.back()] < d[i])
			st.push_back(i);
	}

	qtd[0] = 1;
	for(int i = 1; i < st.size(); i++) {
		int last = st[i-1], aq = st[i];
		qtd[st[i]] = ((d[st[i]] + qtd[st[i-1]] - 1) / qtd[st[i-1]]) * qtd[st[i-1]];
	}

	for(int i = 1; i <= n; i++)
		if(!qtd[i]) qtd[i] = qtd[i-1];

	/* for(int i = 0; i <= n; i++)
		printf("%lld ", qtd[i]);
	puts(""); */

	for(int i = 0; i < q; i++) {
		int t, L, R; scanf("%lld %lld %lld", &t, &L, &R);

		// printf("\ntempo %lld\n", t);

		if(t < L) { puts("0"); continue; }

		int l = 0, r = n, GeqL = -1; // quero o primeiro cara maior ou igual a l
		while(l <= r) {
			int m = (l+r) >> 1;
			int pos = t - (t % qtd[m]) - m;
			if(pos >= L) GeqL = m, l = m+1;
			else r = m-1;
			// printf("%lld -> %lld\n", m, pos);
		}

		assert(GeqL != -1);

		if(t <= R) { printf("%lld\n", GeqL+1); continue; }

		l = 0, r = n;
		int GR = 0;
		while(l <= r) {
			int m = (l+r) >> 1;
			int pos = t - (t % qtd[m]) - m;
			if(pos > R) GR = m, l = m+1;
			else r = m-1;
			// printf("%lld -> %lld\n", m, pos);
		}

		assert(GR != -1);

		// printf("%lld %lld\n", GeqL, GR);
		printf("%lld\n", GeqL - GR);
	}
}

Compilation message

worst_reporter3.cpp: In function 'int32_t main()':
worst_reporter3.cpp:23:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for(int i = 1; i < st.size(); i++) {
      |                 ~~^~~~~~~~~~~
worst_reporter3.cpp:24:7: warning: unused variable 'last' [-Wunused-variable]
   24 |   int last = st[i-1], aq = st[i];
      |       ^~~~
worst_reporter3.cpp:24:23: warning: unused variable 'aq' [-Wunused-variable]
   24 |   int last = st[i-1], aq = st[i];
      |                       ^~
worst_reporter3.cpp:11:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  int n, q; scanf("%lld %lld", &n, &q);
      |            ~~~~~^~~~~~~~~~~~~~~~~~~~~
worst_reporter3.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%lld", d+i);
      |   ~~~~~^~~~~~~~~~~~~
worst_reporter3.cpp:36:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |   int t, L, R; scanf("%lld %lld %lld", &t, &L, &R);
      |                ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 525 ms 11052 KB Output is correct
2 Correct 514 ms 11112 KB Output is correct
3 Correct 570 ms 11020 KB Output is correct
4 Correct 521 ms 11068 KB Output is correct
5 Correct 541 ms 11072 KB Output is correct
6 Correct 535 ms 11028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 525 ms 11052 KB Output is correct
2 Correct 514 ms 11112 KB Output is correct
3 Correct 570 ms 11020 KB Output is correct
4 Correct 521 ms 11068 KB Output is correct
5 Correct 541 ms 11072 KB Output is correct
6 Correct 535 ms 11028 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 361 ms 19976 KB Output is correct
14 Correct 384 ms 25536 KB Output is correct
15 Correct 315 ms 24200 KB Output is correct
16 Correct 337 ms 24736 KB Output is correct
17 Correct 416 ms 25680 KB Output is correct
18 Correct 465 ms 30212 KB Output is correct
19 Correct 428 ms 28468 KB Output is correct
20 Correct 433 ms 25972 KB Output is correct
21 Correct 400 ms 30372 KB Output is correct
22 Correct 409 ms 24596 KB Output is correct
23 Correct 420 ms 31768 KB Output is correct
24 Correct 431 ms 24464 KB Output is correct
25 Correct 529 ms 26520 KB Output is correct
26 Correct 519 ms 26472 KB Output is correct
27 Correct 450 ms 28636 KB Output is correct
28 Correct 432 ms 28404 KB Output is correct
29 Correct 501 ms 28564 KB Output is correct
30 Correct 469 ms 28660 KB Output is correct
31 Correct 429 ms 28808 KB Output is correct
32 Correct 466 ms 25152 KB Output is correct
33 Correct 1 ms 204 KB Output is correct