codeforces#527 - C. Glass Carving (线段树)

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值