hdu-4614 Vases and Flowers 成段更新
2014-07-19 17:12
211 查看
题目链接
#include "stdio.h" #include "string.h" #include "queue" #include "vector" #include "algorithm" using namespace std; const int maxn = 50005; const int mod = 10007; const int inf = 1<<30; int n,m; int op,x,y,fir,las,f; struct node { int c; }tree[maxn<<2]; int Pow( int a,int x ) { int ans = 1; for( int i = 1; i <= x; i ++ ) { ans = ( ans*a )%mod; } return ans; } void PushUp( int rt ) { if( tree[rt<<1].c == tree[rt<<1|1].c && tree[rt<<1].c != -1 ) tree[rt].c = tree[rt<<1].c; } void PushDown( int rt ) { if( tree[rt].c != -1 ) { tree[rt<<1].c = tree[rt<<1|1].c = tree[rt].c; tree[rt].c = -1; } } void BuildTree( int rt,int ld,int rd ) { tree[rt].c = 0; if( ld < rd ) { int mid = ( ld+rd )>>1; BuildTree( rt<<1,ld,mid ); BuildTree( rt<<1|1,mid+1,rd ); } } void updata( int rt,int ld,int rd ) { if( f <= 0 ) return; if( x <= ld && rd <= y && tree[rt].c != -1 && f >= ( rd - ld + 1 ) ) { if( tree[rt].c == 0 ){ tree[rt].c = 1; if( fir == -1 ) fir = ld; las = rd; f -= rd - ld + 1; } return; } PushDown( rt ); int mid = ( ld+rd )>>1; if( x <= mid ) updata( rt<<1,ld,mid ); if( y > mid ) updata( rt<<1|1,mid+1,rd ); PushUp( rt ); } int query( int rt,int ld,int rd ) { if( x <= ld && rd <= y && tree[rt].c != -1 ) { if( tree[rt].c == 1 ){ tree[rt].c = 0; return rd - ld + 1; } else return 0; } if( y < ld || x > rd ) return 0; PushDown( rt ); int mid = ( ld+rd )>>1; int l = query( rt<<1,ld,mid ); int r = query( rt<<1|1,mid+1,rd ); PushUp( rt ); return l + r; } int main() { #ifndef ONLINE_JUDGE freopen("data.txt","r",stdin); #endif int cas; scanf("%d",&cas); while( cas -- ) { scanf("%d%d",&n,&m); BuildTree( 1,0,n-1 ); for( int i = 0; i < m; i ++ ) { scanf("%d",&op); if( op == 1 ) { scanf("%d%d",&x,&f); fir = las = -1; y = n-1; updata( 1,0,n-1 ); if( fir == -1 ) puts("Can not put any one."); else printf("%d %d\n",fir,las); } else{ scanf("%d%d",&x,&y); printf("%d\n",query( 1,0,n-1 )); } } puts(""); } return 0; }
相关文章推荐
- hdu 4614 Vases and Flowers(线段树:成段更新)
- HDU 4614 Vases and Flowers 解题报告
- hdu 4614 Vases and Flowers
- HDU 4614 Vases and Flowers
- HDU 4614 Vases and Flowers 线段树 + 二分
- HDU 4614 Vases and Flowers 线段树区间更新
- hdu 4614 Vases and Flowers (线段树+二分)
- hdu 4614 Vases and Flowers
- hdu 4614 Vases and Flowers
- hdu 4614 Vases and Flowers
- 2013 多校联合2 D Vases and Flowers (hdu 4614)
- HDU 4614 Vases and Flowers (2013多校第二场线段树)
- HDU 4614 Vases and Flowers(成端更新 求和 + 二分)转自网络
- HDU 4614 Vases and Flowers(线段树)#by zh
- HDU-4614-Vases and Flowers
- 2013 多校第二场 hdu 4614 Vases and Flowers(线段树)
- 2013 Multi-University Training Contest 1 Vases and Flowers HDU 4614
- HDU-4614 Vases and Flowers 线段树区间更新
- hdu 4614 Vases and Flowers (二分 线段树)
- HDU 4614 Vases and Flowers(线段树+二分)