Submission #220210

# Submission time Handle Problem Language Result Execution time Memory
220210 2020-04-07T10:34:07 Z patrikpavic2 Worst Reporter 3 (JOI18_worst_reporter3) C++17
100 / 100
582 ms 25648 KB
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;

const int N = 5e5  + 500;

ll D[N];
int n, q, nxt[N];

int kolko(ll T,ll L,ll R){
	ll tren = T;
	int ans = 0;
	for(int i = 0;i <= n;i = nxt[i]){
		ll R2 = tren * D[i] - i, L2 = tren * D[i] - nxt[i] + 1;
		if(max(L, L2) <= min(R, R2))
			ans += min(R, R2) - max(L, L2) + 1;
		if(nxt[i] <= n)
			tren = tren / (D[nxt[i]] / D[i]);
		if(!tren) 
			break;
	}
	return ans;
}

int main(){
	scanf("%d%d", &n, &q);
	D[0] = 1;
	for(int i = 1;i <= n;i++){
		scanf("%lld", D + i);
		if(D[i] < D[i - 1])
			D[i] = D[i - 1];
		else if(D[i] % D[i - 1])
			D[i] += D[i - 1] - D[i] % D[i - 1];
	}
	int lst = 0;
	for(int i = 1;i <= n;i++){
		if(D[i] != D[lst]){
			nxt[lst] = i;
			lst = i;
		}
	}
	nxt[lst] = n + 1;
	for(;q--;){
		ll A, B, C; scanf("%lld%lld%lld", &A, &B, &C);
		printf("%d\n", kolko(A, B, C));
	}
	return 0;
}

Compilation message

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:35: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:38: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:53:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   ll A, B, C; scanf("%lld%lld%lld", &A, &B, &C);
               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 364 ms 21624 KB Output is correct
2 Correct 374 ms 22752 KB Output is correct
3 Correct 372 ms 22688 KB Output is correct
4 Correct 368 ms 22776 KB Output is correct
5 Correct 367 ms 22648 KB Output is correct
6 Correct 378 ms 22904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 364 ms 21624 KB Output is correct
2 Correct 374 ms 22752 KB Output is correct
3 Correct 372 ms 22688 KB Output is correct
4 Correct 368 ms 22776 KB Output is correct
5 Correct 367 ms 22648 KB Output is correct
6 Correct 378 ms 22904 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 402 ms 21196 KB Output is correct
14 Correct 404 ms 21756 KB Output is correct
15 Correct 377 ms 20472 KB Output is correct
16 Correct 392 ms 21240 KB Output is correct
17 Correct 550 ms 25292 KB Output is correct
18 Correct 549 ms 25336 KB Output is correct
19 Correct 573 ms 25648 KB Output is correct
20 Correct 551 ms 25504 KB Output is correct
21 Correct 532 ms 25444 KB Output is correct
22 Correct 533 ms 25336 KB Output is correct
23 Correct 559 ms 25312 KB Output is correct
24 Correct 550 ms 25592 KB Output is correct
25 Correct 383 ms 22888 KB Output is correct
26 Correct 402 ms 22776 KB Output is correct
27 Correct 544 ms 24824 KB Output is correct
28 Correct 576 ms 25464 KB Output is correct
29 Correct 574 ms 24848 KB Output is correct
30 Correct 563 ms 25080 KB Output is correct
31 Correct 582 ms 25336 KB Output is correct
32 Correct 359 ms 21368 KB Output is correct
33 Correct 4 ms 256 KB Output is correct