Submission #572435

# Submission time Handle Problem Language Result Execution time Memory
572435 2022-06-04T11:29:26 Z CpDark Street Lamps (APIO19_street_lamps) C++14
20 / 100
456 ms 15100 KB
#include <bits/stdc++.h>
#define fastInput ios::sync_with_stdio(false); cin.tie(nullptr);

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pii;
typedef vector<pii> vp;
typedef vector<bool> vb;
typedef vector<vb> vvb;

struct segmentTree
{
	vi st;
	int size;

	void init(int n) {
		for (size = 1; size < n; size *= 2) {}
		st.resize(2 * size);
	}

	void update(int index, int val) {
		index += size;
		st[index] = val;
		for (index /= 2; index; index /= 2) {
			st[index] = min(st[index * 2], st[index * 2 + 1]);
		}
	}

	int query(int l, int r) {
		int ans = INT_MAX;
		for (l += size, r += size; l <= r; l /= 2, r /= 2) {
			if (l % 2) {
				ans = min(ans, st[l]);
				l++;
			}
			if (r % 2 == 0) {
				ans = min(ans, st[r]);
				r--;
			}
		}
		return ans;
	}

};
int main() {
	fastInput;
	int n, q;
	cin >> n >> q;
	segmentTree st;
	st.init(n + 1);
	vb lights(n+1);

	vi ans(n + 1);
	vi last(n + 1, -1);
	string curr;
	cin >> curr;
	for (int i = 0; i < n; i++) {
		if (curr[i] == '1') {
			lights[i + 1] = true;
			last[i + 1] = 0;
		}
		else {
			lights[i + 1] = false;
		}
		//st.update(i + 1, lights[i + 1]);
	}


	string type;
	for (int i = 1; i <= q; i++) {

		cin >> type;
		if (type == "query") {
			int a, b;
			cin >> a >> b;
			int count = ans[a];
			if (lights[a]) {
				count += i - last[a];
			}
			cout << count << endl;
		}
		else {
			int index;
			cin >> index;
			lights[index] = !lights[index];
			if (lights[index]) {
				last[index] = i;
			}
			else {
				ans[index] += i - last[index];
			}
		}
	}
	

	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 229 ms 1172 KB Output is correct
2 Correct 234 ms 4648 KB Output is correct
3 Correct 257 ms 5416 KB Output is correct
4 Correct 260 ms 13024 KB Output is correct
5 Correct 296 ms 13472 KB Output is correct
6 Correct 245 ms 12724 KB Output is correct
7 Correct 446 ms 13676 KB Output is correct
8 Correct 456 ms 15100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -