Submission #536684

#TimeUsernameProblemLanguageResultExecution timeMemory
536684blueSimple game (IZhO17_game)C++17
100 / 100
95 ms11240 KiB
#include <iostream>
#include <vector>
using namespace std;

using vi = vector<int>;

const int mx = (1<<20);

vi st(mx<<1, 0);

void add(int l, int r, int v)
{
	if(r < l) swap(l, r);
	l += mx;
	r += mx+1;
	while(l < r)
	{
		if(l & 1)
		{
			st[l] += v;
			l++;
		}

		if(r & 1)
		{
			r--;
			st[r] += v;
		}

		l >>= 1;
		r >>= 1;
	}
}

int get(int i)
{
	i += mx;
	int res = 0;
	while(i >= 1)
	{
		res += st[i];
		i >>= 1;
	}
	return res;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int N, M;
	cin >> N >> M;

	vi h(1+N);
	for(int i = 1; i <= N; i++) cin >> h[i];

	for(int i = 1; i < N; i++)
		add(h[i], h[i+1], 1);

	for(int j = 1; j <= M; j++)
	{
		int o;
		cin >> o;

		if(o == 1)
		{
			int i, v;
			cin >> i >> v;

			if(i != 1) add(h[i], h[i-1], -1);
			if(i != N) add(h[i], h[i+1], -1);

			h[i] = v;

			if(i != 1) add(h[i], h[i-1], +1);
			if(i != N) add(h[i], h[i+1], +1);
		}
		else
		{
			int H;
			cin >> H;

			cout << get(H) << '\n';
		}
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...