답안 #1024860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024860 2024-07-16T11:16:52 Z Unforgettablepl Fish 2 (JOI22_fish2) C++17
25 / 100
4000 ms 5320 KB
// #pragma GCC optimize("Ofast","unroll-loops")
#include <bits/stdc++.h>
using namespace std;
 
// #define int long long
 
const int INF = INT32_MAX;
 
 
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<long long> arr(n+1);
	for(int i=1;i<=n;i++)cin>>arr[i];
	vector<pair<int,int>> connection(n+1);
	vector<int> left(n+1),right(n+1);
	vector<long long> pref(n+2);
	vector<pair<int,int>> adj(n+1);
	auto solve = [&](int l,int r){
		pref[l-1]=0;
		for(int i=l;i<=r;i++){
			pref[i]=pref[i-1]+arr[i];
			adj[i].first=adj[i].second=0;
		}
		stack<pair<int,int>> s;
		s.emplace(INF,l-1);
		for(int i=l;i<=r;i++){
			while(s.top().first<=arr[i])s.pop();
			connection[i]=s.top();
			left[i]=s.top().second;
			s.emplace(arr[i],i);
		}
		while(!s.empty())s.pop();
		s.emplace(INF,r+1);
		for(int i=r;i>=l;i--){
			while(s.top().first<arr[i])s.pop();
			connection[i]=min(s.top(),connection[i]);
			right[i]=s.top().second;
			s.emplace(arr[i],i);
		}
		for(int i=l;i<=r;i++){
			if(connection[i].second<i)adj[connection[i].second].second=i;
			else adj[connection[i].second].first=i;		
		}
		int ans = 0;
		function<void(int,int)> dfs = [&](int x,int threshold){
			if(pref[right[x]-1]-pref[left[x]]<threshold)return;
			ans++;
			if(adj[x].first)dfs(adj[x].first,arr[x]);
			if(adj[x].second)dfs(adj[x].second,arr[x]);
		};
		dfs(adj[l-1].second,0);
		return ans;
	};
	int q;
	cin >> q;
	for(int i=1;i<=q;i++){
		int type;cin>>type;
		if(type==1){
			int x,y;cin>>x>>y;
			arr[x]=y;
		} else {
			int l,r;cin>>l>>r;
			cout << solve(l,r) << '\n';
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 8 ms 4188 KB Output is correct
3 Correct 7 ms 4296 KB Output is correct
4 Correct 8 ms 4184 KB Output is correct
5 Correct 7 ms 4188 KB Output is correct
6 Correct 12 ms 4324 KB Output is correct
7 Correct 8 ms 4184 KB Output is correct
8 Correct 12 ms 4188 KB Output is correct
9 Correct 8 ms 4388 KB Output is correct
10 Correct 13 ms 4444 KB Output is correct
11 Correct 7 ms 4184 KB Output is correct
12 Correct 9 ms 4188 KB Output is correct
13 Correct 9 ms 4320 KB Output is correct
14 Correct 10 ms 4580 KB Output is correct
15 Correct 11 ms 4668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 8 ms 4188 KB Output is correct
23 Correct 7 ms 4296 KB Output is correct
24 Correct 8 ms 4184 KB Output is correct
25 Correct 7 ms 4188 KB Output is correct
26 Correct 12 ms 4324 KB Output is correct
27 Correct 8 ms 4184 KB Output is correct
28 Correct 12 ms 4188 KB Output is correct
29 Correct 8 ms 4388 KB Output is correct
30 Correct 13 ms 4444 KB Output is correct
31 Correct 7 ms 4184 KB Output is correct
32 Correct 9 ms 4188 KB Output is correct
33 Correct 9 ms 4320 KB Output is correct
34 Correct 10 ms 4580 KB Output is correct
35 Correct 11 ms 4668 KB Output is correct
36 Correct 254 ms 4444 KB Output is correct
37 Correct 416 ms 4188 KB Output is correct
38 Correct 473 ms 4372 KB Output is correct
39 Correct 105 ms 4444 KB Output is correct
40 Correct 510 ms 4188 KB Output is correct
41 Correct 1002 ms 4388 KB Output is correct
42 Correct 1291 ms 4188 KB Output is correct
43 Correct 721 ms 4184 KB Output is correct
44 Correct 854 ms 4184 KB Output is correct
45 Correct 285 ms 4316 KB Output is correct
46 Correct 421 ms 4188 KB Output is correct
47 Correct 536 ms 4188 KB Output is correct
48 Correct 288 ms 4188 KB Output is correct
49 Correct 986 ms 4440 KB Output is correct
50 Correct 525 ms 4948 KB Output is correct
51 Correct 2431 ms 4948 KB Output is correct
52 Correct 2552 ms 5320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 8 ms 4188 KB Output is correct
3 Correct 7 ms 4296 KB Output is correct
4 Correct 8 ms 4184 KB Output is correct
5 Correct 7 ms 4188 KB Output is correct
6 Correct 12 ms 4324 KB Output is correct
7 Correct 8 ms 4184 KB Output is correct
8 Correct 12 ms 4188 KB Output is correct
9 Correct 8 ms 4388 KB Output is correct
10 Correct 13 ms 4444 KB Output is correct
11 Correct 7 ms 4184 KB Output is correct
12 Correct 9 ms 4188 KB Output is correct
13 Correct 9 ms 4320 KB Output is correct
14 Correct 10 ms 4580 KB Output is correct
15 Correct 11 ms 4668 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Execution timed out 4090 ms 4396 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 8 ms 4188 KB Output is correct
3 Correct 7 ms 4296 KB Output is correct
4 Correct 8 ms 4184 KB Output is correct
5 Correct 7 ms 4188 KB Output is correct
6 Correct 12 ms 4324 KB Output is correct
7 Correct 8 ms 4184 KB Output is correct
8 Correct 12 ms 4188 KB Output is correct
9 Correct 8 ms 4388 KB Output is correct
10 Correct 13 ms 4444 KB Output is correct
11 Correct 7 ms 4184 KB Output is correct
12 Correct 9 ms 4188 KB Output is correct
13 Correct 9 ms 4320 KB Output is correct
14 Correct 10 ms 4580 KB Output is correct
15 Correct 11 ms 4668 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Execution timed out 4022 ms 4368 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 3 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 8 ms 4188 KB Output is correct
23 Correct 7 ms 4296 KB Output is correct
24 Correct 8 ms 4184 KB Output is correct
25 Correct 7 ms 4188 KB Output is correct
26 Correct 12 ms 4324 KB Output is correct
27 Correct 8 ms 4184 KB Output is correct
28 Correct 12 ms 4188 KB Output is correct
29 Correct 8 ms 4388 KB Output is correct
30 Correct 13 ms 4444 KB Output is correct
31 Correct 7 ms 4184 KB Output is correct
32 Correct 9 ms 4188 KB Output is correct
33 Correct 9 ms 4320 KB Output is correct
34 Correct 10 ms 4580 KB Output is correct
35 Correct 11 ms 4668 KB Output is correct
36 Correct 254 ms 4444 KB Output is correct
37 Correct 416 ms 4188 KB Output is correct
38 Correct 473 ms 4372 KB Output is correct
39 Correct 105 ms 4444 KB Output is correct
40 Correct 510 ms 4188 KB Output is correct
41 Correct 1002 ms 4388 KB Output is correct
42 Correct 1291 ms 4188 KB Output is correct
43 Correct 721 ms 4184 KB Output is correct
44 Correct 854 ms 4184 KB Output is correct
45 Correct 285 ms 4316 KB Output is correct
46 Correct 421 ms 4188 KB Output is correct
47 Correct 536 ms 4188 KB Output is correct
48 Correct 288 ms 4188 KB Output is correct
49 Correct 986 ms 4440 KB Output is correct
50 Correct 525 ms 4948 KB Output is correct
51 Correct 2431 ms 4948 KB Output is correct
52 Correct 2552 ms 5320 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Execution timed out 4090 ms 4396 KB Time limit exceeded
55 Halted 0 ms 0 KB -