Submission #847393

# Submission time Handle Problem Language Result Execution time Memory
847393 2023-09-09T15:16:14 Z qwerasdfzxcl Mizuyokan 2 (JOI23_mizuyokan2) C++17
60 / 100
4000 ms 27080 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr int INF1 = 1e9 + 100;

int n;
int a[250250];

int sp[250250][20];
ll S[250250];

void init(int n){
	for (int i=1;i<=n;i++) S[i] = S[i-1] + a[i];

	sp[n+1][0] = n+1;
	for (int i=1;i<=n;i++){
		sp[i][0] = n+1;
		for (int j=i+2;j<=min(i+200, n);j++) if (S[j-1] - S[i] > max(a[i], a[j])){
			sp[i][0] = j;
			break;
		}
	}

	for (int i=n;i;i--) sp[i][0] = min(sp[i][0], sp[i+1][0]);

	for (int j=1;j<20;j++){
		for (int i=1;i<=n+1;i++){
			sp[i][j] = sp[sp[i][j-1]][j-1];
		}
	}
}

int solve(int l, int r){
	if (r-l+1 < 3) return -INF1;
	int cnt = 0;
	for (int x=l,j=19;j>=0;j--) if (sp[x][j] <= r){
		x = sp[x][j];
		cnt |= 1<<j;
	}

	cnt = max(cnt-200, 0);
	for (int j=19;j>=0;j--) if (cnt&(1<<j)) l = sp[l][j];

	int cur = cnt*2, ret = -INF1;
	while(l<=r){
		if (l==r) ret = max(ret, cur+1);
		else if (r-l+1 >= 3 && S[r-1]-S[l] > max(a[l], a[r])) ret = max(ret, cur+3);
		else ret = max(ret, cur+1);

		l = sp[l][0];
		cur += 2;
	}

	return ret;
}

int query(int l, int r){
	int ret = 1;
	if (l==r) return ret;
	if (S[r-1]-S[l-1] > a[r]) ret = 2;
	if (S[r]-S[l] > a[l]) ret = 2;

	int nl = r+1, nr = l-1;
	for (int i=l+1;i<=min(l+200, r);i++) if (S[i-1]-S[l-1] > a[i]) {nl = i; break;}
	for (int i=r-1;i>=max(l, r-200);i--) if (S[r]-S[i] > a[i]) {nr = i; break;}
	if (nl <= nr) ret = 3;

	return max({ret, solve(l, r), solve(nl, r) + 1, solve(l, nr) + 1, solve(nl, nr) + 2});
}

void update(int x, int y){
	a[x] = y;
	init(n);
}

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

	init(n);

	int q;
	scanf("%d", &q);
	while(q--){
		int x, y, l, r;
		scanf("%d %d %d %d", &x, &y, &l, &r);
		
		if (a[x]!=y) update(x, y);

		l++;
		printf("%d\n", query(l, r));
	}
}

Compilation message

mizuyokan2.cpp: In function 'int main()':
mizuyokan2.cpp:79:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
mizuyokan2.cpp:80:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |  for (int i=1;i<=n;i++) scanf("%d", a+i);
      |                         ~~~~~^~~~~~~~~~~
