【HDU】5023 A Corrupt Mayor's Performance Art 线段树
来源:互联网 发布:java swing怎么运行 编辑:程序博客网 时间:2024/05/16 06:39
传送门:【HDU】5023 A Corrupt Mayor's Performance Art
题目分析:水水的线段树,首先颜色只有30种,所以状压就好了,然后每次查询就把区间内所有的颜色“或”出来,用位运算判断一下有哪些颜色就好了。。
代码如下:
#include <cstdio>#include <cstring>#include <algorithm>#include <vector>#include <queue>using namespace std ;typedef long long LL ;#define rep( i , a , b ) for ( int i = a ; i < b ; ++ i )#define FOR( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REV( i , a , b ) for ( int i = a ; i >= b ; -- i )#define travel( e , H , u ) for ( Edge* e = H[u] ; e ; e = e -> next )#define clr( a , x ) memset ( a , x , sizeof a )#define CPY( a , x ) memcpy ( a , x , sizeof a )#define ls ( o << 1 )#define rs ( o << 1 | 1 )#define lson ls , l , m#define rson rs , m + 1 , r#define mid ( ( l + r ) >> 1 )#define root 1 , 1 , n#define rt o , l , rconst int MAXN = 1000005 ;int cover[MAXN << 2] ;int color[MAXN << 2] ;int n , q ;void pushup ( int o ) {color[o] = color[ls] | color[rs] ;}void pushdown ( int o ) {if ( cover[o] ) {cover[ls] = cover[o] ;cover[rs] = cover[o] ;color[ls] = color[rs] = cover[o] ;cover[o] = 0 ;}}void update ( int L , int R , int v , int o , int l , int r ) {if ( L <= l && r <= R ) {cover[o] = 1 << v ;color[o] = 1 << v ;return ;}int m = mid ;pushdown ( o ) ;if ( L <= m ) update ( L , R , v , lson ) ;if ( m < R ) update ( L , R , v , rson ) ;pushup ( o ) ;}int query ( int L , int R , int o , int l , int r ) {if ( L <= l && r <= R ) return color[o] ;int m = mid ;pushdown ( o ) ;if ( R <= m ) return query ( L , R , lson ) ;if ( m < L ) return query ( L , R , rson ) ;return query ( L , R , lson ) | query ( L , R , rson ) ;}void solve () {char s[5] ;int x , y , c ;clr ( color , 0 ) ;clr ( cover , 0 ) ;update ( 1 , n , 1 , root ) ;while ( q -- ) {scanf ( "%s%d%d" , s , &x , &y ) ;if ( s[0] == 'Q' ) {int S = query ( x , y , root ) ;int flag = 0 ;rep ( i , 0 , 30 ) {if ( S & ( 1 << i ) ) {if ( flag ) printf ( " " ) ;flag = 1 ;printf ( "%d" , i + 1 ) ;}}printf ( "\n" ) ;} else {scanf ( "%d" , &c ) ;update ( x , y , c - 1 , root ) ;}}}int main () {while ( ~scanf ( "%d%d" , &n , &q ) && ( n || q ) ) solve () ;return 0 ;}
0 0
- 【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 5025 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 (线段树+区间更新+状压)
- 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(线段树+位运算)
- HDU 5023 A Corrupt Mayor's Performance Art (线段树区间更新,入门详解)
- HDU 5023 - A Corrupt Mayor's Performance Art(线段树区间更新+状态压缩)
- 代码中“\n”“\r”的区别
- Java基础-类的反射之一
- Oracle内部函数 wmsys.wm_concat 替换办法及思考
- 清华男写的大学4年
- java学习笔记day8
- 【HDU】5023 A Corrupt Mayor's Performance Art 线段树
- 关于命令行环境执行有包结构的java文件不成功的一点点经验
- another app is currently holding the yum lock;waiting for it to exit...
- cocos2dx 系类教程
- ASP.NET 用MultiView和View实现选项卡效果
- 让Appium支持xcdoe6及其以上版本
- OA项目之Jquery客户端验证
- 位置无关代码码与位置相关代码
- Android应用程序开发之requestWindowFeature()