Submission #639712

# Submission time Handle Problem Language Result Execution time Memory
639712 2022-09-11T08:12:33 Z LittleCube Fish 2 (JOI22_fish2) C++14
13 / 100
4000 ms 9060 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;

int N, Q;
ll A[100005], able[100005], mL[100005], mR[100005], sum[100005];

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> N;
	for(int i = 1; i <= N; i++)
		cin >> A[i];
	cin >> Q;
	while(Q--)
	{
		int T, L, R;
		cin >> T >> L >> R;
		if(T == 1)
		{
			A[L] = R;
			continue;
		}
		for(int i = 1; i <= N; i++)
			sum[i] = sum[i - 1] + A[i], able[i] = 0;

		vector<int> v;
		for(int i = L; i <= R; i++)
			v.emplace_back(i);
		sort(v.begin(), v.end(), [&](int i, int j){ return A[i] > A[j]; });

		ll inf1 = 1e18, inf2 = 1e18;
		swap(A[L - 1], inf1);
		swap(A[R + 1], inf2);

		int ans = 0;
		set<int> bound;

		for(int i : v)
		{
			auto iter = bound.lower_bound(i);
			if(iter == bound.end() && iter == bound.begin())
			   ans++, able[i] = 1;
			else
			{
				ll l = (iter == bound.begin() ? L - 1 : *prev(iter)),
				   r = (iter == bound.end()   ? R + 1: *iter);
				bool valid = 0;
				if(A[l] <= A[r])
					valid = (sum[r - 1] - sum[l] >= A[l] && able[l]);
				else
					valid = (sum[r - 1] - sum[l] >= A[r] && able[r]);
				ans += valid, able[i] = valid;
			}	

			bound.insert(i);
		}

		swap(A[L - 1], inf1);
		swap(A[R + 1], inf2);
		cout << ans << '\n';
	}
	
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 10 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 10 ms 388 KB Output is correct
9 Correct 17 ms 388 KB Output is correct
10 Correct 7 ms 336 KB Output is correct
11 Correct 15 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 13 ms 340 KB Output is correct
14 Correct 4 ms 340 KB Output is correct
15 Correct 8 ms 388 KB Output is correct
16 Correct 18 ms 340 KB Output is correct
17 Correct 5 ms 340 KB Output is correct
18 Correct 15 ms 340 KB Output is correct
19 Correct 7 ms 332 KB Output is correct
20 Correct 41 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 44 ms 8328 KB Output is correct
3 Correct 40 ms 8084 KB Output is correct
4 Correct 49 ms 8332 KB Output is correct
5 Correct 43 ms 8012 KB Output is correct
6 Correct 57 ms 8744 KB Output is correct
7 Correct 35 ms 7948 KB Output is correct
8 Correct 60 ms 8648 KB Output is correct
9 Correct 38 ms 7964 KB Output is correct
10 Correct 44 ms 8272 KB Output is correct
11 Correct 39 ms 8012 KB Output is correct
12 Correct 42 ms 7920 KB Output is correct
13 Correct 43 ms 7980 KB Output is correct
14 Correct 44 ms 8232 KB Output is correct
15 Correct 50 ms 8392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 10 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 10 ms 388 KB Output is correct
9 Correct 17 ms 388 KB Output is correct
10 Correct 7 ms 336 KB Output is correct
11 Correct 15 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 13 ms 340 KB Output is correct
14 Correct 4 ms 340 KB Output is correct
15 Correct 8 ms 388 KB Output is correct
16 Correct 18 ms 340 KB Output is correct
17 Correct 5 ms 340 KB Output is correct
18 Correct 15 ms 340 KB Output is correct
19 Correct 7 ms 332 KB Output is correct
20 Correct 41 ms 380 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 44 ms 8328 KB Output is correct
23 Correct 40 ms 8084 KB Output is correct
24 Correct 49 ms 8332 KB Output is correct
25 Correct 43 ms 8012 KB Output is correct
26 Correct 57 ms 8744 KB Output is correct
27 Correct 35 ms 7948 KB Output is correct
28 Correct 60 ms 8648 KB Output is correct
29 Correct 38 ms 7964 KB Output is correct
30 Correct 44 ms 8272 KB Output is correct
31 Correct 39 ms 8012 KB Output is correct
32 Correct 42 ms 7920 KB Output is correct
33 Correct 43 ms 7980 KB Output is correct
34 Correct 44 ms 8232 KB Output is correct
35 Correct 50 ms 8392 KB Output is correct
36 Execution timed out 4033 ms 8312 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 44 ms 8328 KB Output is correct
3 Correct 40 ms 8084 KB Output is correct
4 Correct 49 ms 8332 KB Output is correct
5 Correct 43 ms 8012 KB Output is correct
6 Correct 57 ms 8744 KB Output is correct
7 Correct 35 ms 7948 KB Output is correct
8 Correct 60 ms 8648 KB Output is correct
9 Correct 38 ms 7964 KB Output is correct
10 Correct 44 ms 8272 KB Output is correct
11 Correct 39 ms 8012 KB Output is correct
12 Correct 42 ms 7920 KB Output is correct
13 Correct 43 ms 7980 KB Output is correct
14 Correct 44 ms 8232 KB Output is correct
15 Correct 50 ms 8392 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Execution timed out 4041 ms 8104 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 44 ms 8328 KB Output is correct
3 Correct 40 ms 8084 KB Output is correct
4 Correct 49 ms 8332 KB Output is correct
5 Correct 43 ms 8012 KB Output is correct
6 Correct 57 ms 8744 KB Output is correct
7 Correct 35 ms 7948 KB Output is correct
8 Correct 60 ms 8648 KB Output is correct
9 Correct 38 ms 7964 KB Output is correct
10 Correct 44 ms 8272 KB Output is correct
11 Correct 39 ms 8012 KB Output is correct
12 Correct 42 ms 7920 KB Output is correct
13 Correct 43 ms 7980 KB Output is correct
14 Correct 44 ms 8232 KB Output is correct
15 Correct 50 ms 8392 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Execution timed out 4062 ms 9060 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 328 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Correct 10 ms 340 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 10 ms 388 KB Output is correct
9 Correct 17 ms 388 KB Output is correct
10 Correct 7 ms 336 KB Output is correct
11 Correct 15 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 13 ms 340 KB Output is correct
14 Correct 4 ms 340 KB Output is correct
15 Correct 8 ms 388 KB Output is correct
16 Correct 18 ms 340 KB Output is correct
17 Correct 5 ms 340 KB Output is correct
18 Correct 15 ms 340 KB Output is correct
19 Correct 7 ms 332 KB Output is correct
20 Correct 41 ms 380 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 44 ms 8328 KB Output is correct
23 Correct 40 ms 8084 KB Output is correct
24 Correct 49 ms 8332 KB Output is correct
25 Correct 43 ms 8012 KB Output is correct
26 Correct 57 ms 8744 KB Output is correct
27 Correct 35 ms 7948 KB Output is correct
28 Correct 60 ms 8648 KB Output is correct
29 Correct 38 ms 7964 KB Output is correct
30 Correct 44 ms 8272 KB Output is correct
31 Correct 39 ms 8012 KB Output is correct
32 Correct 42 ms 7920 KB Output is correct
33 Correct 43 ms 7980 KB Output is correct
34 Correct 44 ms 8232 KB Output is correct
35 Correct 50 ms 8392 KB Output is correct
36 Execution timed out 4033 ms 8312 KB Time limit exceeded
37 Halted 0 ms 0 KB -