codeforces#527 - C. Glass Carving
链接:
https://codeforces.com/problemset/problem/527/C
题解链接:
https://blog.csdn.net/scau_cdx/article/details/89893591
https://www.cnblogs.com/shuaihui520/p/9835973.html
求最长连续0区间
Code:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
#include <string.h>
#include <map>
#include <set>
#include <stack>
#include <time.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 2e5+10;
struct node {
int lz, rz, az,mz;
}st[N*4][2];
void pushup(int rt ,int k){
st[rt][k].lz = (st[rt<<1][k].az == 1)?(st[rt<<1][k].lz+st[rt<<1|1][k].lz) : st[rt<<1][k].lz;
st[rt][k].rz = (st[rt<<1|1][k].az == 1)?(st[rt<<1|1][k].rz+st[rt<<1][k].rz): st[rt<<1|1][k].rz;
st[rt][k].az = st[rt<<1][k].az & st[rt<<1|1][k].az;
st[rt][k].mz = max(st[rt<<1][k].mz, max(st[rt<<1|1][k].mz, st[rt<<1][k].rz + st[rt<<1|1][k].lz));
}
void build(int rt, int l, int r, int k){
if(l == r) st[rt][k].lz = st[rt][k].rz = st[rt][k].az = st[rt][k].mz = 1;
else {
int m = (l+r)>>1;
build(rt<<1, l, m, k);
build(rt<<1|1, m+1, r, k);
pushup(rt,k);
}
}
void update(int rt, int l, int r, int idx, int k){
if(l == r) st[rt][k].az = st[rt][k].lz = st[rt][k].rz = st[rt][k].mz = 0;
else {
int m = (l + r) >>1;
if(idx <= m) update(rt<<1, l, m, idx, k);
else update(rt<<1|1, m+1, r, idx, k);
pushup(rt, k);
}
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int h, w, n;
cin>>w >> h >>n;
build(1, 1, w-1, 0);
build(1, 1, h-1, 1);
while(n--){
string a;
int x;
cin>>a>>x;
if(a=="H") update(1, 1, h-1, x, 1);
else update(1, 1, w-1, x, 0);
cout<< (ll)(1+st[1][0].mz) * (ll)(1+st[1][1].mz) <<endl;
}
return 0;
}