답안 #1020918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1020918 2024-07-12T11:25:49 Z Unforgettablepl Fish 2 (JOI22_fish2) C++17
13 / 100
4000 ms 9792 KB
// #pragma GCC optimize("Ofast","unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int INF = 1e15;


int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vector<int> arr(n+1);
	for(int i=1;i<=n;i++)cin>>arr[i];
	auto solve = [&](int l,int r){
		vector<int> left(n+1,l-1),right(n+1,r+1),pref(n+2);
		for(int i=l;i<=r;i++)pref[i]=pref[i-1]+arr[i];
		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();
			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();
			right[i]=s.top().second;
			s.emplace(arr[i],i);
		}
		vector<vector<int>> adj(n+1);
		for(int i=l;i<=r;i++){
			if(left[i]==l-1 and right[i]==r+1)adj[left[i]].emplace_back(i);
			else if(left[i]==l-1)adj[right[i]].emplace_back(i);
			else if(right[i]==r+1)adj[left[i]].emplace_back(i);
			else if(arr[left[i]]<=arr[right[i]])adj[left[i]].emplace_back(i);
			else adj[right[i]].emplace_back(i);
		}
		int ans = 0;
		function<void(int,int)> dfs = [&](int x,int threshold){
			if(pref[right[x]-1]-pref[left[x]]<threshold)return;
			ans++;
			for(int&i:adj[x])dfs(i,arr[x]);
		};
		for(int&i:adj[l-1])dfs(i,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 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 5 ms 344 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 10 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 16 ms 9428 KB Output is correct
3 Correct 10 ms 8400 KB Output is correct
4 Correct 13 ms 9424 KB Output is correct
5 Correct 15 ms 8536 KB Output is correct
6 Correct 18 ms 8844 KB Output is correct
7 Correct 17 ms 7760 KB Output is correct
8 Correct 18 ms 8796 KB Output is correct
9 Correct 17 ms 7640 KB Output is correct
10 Correct 13 ms 8280 KB Output is correct
11 Correct 10 ms 7516 KB Output is correct
12 Correct 14 ms 8216 KB Output is correct
13 Correct 14 ms 8284 KB Output is correct
14 Correct 14 ms 8248 KB Output is correct
15 Correct 15 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 5 ms 344 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 10 ms 512 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 16 ms 9428 KB Output is correct
23 Correct 10 ms 8400 KB Output is correct
24 Correct 13 ms 9424 KB Output is correct
25 Correct 15 ms 8536 KB Output is correct
26 Correct 18 ms 8844 KB Output is correct
27 Correct 17 ms 7760 KB Output is correct
28 Correct 18 ms 8796 KB Output is correct
29 Correct 17 ms 7640 KB Output is correct
30 Correct 13 ms 8280 KB Output is correct
31 Correct 10 ms 7516 KB Output is correct
32 Correct 14 ms 8216 KB Output is correct
33 Correct 14 ms 8284 KB Output is correct
34 Correct 14 ms 8248 KB Output is correct
35 Correct 15 ms 8540 KB Output is correct
36 Correct 931 ms 9324 KB Output is correct
37 Correct 1458 ms 8304 KB Output is correct
38 Correct 1630 ms 9280 KB Output is correct
39 Correct 471 ms 8988 KB Output is correct
40 Correct 1813 ms 8188 KB Output is correct
41 Correct 2070 ms 9464 KB Output is correct
42 Correct 2734 ms 8880 KB Output is correct
43 Correct 1634 ms 7768 KB Output is correct
44 Correct 1861 ms 7528 KB Output is correct
45 Correct 908 ms 8044 KB Output is correct
46 Correct 1192 ms 8056 KB Output is correct
47 Correct 1444 ms 8936 KB Output is correct
48 Correct 637 ms 7924 KB Output is correct
49 Correct 2112 ms 8124 KB Output is correct
50 Correct 1087 ms 8172 KB Output is correct
51 Execution timed out 4066 ms 8632 KB Time limit exceeded
52 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 16 ms 9428 KB Output is correct
3 Correct 10 ms 8400 KB Output is correct
4 Correct 13 ms 9424 KB Output is correct
5 Correct 15 ms 8536 KB Output is correct
6 Correct 18 ms 8844 KB Output is correct
7 Correct 17 ms 7760 KB Output is correct
8 Correct 18 ms 8796 KB Output is correct
9 Correct 17 ms 7640 KB Output is correct
10 Correct 13 ms 8280 KB Output is correct
11 Correct 10 ms 7516 KB Output is correct
12 Correct 14 ms 8216 KB Output is correct
13 Correct 14 ms 8284 KB Output is correct
14 Correct 14 ms 8248 KB Output is correct
15 Correct 15 ms 8540 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Execution timed out 4081 ms 9792 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 16 ms 9428 KB Output is correct
3 Correct 10 ms 8400 KB Output is correct
4 Correct 13 ms 9424 KB Output is correct
5 Correct 15 ms 8536 KB Output is correct
6 Correct 18 ms 8844 KB Output is correct
7 Correct 17 ms 7760 KB Output is correct
8 Correct 18 ms 8796 KB Output is correct
9 Correct 17 ms 7640 KB Output is correct
10 Correct 13 ms 8280 KB Output is correct
11 Correct 10 ms 7516 KB Output is correct
12 Correct 14 ms 8216 KB Output is correct
13 Correct 14 ms 8284 KB Output is correct
14 Correct 14 ms 8248 KB Output is correct
15 Correct 15 ms 8540 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Execution timed out 4080 ms 9704 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 4 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 6 ms 348 KB Output is correct
9 Correct 6 ms 344 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 6 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 5 ms 344 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 5 ms 348 KB Output is correct
19 Correct 3 ms 348 KB Output is correct
20 Correct 10 ms 512 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 16 ms 9428 KB Output is correct
23 Correct 10 ms 8400 KB Output is correct
24 Correct 13 ms 9424 KB Output is correct
25 Correct 15 ms 8536 KB Output is correct
26 Correct 18 ms 8844 KB Output is correct
27 Correct 17 ms 7760 KB Output is correct
28 Correct 18 ms 8796 KB Output is correct
29 Correct 17 ms 7640 KB Output is correct
30 Correct 13 ms 8280 KB Output is correct
31 Correct 10 ms 7516 KB Output is correct
32 Correct 14 ms 8216 KB Output is correct
33 Correct 14 ms 8284 KB Output is correct
34 Correct 14 ms 8248 KB Output is correct
35 Correct 15 ms 8540 KB Output is correct
36 Correct 931 ms 9324 KB Output is correct
37 Correct 1458 ms 8304 KB Output is correct
38 Correct 1630 ms 9280 KB Output is correct
39 Correct 471 ms 8988 KB Output is correct
40 Correct 1813 ms 8188 KB Output is correct
41 Correct 2070 ms 9464 KB Output is correct
42 Correct 2734 ms 8880 KB Output is correct
43 Correct 1634 ms 7768 KB Output is correct
44 Correct 1861 ms 7528 KB Output is correct
45 Correct 908 ms 8044 KB Output is correct
46 Correct 1192 ms 8056 KB Output is correct
47 Correct 1444 ms 8936 KB Output is correct
48 Correct 637 ms 7924 KB Output is correct
49 Correct 2112 ms 8124 KB Output is correct
50 Correct 1087 ms 8172 KB Output is correct
51 Execution timed out 4066 ms 8632 KB Time limit exceeded
52 Halted 0 ms 0 KB -