답안 #781195

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781195 2023-07-12T22:27:58 Z AdamGS Mizuyokan 2 (JOI23_mizuyokan2) C++17
28 / 100
4000 ms 27332 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e9+7;
const int LIM=25e4+7;
int tr[4*LIM], dp[LIM], N=1;
vector<int>V[LIM];
ll sum[LIM];
ll cnt(int l, int r) {
	return sum[r]-(l?sum[l-1]:0);
}
void upd(int v, int x) {
	v+=N;
	while(v) {
		tr[v]=max(tr[v], x);
		v/=2;
	}
}
int cnt2(int l, int r) {
	if(l>r) return -INF;
	l+=N; r+=N;
	int ans=max(tr[l], tr[r]);
	while(l/2!=r/2) {
		if(l%2==0) ans=max(ans, tr[l+1]);
		if(r%2==1) ans=max(ans, tr[r-1]);
		l/=2; r/=2;
	}
	return ans;
}
int solve(vector<ll>T) {
	int n=T.size();
	rep(i, n+1) V[i].clear();
	rep(i, n) {
		sum[i]=T[i];
		if(i) sum[i]+=sum[i-1];
		dp[i]=-INF;
	}
	N=1;
	while(N<n) N*=2;
	rep(i, 2*N) tr[i]=-INF;
	rep(i, n) {
		for(auto j : V[i]) upd(j, dp[j]);
		if(i==0) dp[i]=1;
		else if(cnt(0, i-1)>T[i]) {
			dp[i]=2;
			int po=0, ko=i-1;
			while(po<ko) {
				int sr=(po+ko+1)/2;
				if(cnt(sr, i-1)>T[i]) po=sr; else ko=sr-1;
			}
			dp[i]=max(dp[i], cnt2(0, po-1)+2);
		}
		if(cnt(i+1, n-1)>T[i]) {
			int po=i+1, ko=n-1;
			while(po<ko) {
				int sr=(po+ko)/2;
				if(cnt(i+1, sr)>T[i]) ko=sr; else po=sr+1;
			}
			V[po+1].pb(i);
		}
	}
	int ans=max(1, dp[n-1]);
	rep(i, n-1) if(cnt(i+1, n-1)>T[i]) ans=max(ans, dp[i]+1);
	return ans;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	vector<ll>T(n);
	rep(i, n) cin >> T[i];
	int q;
	cin >> q;
	while(q--) {
		ll x, y, a, b;
		cin >> x >> y >> a >> b; --x; --b;
		T[x]=y;
		vector<ll>P;
		while(a<=b) {
			P.pb(T[a]);
			++a;
		}
		cout << solve(P) << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 4 ms 6100 KB Output is correct
4 Correct 3 ms 6228 KB Output is correct
5 Correct 3 ms 6100 KB Output is correct
6 Correct 3 ms 6100 KB Output is correct
7 Correct 3 ms 6100 KB Output is correct
8 Correct 3 ms 6100 KB Output is correct
9 Correct 3 ms 6228 KB Output is correct
10 Correct 3 ms 6100 KB Output is correct
11 Correct 3 ms 6124 KB Output is correct
12 Correct 3 ms 6100 KB Output is correct
13 Correct 3 ms 6100 KB Output is correct
14 Correct 3 ms 6228 KB Output is correct
15 Correct 3 ms 6100 KB Output is correct
16 Correct 4 ms 6220 KB Output is correct
17 Correct 4 ms 6228 KB Output is correct
18 Correct 3 ms 6228 KB Output is correct
19 Correct 3 ms 6228 KB Output is correct
20 Correct 3 ms 6100 KB Output is correct
21 Correct 3 ms 6100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 4 ms 6100 KB Output is correct
4 Correct 3 ms 6228 KB Output is correct
5 Correct 3 ms 6100 KB Output is correct
6 Correct 3 ms 6100 KB Output is correct
7 Correct 3 ms 6100 KB Output is correct
8 Correct 3 ms 6100 KB Output is correct
9 Correct 3 ms 6228 KB Output is correct
10 Correct 3 ms 6100 KB Output is correct
11 Correct 3 ms 6124 KB Output is correct
12 Correct 3 ms 6100 KB Output is correct
13 Correct 3 ms 6100 KB Output is correct
14 Correct 3 ms 6228 KB Output is correct
15 Correct 3 ms 6100 KB Output is correct
16 Correct 4 ms 6220 KB Output is correct
17 Correct 4 ms 6228 KB Output is correct
18 Correct 3 ms 6228 KB Output is correct
19 Correct 3 ms 6228 KB Output is correct
20 Correct 3 ms 6100 KB Output is correct
21 Correct 3 ms 6100 KB Output is correct
22 Correct 3 ms 6228 KB Output is correct
23 Correct 3 ms 6228 KB Output is correct
24 Correct 3 ms 6228 KB Output is correct
25 Correct 4 ms 6228 KB Output is correct
26 Correct 4 ms 6356 KB Output is correct
27 Correct 4 ms 6360 KB Output is correct
28 Correct 4 ms 6228 KB Output is correct
29 Correct 4 ms 6228 KB Output is correct
30 Correct 4 ms 6328 KB Output is correct
31 Correct 4 ms 6336 KB Output is correct
32 Correct 4 ms 6228 KB Output is correct
33 Correct 4 ms 6228 KB Output is correct
34 Correct 4 ms 6228 KB Output is correct
35 Correct 4 ms 6356 KB Output is correct
36 Correct 4 ms 6228 KB Output is correct
37 Correct 4 ms 6340 KB Output is correct
38 Correct 4 ms 6228 KB Output is correct
39 Correct 3 ms 6228 KB Output is correct
40 Correct 3 ms 6228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 4 ms 6100 KB Output is correct
4 Correct 3 ms 6228 KB Output is correct
5 Correct 3 ms 6100 KB Output is correct
6 Correct 3 ms 6100 KB Output is correct
7 Correct 3 ms 6100 KB Output is correct
8 Correct 3 ms 6100 KB Output is correct
9 Correct 3 ms 6228 KB Output is correct
10 Correct 3 ms 6100 KB Output is correct
11 Correct 3 ms 6124 KB Output is correct
12 Correct 3 ms 6100 KB Output is correct
13 Correct 3 ms 6100 KB Output is correct
14 Correct 3 ms 6228 KB Output is correct
15 Correct 3 ms 6100 KB Output is correct
16 Correct 4 ms 6220 KB Output is correct
17 Correct 4 ms 6228 KB Output is correct
18 Correct 3 ms 6228 KB Output is correct
19 Correct 3 ms 6228 KB Output is correct
20 Correct 3 ms 6100 KB Output is correct
21 Correct 3 ms 6100 KB Output is correct
22 Correct 3 ms 6228 KB Output is correct
23 Correct 3 ms 6228 KB Output is correct
24 Correct 3 ms 6228 KB Output is correct
25 Correct 4 ms 6228 KB Output is correct
26 Correct 4 ms 6356 KB Output is correct
27 Correct 4 ms 6360 KB Output is correct
28 Correct 4 ms 6228 KB Output is correct
29 Correct 4 ms 6228 KB Output is correct
30 Correct 4 ms 6328 KB Output is correct
31 Correct 4 ms 6336 KB Output is correct
32 Correct 4 ms 6228 KB Output is correct
33 Correct 4 ms 6228 KB Output is correct
34 Correct 4 ms 6228 KB Output is correct
35 Correct 4 ms 6356 KB Output is correct
36 Correct 4 ms 6228 KB Output is correct
37 Correct 4 ms 6340 KB Output is correct
38 Correct 4 ms 6228 KB Output is correct
39 Correct 3 ms 6228 KB Output is correct
40 Correct 3 ms 6228 KB Output is correct
41 Correct 19 ms 7908 KB Output is correct
42 Correct 21 ms 8148 KB Output is correct
43 Correct 24 ms 8404 KB Output is correct
44 Correct 25 ms 10232 KB Output is correct
45 Correct 77 ms 17352 KB Output is correct
46 Correct 236 ms 24072 KB Output is correct
47 Correct 175 ms 20788 KB Output is correct
48 Correct 282 ms 26224 KB Output is correct
49 Correct 338 ms 27332 KB Output is correct
50 Correct 222 ms 23772 KB Output is correct
51 Correct 211 ms 24584 KB Output is correct
52 Correct 134 ms 20792 KB Output is correct
53 Correct 290 ms 25412 KB Output is correct
54 Correct 269 ms 23676 KB Output is correct
55 Correct 226 ms 26092 KB Output is correct
56 Correct 209 ms 21032 KB Output is correct
57 Correct 126 ms 17076 KB Output is correct
58 Correct 213 ms 24136 KB Output is correct
59 Correct 74 ms 19012 KB Output is correct
60 Correct 93 ms 17208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 266 ms 7828 KB Output is correct
3 Correct 1628 ms 8472 KB Output is correct
4 Execution timed out 4083 ms 8960 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 255 ms 8184 KB Output is correct
4 Correct 1648 ms 8464 KB Output is correct
5 Execution timed out 4049 ms 23100 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6100 KB Output is correct
2 Correct 3 ms 6100 KB Output is correct
3 Correct 4 ms 6100 KB Output is correct
4 Correct 3 ms 6228 KB Output is correct
5 Correct 3 ms 6100 KB Output is correct
6 Correct 3 ms 6100 KB Output is correct
7 Correct 3 ms 6100 KB Output is correct
8 Correct 3 ms 6100 KB Output is correct
9 Correct 3 ms 6228 KB Output is correct
10 Correct 3 ms 6100 KB Output is correct
11 Correct 3 ms 6124 KB Output is correct
12 Correct 3 ms 6100 KB Output is correct
13 Correct 3 ms 6100 KB Output is correct
14 Correct 3 ms 6228 KB Output is correct
15 Correct 3 ms 6100 KB Output is correct
16 Correct 4 ms 6220 KB Output is correct
17 Correct 4 ms 6228 KB Output is correct
18 Correct 3 ms 6228 KB Output is correct
19 Correct 3 ms 6228 KB Output is correct
20 Correct 3 ms 6100 KB Output is correct
21 Correct 3 ms 6100 KB Output is correct
22 Correct 3 ms 6228 KB Output is correct
23 Correct 3 ms 6228 KB Output is correct
24 Correct 3 ms 6228 KB Output is correct
25 Correct 4 ms 6228 KB Output is correct
26 Correct 4 ms 6356 KB Output is correct
27 Correct 4 ms 6360 KB Output is correct
28 Correct 4 ms 6228 KB Output is correct
29 Correct 4 ms 6228 KB Output is correct
30 Correct 4 ms 6328 KB Output is correct
31 Correct 4 ms 6336 KB Output is correct
32 Correct 4 ms 6228 KB Output is correct
33 Correct 4 ms 6228 KB Output is correct
34 Correct 4 ms 6228 KB Output is correct
35 Correct 4 ms 6356 KB Output is correct
36 Correct 4 ms 6228 KB Output is correct
37 Correct 4 ms 6340 KB Output is correct
38 Correct 4 ms 6228 KB Output is correct
39 Correct 3 ms 6228 KB Output is correct
40 Correct 3 ms 6228 KB Output is correct
41 Correct 19 ms 7908 KB Output is correct
42 Correct 21 ms 8148 KB Output is correct
43 Correct 24 ms 8404 KB Output is correct
44 Correct 25 ms 10232 KB Output is correct
45 Correct 77 ms 17352 KB Output is correct
46 Correct 236 ms 24072 KB Output is correct
47 Correct 175 ms 20788 KB Output is correct
48 Correct 282 ms 26224 KB Output is correct
49 Correct 338 ms 27332 KB Output is correct
50 Correct 222 ms 23772 KB Output is correct
51 Correct 211 ms 24584 KB Output is correct
52 Correct 134 ms 20792 KB Output is correct
53 Correct 290 ms 25412 KB Output is correct
54 Correct 269 ms 23676 KB Output is correct
55 Correct 226 ms 26092 KB Output is correct
56 Correct 209 ms 21032 KB Output is correct
57 Correct 126 ms 17076 KB Output is correct
58 Correct 213 ms 24136 KB Output is correct
59 Correct 74 ms 19012 KB Output is correct
60 Correct 93 ms 17208 KB Output is correct
61 Correct 3 ms 6100 KB Output is correct
62 Correct 266 ms 7828 KB Output is correct
63 Correct 1628 ms 8472 KB Output is correct
64 Execution timed out 4083 ms 8960 KB Time limit exceeded
65 Halted 0 ms 0 KB -