hdu5023 A Corrupt Mayor's Performance Art(线段树+区间更新)
来源:互联网 发布:会计事务所审计软件 编辑:程序博客网 时间:2024/04/30 17:17
hdu5023
题目
P :A到B区间图上第C种颜色;
Q:A到B所有点存在的颜色种类;
思路
因为只有30种颜色,可以用位运算进行状态压缩,线段树就是区间更新,区间查询。
代码
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#define lson l, m , rt << 1#define rson m + 1 ,r , rt << 1 | 1using namespace std;typedef long long ll;const int maxn=1000010;int n,m;ll col[maxn<<2];ll sum[maxn<<2];void PushDown(int rt){ if(col[rt]) { col[rt<<1]=col[rt]; col[rt<<1|1]=col[rt]; sum[rt<<1]=col[rt]; sum[rt<<1|1]=col[rt]; col[rt]=0; }}void PushUp(int rt){ sum[rt]=sum[rt<<1]|sum[rt<<1|1];}void build(int l,int r,int rt){ col[rt]=0; if(l==r) { sum[rt]=2; return; } int m=(l+r)>>1; build(lson); build(rson); PushUp(rt);}void update(int c,int L,int R,int l,int r,int rt){ if(L<=l&&r<=R) { col[rt]=1<<(c-1); sum[rt]=1<<(c-1); return; } PushDown(rt); int m=(l+r)>>1; if(L<=m) update(c,L,R,lson); if(R>m) update(c,L,R,rson); PushUp(rt);}ll query(int L,int R,int l,int r,int rt){ if(L<=l&&r<=R) { return sum[rt]; } ll ans=0; PushDown(rt); int m=(l+r)>>1; if(L<=m) ans|=query(L,R,lson); if(R>m) ans|=query(L,R,rson); return ans;}int main(){ while(scanf("%d %d",&n,&m)!=EOF) { if(n==0&&m==0) break; build(1,n,1); char op; int a,b,c; for(int i=0; i<m; i++) { getchar(); scanf("%c",&op); if(op=='P') { scanf("%d %d %d",&a,&b,&c); update(c,a,b,1,n,1); } else if(op=='Q') { scanf("%d %d",&a,&b); ll sum=query(a,b,1,n,1); int cnt=0; for(int j=1; j<=30; j++) { if(sum&(1<<(j-1))) { if(cnt!=0) printf(" %d",j); else printf("%d",j); cnt++; } } printf("\n"); } } } return 0;}
0 0
- hdu5023 A Corrupt Mayor's Performance Art(线段树+区间更新)
- HDU5023 A Corrupt Mayor's Performance Art 【线段树】
- HDU5023 - A Corrupt Mayor's Performance Art(线段树)
- hdoj5023A Corrupt Mayor's Performance Art【线段树区间更新】
- A Corrupt Mayor's Performance Art+线段树区间更新查询
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
- hdu 5023 A Corrupt Mayor's Performance Art (线段树+区间更新+状压)
- hdu 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
- HDU 5023 A Corrupt Mayor's Performance Art (线段树区间更新,入门详解)
- HDU 5023 - A Corrupt Mayor's Performance Art(线段树区间更新+状态压缩)
- hdu5023——A Corrupt Mayor's Performance Art
- 【HDU】5023 A Corrupt Mayor's Performance Art 线段树
- 【线段树】 HDU 5025 A Corrupt Mayor's Performance Art
- hdu 5023 A Corrupt Mayor's Performance Art(线段树)
- HDU 5023 A Corrupt Mayor's Performance Art (线段树)
- A Corrupt Mayor's Performance Art (线段树+二进制压缩)
- HDU 5023 A Corrupt Mayor's Performance Art 线段树 区间染色
- 报表设计器——设计自己的报表
- 我眼中的Activity的工作过程
- Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
- android学习——Android Studio下创建menu布局文件
- idea控制台打印乱码
- hdu5023 A Corrupt Mayor's Performance Art(线段树+区间更新)
- pci acpi note 2
- Python中幽灵般的yield
- Hibernate中所需要的各jar的作用
- 写给新手程序员的一封信
- Leetcode 389. Find the Difference (Easy) (cpp)
- DFS-PATA-1004. Counting Leaves (30)
- 文章标题
- Studio部署文件时出现错误 ADB enabled