# POJ 3667 Hotel(算竞进阶习题)

2022年11月23日
0 收藏 794 点赞 4,678 浏览 2537 个字

# 线段树区间染色

push_up和连续子段和有点像，需要维护前缀和后缀

``#include <bits/stdc++.h>#define INF 0x3f3f3f3fusing namespace std;typedef long long ll;inline int lowbit(int x){ return x & (-x); }inline int read(){    int X = 0, w = 0; char ch = 0;    while(!isdigit(ch)) { w |= ch == '-'; ch = getchar(); }    while(isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();    return w ? -X : X;}inline int gcd(int a, int b){ return a % b ? gcd(b, a % b) : b; }inline int lcm(int a, int b){ return a / gcd(a, b) * b; }template<typename T>inline T max(T x, T y, T z){ return max(max(x, y), z); }template<typename T>inline T min(T x, T y, T z){ return min(min(x, y), z); }template<typename A, typename B, typename C>inline A fpow(A x, B p, C yql){    A ans = 1;    for(; p; p >>= 1, x = 1LL * x * x % yql)if(p & 1)ans = 1LL * x * ans % yql;    return ans;}const int N = 50005;int n, m;int prefix[N<<2], suffix[N<<2], tree[N<<2], lazy[N<<2];void push_up(int rt, int l, int r){    int lson = rt << 1, rson = rt << 1 | 1;    int mid = (l + r) >> 1;    tree[rt] = max(tree[lson], tree[rson], suffix[lson] + prefix[rson]);    prefix[rt] = prefix[lson], suffix[rt] = suffix[rson];    if(tree[lson] == mid - l + 1) prefix[rt] += prefix[rson];    if(tree[rson] == r - mid) suffix[rt] += suffix[lson];}void push_down(int rt, int l, int r){    if(lazy[rt] != -1){        int lson = rt << 1, rson = rt << 1 | 1;        int mid = (l + r) >> 1;        lazy[lson] = lazy[rson] = lazy[rt];        prefix[lson] = suffix[lson] = tree[lson] = lazy[rt] * (mid - l + 1);        prefix[rson] = suffix[rson] = tree[rson] = lazy[rt] * (r - mid);        lazy[rt] = -1;    }}void buildTree(int rt, int l, int r){    if(l == r){        prefix[rt] = suffix[rt] = tree[rt] = 1;        lazy[rt] = -1;        return;    }    lazy[rt] = -1;    int mid = (l + r) >> 1;    buildTree(rt << 1, l, mid);    buildTree(rt << 1 | 1, mid + 1, r);    push_up(rt, l, r);}void modify(int rt, int l, int r, int modifyL, int modifyR, int status){    if(l == modifyL && r == modifyR){        tree[rt] = prefix[rt] = suffix[rt] = (r - l + 1) * status;        lazy[rt] = status;        return;    }    push_down(rt, l, r);    int mid = (l + r) >> 1;    if(modifyL > mid) modify(rt << 1 | 1, mid + 1, r, modifyL, modifyR, status);    else if(modifyR <= mid) modify(rt << 1, l, mid, modifyL, modifyR, status);    else{        modify(rt << 1, l, mid, modifyL, mid, status);        modify(rt << 1 | 1, mid + 1, r, mid + 1, modifyR, status);    }    push_up(rt, l, r);}int query(int rt, int l, int r, int len){    if(prefix[rt] >= len) return l;    push_down(rt, l, r);    int mid = (l + r) >> 1, lson = rt << 1, rson = rt << 1 | 1;    if(tree[lson] >= len) return query(lson, l, mid, len);    //else if(tree[rson] >= len) return query(rson, mid + 1, r, len);    else if(suffix[lson] + prefix[rson] >= len) return mid - suffix[lson] + 1;    else if(tree[rson] >= len) return query(rson, mid + 1, r, len);    else return 0;}int main(){    n = read(), m = read();    buildTree(1, 1, n);    while(m --){        int opt = read();        if(opt == 1){            int len = read();            int pos = query(1, 1, n, len);            if(pos != 0 ) modify(1, 1, n, pos, pos + len - 1, 0);            printf("%d\n", pos);        }        else if(opt == 2){            int x = read(), y = read();            modify(1, 1, n, x, x + y - 1, 1);        }    }    return 0;}``

python开发_常用的python模块及安装方法

Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接：http://www.codeforces.com/contest/660/problem/CDes…

zengkefu@server1:/usr/src\$ uname -aLinux server1 4.10.0-19-generic #21…

Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式，并且由于涉及到要把拍到的照片显…

Struts的使用

400-888-8888

ceotheme@ceo.com