답안 #847374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
847374 2023-09-09T14:34:46 Z qwerasdfzxcl Mizuyokan 2 (JOI23_mizuyokan2) C++17
0 / 100
4000 ms 22044 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+100, n);j++) if (S[j-1] - S[i] > max(a[i], a[j])){
			sp[i][0] = j;
			break;
		}
	}

	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 ret = 1;
	for (int j=19;j>=0;j--) if (sp[l][j] <= r){
		l = sp[l][j];
		ret += 1<<(j+1);
	}

	if (l!=r) return -INF1;
	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+40, r);i++) if (S[i-1]-S[l-1] > a[i]) {nl = i; break;}
	for (int i=r-1;i>=max(l, r-40);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(nr, l) + 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:65:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
mizuyokan2.cpp:66:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |  for (int i=1;i<=n;i++) scanf("%d", a+i);
      |                         ~~~~~^~~~~~~~~~~
mizuyokan2.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
mizuyokan2.cpp:74:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |   scanf("%d %d %d %d", &x, &y, &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Incorrect 52 ms 17756 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Execution timed out 4003 ms 22044 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 1 ms 2396 KB Output isn't correct
4 Halted 0 ms 0 KB -