mizuyokan2.cpp:85:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
mizuyokan2.cpp:88:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |   scanf("%d %d %d %d", &x, &y, &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2500 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 2 ms 2500 KB Output is correct
29 Correct 2 ms 2908 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2500 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 2 ms 2500 KB Output is correct
29 Correct 2 ms 2908 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 212 ms 24144 KB Output is correct
42 Correct 297 ms 25080 KB Output is correct
43 Correct 279 ms 24912 KB Output is correct
44 Correct 75 ms 19292 KB Output is correct
45 Correct 317 ms 25180 KB Output is correct
46 Correct 346 ms 24404 KB Output is correct
47 Correct 116 ms 19192 KB Output is correct
48 Correct 310 ms 24412 KB Output is correct
49 Correct 301 ms 24656 KB Output is correct
50 Correct 313 ms 24376 KB Output is correct
51 Correct 331 ms 24576 KB Output is correct
52 Correct 96 ms 21644 KB Output is correct
53 Correct 297 ms 25348 KB Output is correct
54 Correct 323 ms 24300 KB Output is correct
55 Correct 240 ms 24300 KB Output is correct
56 Correct 317 ms 24296 KB Output is correct
57 Correct 288 ms 24148 KB Output is correct
58 Correct 311 ms 24404 KB Output is correct
59 Correct 173 ms 25180 KB Output is correct
60 Correct 152 ms 25168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 96 ms 17760 KB Output is correct
3 Correct 217 ms 26452 KB Output is correct
4 Correct 255 ms 26376 KB Output is correct
5 Correct 239 ms 26708 KB Output is correct
6 Correct 343 ms 25804 KB Output is correct
7 Correct 362 ms 26492 KB Output is correct
8 Correct 355 ms 25940 KB Output is correct
9 Correct 363 ms 25860 KB Output is correct
10 Correct 314 ms 23172 KB Output is correct
11 Correct 425 ms 27080 KB Output is correct
12 Correct 484 ms 25584 KB Output is correct
13 Correct 284 ms 25720 KB Output is correct
14 Correct 516 ms 25652 KB Output is correct
15 Correct 390 ms 25680 KB Output is correct
16 Correct 552 ms 25748 KB Output is correct
17 Correct 153 ms 26704 KB Output is correct
18 Correct 237 ms 26968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Execution timed out 4038 ms 21852 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2500 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 2 ms 2500 KB Output is correct
29 Correct 2 ms 2908 KB Output is correct
30 Correct 2 ms 2396 KB Output is correct
31 Correct 2 ms 2396 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 1 ms 2396 KB Output is correct
35 Correct 1 ms 2392 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 1 ms 2396 KB Output is correct
39 Correct 1 ms 2396 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 212 ms 24144 KB Output is correct
42 Correct 297 ms 25080 KB Output is correct
43 Correct 279 ms 24912 KB Output is correct
44 Correct 75 ms 19292 KB Output is correct
45 Correct 317 ms 25180 KB Output is correct
46 Correct 346 ms 24404 KB Output is correct
47 Correct 116 ms 19192 KB Output is correct
48 Correct 310 ms 24412 KB Output is correct
49 Correct 301 ms 24656 KB Output is correct
50 Correct 313 ms 24376 KB Output is correct
51 Correct 331 ms 24576 KB Output is correct
52 Correct 96 ms 21644 KB Output is correct
53 Correct 297 ms 25348 KB Output is correct
54 Correct 323 ms 24300 KB Output is correct
55 Correct 240 ms 24300 KB Output is correct
56 Correct 317 ms 24296 KB Output is correct
57 Correct 288 ms 24148 KB Output is correct
58 Correct 311 ms 24404 KB Output is correct
59 Correct 173 ms 25180 KB Output is correct
60 Correct 152 ms 25168 KB Output is correct
61 Correct 0 ms 2396 KB Output is correct
62 Correct 96 ms 17760 KB Output is correct
63 Correct 217 ms 26452 KB Output is correct
64 Correct 255 ms 26376 KB Output is correct
65 Correct 239 ms 26708 KB Output is correct
66 Correct 343 ms 25804 KB Output is correct
67 Correct 362 ms 26492 KB Output is correct
68 Correct 355 ms 25940 KB Output is correct
69 Correct 363 ms 25860 KB Output is correct
70 Correct 314 ms 23172 KB Output is correct
71 Correct 425 ms 27080 KB Output is correct
72 Correct 484 ms 25584 KB Output is correct
73 Correct 284 ms 25720 KB Output is correct
74 Correct 516 ms 25652 KB Output is correct
75 Correct 390 ms 25680 KB Output is correct
76 Correct 552 ms 25748 KB Output is correct
77 Correct 153 ms 26704 KB Output is correct
78 Correct 237 ms 26968 KB Output is correct
79 Correct 1 ms 2392 KB Output is correct
80 Correct 1 ms 2392 KB Output is correct
81 Execution timed out 4038 ms 21852 KB Time limit exceeded
82 Halted 0 ms 0 KB -