From 85716f1888b4c047c38aa159388090e4854b19fc Mon Sep 17 00:00:00 2001 From: KiritoTRw <3021577574@qq.com> Date: Thu, 11 Aug 2016 09:23:15 +0800 Subject: [PATCH] Create 1698_chendl111.cpp From http://acm.hdu.edu.cn/discuss/problem/post/reply.php?postid=28786&messageid=1&deep=0 --- HDOJ/1698_chendl111.cpp | 59 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 HDOJ/1698_chendl111.cpp diff --git a/HDOJ/1698_chendl111.cpp b/HDOJ/1698_chendl111.cpp new file mode 100644 index 0000000..5e2475e --- /dev/null +++ b/HDOJ/1698_chendl111.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +using namespace std; +#define lchild rt << 1, l, m +#define rchild rt << 1 | 1, m + 1, r +const int N=400010; +int tree[N],lazy[N],t,ans=1,L,R,delta,n,m; + +//区间求和 +void push_up(int rt){ + tree[rt]=tree[rt << 1]+tree[rt << 1 | 1]; +} + +void push_down(int rt, int len) { + if(lazy[rt]) + { + lazy[rt << 1]=lazy[rt << 1 | 1] = lazy[rt]; + tree[rt << 1] = lazy[rt << 1] * (len - (len >> 1)); + tree[rt << 1 | 1] = lazy[rt << 1 | 1] * (len >> 1); + lazy[rt] = 0; + } +} + +void build(int rt = 1, int l = 1, int r = n) { + lazy[rt]=0; + if (l == r) { tree[rt]=1; return; }//注意对树的初始赋值 + int m = (l + r) >> 1; + build(lchild); build(rchild); + push_up(rt); +} + +void update(int L, int R, int delta, int rt = 1, int l = 1, int r = n) { + if (L <= l && r <= R) { + tree[rt] = delta * (r - l + 1);//数据更新 + lazy[rt] = delta; + return; + } + push_down(rt, r - l + 1); + int m = (l + r) >> 1; + if (L <= m) update(L, R, delta, lchild); + if (R > m) update(L, R, delta, rchild); + push_up(rt); +} + +int main() +{ + for(scanf("%d",&t);t--;) + { + scanf("%d%d",&n,&m); + build(); + for(int i=0;i