Submission #163960

# Submission time Handle Problem Language Result Execution time Memory
163960 2019-11-16T12:16:42 Z sams Street Lamps (APIO19_street_lamps) C++14
20 / 100
426 ms 12236 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 3e5+10;

struct ND
{
	int s, m;	
} seg[4*maxn];

int n, q;
int v[maxn];
string ss;

ND op(ND a, ND b)
{
	return {a.s + b.s, max(a.m, b.m)};
}

void build(int u = 1, int l = 1, int r = n)
{
	if(l == r)
	{
		seg[u] = {v[l], 0};
		return;
	}

	int mid = (l+r) >> 1;

	build(2*u, l, mid);
	build(2*u + 1, mid + 1, r);

	seg[u] = op(seg[2*u], seg[2*u+1]);
}

ND query(int a, int b, int u = 1, int l = 1 , int r = n)
{
	if(r < a || l > b) return {0, 0};
	if(a <= l && r <= b) return seg[u];

	int mid = (l + r) >> 1;

	return op(query(a, b, 2*u, l, mid), query(a, b, 2*u+1, mid +1, r));
}

void upd(int a, int t, int u = 1, int l = 1, int r = n)
{
	if(l == r)
	{
		seg[u] = {(seg[u].s == 0)? 1 : 0, t};

		return;
	}

	int mid = (l + r) >> 1;

	if(a <= mid) upd(a, t, 2*u, l, mid);
	else upd(a, t, 2*u +1, mid +1, r);

	seg[u] = op(seg[2*u], seg[2*u +1]);
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

	cin >> n >> q >> ss;

	for(int i = 0 ; i < n ; ++i)
	{
		if(ss[i] == '0') v[i + 1] = 0;
		else v[i + 1] = 1;
	}

	build();

	for(int i = 1 ; i <= q ; ++i)
	{
		string S;
		int l, r;
		cin >> S >> l;

		if(S == "query")
		{
			cin >> r;

			ND qr = query(l, r-1);

			if(qr.s == r - l) cout << i - qr.m << "\n";
			else cout << "0\n";
		}
		else
		{
			upd(l, i);
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 102 ms 760 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 162 ms 10252 KB Output is correct
6 Correct 206 ms 10412 KB Output is correct
7 Correct 246 ms 10552 KB Output is correct
8 Correct 331 ms 12236 KB Output is correct
9 Correct 105 ms 1272 KB Output is correct
10 Correct 111 ms 1284 KB Output is correct
11 Correct 116 ms 1412 KB Output is correct
12 Correct 303 ms 10812 KB Output is correct
13 Correct 426 ms 12216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -