阅读背景:

Codeforces 527C Glass Carvi

来源:互联网 
#include<bits/stdc++.h>
#define ls l, mid, rt << 1
#define rs mid + 1, r, rt << 1 | 1
using namespace std;

const int MAXN = 200000 + 10;
struct f
{
	int maxx;
	int ll, rr;
	int l, r, len;
}tree[MAXN << 2][2];

void push_up(int rt, int t)
{
	tree[rt][t].ll = tree[rt << 1][t].ll;
	if(tree[rt << 1][t].ll == tree[rt << 1][t].len)
		tree[rt][t].ll += tree[rt << 1 | 1][t].ll;
	tree[rt][t].rr = tree[rt << 1 | 1][t].rr;
	if(tree[rt << 1 | 1][t].rr == tree[rt << 1 | 1][t].len)
		tree[rt][t].rr += tree[rt << 1][t].rr;
	tree[rt][t].maxx = max (tree[rt << 1][t].maxx, tree[rt << 1 | 1][t].maxx);
	tree[rt][t].maxx = max (tree[rt][t].maxx, tree[rt << 1][t].rr + tree[rt << 1 | 1][t].ll);
}

void build(int l, int r, int rt, int t)
{
	tree[rt][t].l = l, tree[rt][t].r = r, tree[rt][t].len = r - l + 1;
	if(l == r)
	{
		tree[rt][t].ll = tree[rt][t].rr = tree[rt][t].maxx = 1;
		return;
	}
	int mid = (l + r) >> 1;
	build(ls, t);
	build(rs, t);
	push_up(rt, t);
}

void update(int l, int r, int rt, int k, int t)
{
	if(l == r)
	{
		tree[rt][t].ll = tree[rt][t].rr = tree[rt][t].maxx = 0;
		return;
	}
	int mid = (l + r) >> 1;
	if(mid >= k)
		update(ls, k, t);
	if(mid < k)
		update(rs, k, t);
	push_up(rt, t);
}
int main()
{
	int n, m, k,temp;
	char q[10];
	scanf("%d %d %d", &n, &m, &k);
	build(1, n - 1, 1, 1);
	build(1, m - 1, 1, 0);
	//cout << tree[1][0].maxx << " " << tree[1][1].maxx << endl;
	while(k --)
	{
		scanf("%s %d", q, &temp);
		if(q[0] == 'H')
			update(1, m - 1, 1, temp, 0);
		else
			update(1, n - 1, 1, temp, 1);
		//cout << tree[1][0].maxx << " " << tree[1][1].maxx <<endl;
		long long te = (long long )(tree[1][0].maxx + 1) * (tree[1][1].maxx + 1);
		printf("%lld\n", te);
	}
	return 0;
}
#include<bits/stdc++.h>
#define ls l, mid



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: