Submission #721318

# Submission time Handle Problem Language Result Execution time Memory
721318 2023-04-10T16:44:41 Z Abrar_Al_Samit Fish 2 (JOI22_fish2) C++17
13 / 100
4000 ms 8204 KB
#include<bits/stdc++.h>
using namespace std;

const int nax = 1e5 + 3;


struct BIT {
	long long bit[nax] = {0};

	void update(int i, int val) {
		while(i<nax) {
			bit[i] += val;
			i += i&-i;
		}
	}
	long long query(int i) {
		long long ret = 0;
		while(i>0) {
			ret += bit[i];
			i -= i&-i;
		}
		return ret;
	}
	long long query(int l, int r) {
		return query(r) - query(l-1);
	}
};
long long a[nax];
int n;
bool wins[nax];
void PlayGround() {

	BIT T;
	cin>>n;
	for(int i=1; i<=n; ++i) {
		cin>>a[i];
		T.update(i, a[i]);
	}

	int q;
	cin>>q;	
	while(q--) {
		int tp;
		cin>>tp;
		if(tp==1) {
			int x, y;
			cin>>x>>y;
			T.update(x, y-a[x]);
			a[x] = y;
		} else {
			int l, r;
			cin>>l>>r;

			vector<int>ids;
			for(int i=l; i<=r; ++i) {
				ids.push_back(i);
				wins[i] = 0;
			}
			sort(ids.begin(), ids.end(), [&] (int i, int j) {
				return make_pair(a[i], i) > make_pair(a[j], j);
			});	

			set<int>cr = {l-1, r+1};
			for(int j : ids) {
				int lef = *(--cr.lower_bound(j));
				int rit = *cr.lower_bound(j);
				long long S = T.query(lef+1, rit-1);

				if(lef < l && rit > r) {
					wins[j] = 1;
				} 
				if(lef >= l) {
					if(a[lef] <= S) wins[j] = wins[lef];
				}
				if(rit <= r) {
					if(a[rit] <= S) wins[j] = wins[rit];
				} 
				cr.insert(j);
			}
			int ans = 0;
			for(int i=l; i<=r; ++i) {
				ans += wins[i];
			}
			cout<<ans<<'\n';
		}
	}

	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	PlayGround();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1108 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 17 ms 1108 KB Output is correct
7 Correct 5 ms 1112 KB Output is correct
8 Correct 14 ms 1108 KB Output is correct
9 Correct 23 ms 1112 KB Output is correct
10 Correct 8 ms 1108 KB Output is correct
11 Correct 20 ms 1156 KB Output is correct
12 Correct 5 ms 1108 KB Output is correct
13 Correct 21 ms 1144 KB Output is correct
14 Correct 6 ms 1108 KB Output is correct
15 Correct 12 ms 1104 KB Output is correct
16 Correct 24 ms 1108 KB Output is correct
17 Correct 8 ms 1108 KB Output is correct
18 Correct 22 ms 1116 KB Output is correct
19 Correct 10 ms 1156 KB Output is correct
20 Correct 53 ms 1136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 62 ms 7540 KB Output is correct
3 Correct 53 ms 7348 KB Output is correct
4 Correct 62 ms 7528 KB Output is correct
5 Correct 49 ms 7456 KB Output is correct
6 Correct 72 ms 7976 KB Output is correct
7 Correct 47 ms 7260 KB Output is correct
8 Correct 90 ms 7992 KB Output is correct
9 Correct 50 ms 7244 KB Output is correct
10 Correct 62 ms 7572 KB Output is correct
11 Correct 44 ms 7256 KB Output is correct
12 Correct 50 ms 7192 KB Output is correct
13 Correct 66 ms 7316 KB Output is correct
14 Correct 58 ms 7612 KB Output is correct
15 Correct 52 ms 7612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1108 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 17 ms 1108 KB Output is correct
7 Correct 5 ms 1112 KB Output is correct
8 Correct 14 ms 1108 KB Output is correct
9 Correct 23 ms 1112 KB Output is correct
10 Correct 8 ms 1108 KB Output is correct
11 Correct 20 ms 1156 KB Output is correct
12 Correct 5 ms 1108 KB Output is correct
13 Correct 21 ms 1144 KB Output is correct
14 Correct 6 ms 1108 KB Output is correct
15 Correct 12 ms 1104 KB Output is correct
16 Correct 24 ms 1108 KB Output is correct
17 Correct 8 ms 1108 KB Output is correct
18 Correct 22 ms 1116 KB Output is correct
19 Correct 10 ms 1156 KB Output is correct
20 Correct 53 ms 1136 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 62 ms 7540 KB Output is correct
23 Correct 53 ms 7348 KB Output is correct
24 Correct 62 ms 7528 KB Output is correct
25 Correct 49 ms 7456 KB Output is correct
26 Correct 72 ms 7976 KB Output is correct
27 Correct 47 ms 7260 KB Output is correct
28 Correct 90 ms 7992 KB Output is correct
29 Correct 50 ms 7244 KB Output is correct
30 Correct 62 ms 7572 KB Output is correct
31 Correct 44 ms 7256 KB Output is correct
32 Correct 50 ms 7192 KB Output is correct
33 Correct 66 ms 7316 KB Output is correct
34 Correct 58 ms 7612 KB Output is correct
35 Correct 52 ms 7612 KB Output is correct
36 Execution timed out 4032 ms 7644 KB Time limit exceeded
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 62 ms 7540 KB Output is correct
3 Correct 53 ms 7348 KB Output is correct
4 Correct 62 ms 7528 KB Output is correct
5 Correct 49 ms 7456 KB Output is correct
6 Correct 72 ms 7976 KB Output is correct
7 Correct 47 ms 7260 KB Output is correct
8 Correct 90 ms 7992 KB Output is correct
9 Correct 50 ms 7244 KB Output is correct
10 Correct 62 ms 7572 KB Output is correct
11 Correct 44 ms 7256 KB Output is correct
12 Correct 50 ms 7192 KB Output is correct
13 Correct 66 ms 7316 KB Output is correct
14 Correct 58 ms 7612 KB Output is correct
15 Correct 52 ms 7612 KB Output is correct
16 Correct 1 ms 1100 KB Output is correct
17 Execution timed out 4069 ms 7324 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 62 ms 7540 KB Output is correct
3 Correct 53 ms 7348 KB Output is correct
4 Correct 62 ms 7528 KB Output is correct
5 Correct 49 ms 7456 KB Output is correct
6 Correct 72 ms 7976 KB Output is correct
7 Correct 47 ms 7260 KB Output is correct
8 Correct 90 ms 7992 KB Output is correct
9 Correct 50 ms 7244 KB Output is correct
10 Correct 62 ms 7572 KB Output is correct
11 Correct 44 ms 7256 KB Output is correct
12 Correct 50 ms 7192 KB Output is correct
13 Correct 66 ms 7316 KB Output is correct
14 Correct 58 ms 7612 KB Output is correct
15 Correct 52 ms 7612 KB Output is correct
16 Correct 1 ms 1108 KB Output is correct
17 Execution timed out 4016 ms 8204 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1108 KB Output is correct
2 Correct 1 ms 980 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 5 ms 1108 KB Output is correct
6 Correct 17 ms 1108 KB Output is correct
7 Correct 5 ms 1112 KB Output is correct
8 Correct 14 ms 1108 KB Output is correct
9 Correct 23 ms 1112 KB Output is correct
10 Correct 8 ms 1108 KB Output is correct
11 Correct 20 ms 1156 KB Output is correct
12 Correct 5 ms 1108 KB Output is correct
13 Correct 21 ms 1144 KB Output is correct
14 Correct 6 ms 1108 KB Output is correct
15 Correct 12 ms 1104 KB Output is correct
16 Correct 24 ms 1108 KB Output is correct
17 Correct 8 ms 1108 KB Output is correct
18 Correct 22 ms 1116 KB Output is correct
19 Correct 10 ms 1156 KB Output is correct
20 Correct 53 ms 1136 KB Output is correct
21 Correct 1 ms 1108 KB Output is correct
22 Correct 62 ms 7540 KB Output is correct
23 Correct 53 ms 7348 KB Output is correct
24 Correct 62 ms 7528 KB Output is correct
25 Correct 49 ms 7456 KB Output is correct
26 Correct 72 ms 7976 KB Output is correct
27 Correct 47 ms 7260 KB Output is correct
28 Correct 90 ms 7992 KB Output is correct
29 Correct 50 ms 7244 KB Output is correct
30 Correct 62 ms 7572 KB Output is correct
31 Correct 44 ms 7256 KB Output is correct
32 Correct 50 ms 7192 KB Output is correct
33 Correct 66 ms 7316 KB Output is correct
34 Correct 58 ms 7612 KB Output is correct
35 Correct 52 ms 7612 KB Output is correct
36 Execution timed out 4032 ms 7644 KB Time limit exceeded
37 Halted 0 ms 0 KB -