HDU1556 Color the ball
来源:互联网 发布:一句话webshell 编辑:程序博客网 时间:2024/05/16 11:06
区间更新。。也是模板题
还有一种前缀和的办法,更加easy,就不写了
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<cmath>#include<algorithm>using namespace std;#define ll long long#define ull unsigned long long#define eps 1e-8#define inf 0x3f3f3f3f#define lson l, m, rt << 1#define rson m+1, r, rt << 1 | 1#define mnx 111111int sum[mnx<<2], col[mnx<<2], ret;void pushup( int rt ){sum[rt] = sum[rt<<1] + sum[rt<<1|1];}void pushdown( int rt, int m ){if( col[rt] ){col[rt<<1] += col[rt];col[rt<<1|1] += col[rt];sum[rt<<1] += ( m - ( m >> 1 ) ) * col[rt];sum[rt<<1|1] += ( m >> 1 ) * col[rt];col[rt] = 0;}}void update( int L, int R, int c, int l, int r, int rt ){if( L <= l && R >= r ){col[rt] += c;sum[rt] += ( r - l + 1 ) * c;return ;}//pushdown( rt, r-l+1 ); 最后一起更新。。 int m = ( l + r ) >> 1;if( L <= m ) update( L, R, c, lson );if( R > m ) update( L, R, c, rson );pushup( rt );}int find( int L, int R, int l, int r, int rt ){if( L <= l && R >= r ){return sum[rt];}pushdown( rt, r-l+1 ); // 如果把pushdown()放在if的前面,sum[]和col[] 要开 mnx<<3,否则会wa int m = ( l + r ) >> 1;if( L <= m ) ret = find( L, R, lson );if( R > m ) ret = find( L, R, rson );return ret;}int main(){int n, l, r;while( scanf( "%d", &n ) && n ){memset( sum, 0, sizeof(sum) );memset( col, 0, sizeof(col) );for( int i = 0; i < n; i++ ){scanf( "%d%d", &l, &r );update( l, r, 1, 1, n, 1 );}printf( "%d", find( 1, 1, 1, n, 1 ) );for( int i = 2; i <= n; i++ ){printf( " %d", find( i, i, 1, n, 1 ) );}cout<<endl;}return 0;}
0 0
- hdu1556 color the ball
- hdu1556 Color the ball
- hdu1556 Color the ball
- hdu1556 Color the ball
- HDU1556 Color the ball
- hdu1556 Color the ball
- hdu1556--Color the ball
- Color the ball HDU1556
- HDU1556 Color the ball
- hdu1556 Color the ball
- HDU1556-----Color the ball
- hdu1556 Color the Ball
- HDU1556-color the ball
- HDU1556 Color the ball
- hdu1556 Color the ball
- Color the ball||HDU1556
- HDU1556 Color the ball
- HDU1556 Color the ball(线段树)
- 【DFS】DLUToj-1215-组合数字
- HDU 4407
- cocos2dx 3.0正式版 在mac上新建项目
- CCNP路由实验之六 动态路由协议之IS-IS
- Android下生成pdf并显示中文
- HDU1556 Color the ball
- 探究 C++ Singleton(单例模式)
- Yii控制器的高级写法
- javascript模式之--迭代器模式
- centos6.4 rpm rabbitmq安装
- PHPCMS模版解析之TEMPLATE函数
- 实现自定义android柱状图控件!可显示气温!可相应点击事件的回调!
- 人生絮语
- Ubuntu 12.04 安装JDK 8和Eclipse