标签:查询 bsp string namespace col names || fine cas
hdu1698
http://acm.hdu.edu.cn/showproblem.php?pid=1698
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define E 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e5+10; 25 26 int tag[maxn<<2],sum[maxn<<2]; 27 28 void push_down(int index,int len) 29 { 30 tag[index<<1]=tag[index<<1|1]=tag[index]; 31 sum[index<<1]=((len+1)>>1)*tag[index]; 32 sum[index<<1|1]=(len>>1)*tag[index]; 33 tag[index]=0; 34 } 35 36 void build(int index,int l,int r) 37 { 38 tag[index]=0; 39 if (l==r) 40 sum[index]=1; 41 else 42 { 43 int m=(l+r)>>1; 44 build(index<<1,l,m); 45 build(index<<1|1,m+1,r); 46 sum[index]=sum[index<<1]+sum[index<<1|1]; 47 } 48 } 49 50 void update(int index,int l,int r,int s,int t,int v) 51 { 52 if (s<=l && r<=t) 53 { 54 tag[index]=v; 55 sum[index]=(r-l+1)*v; 56 return; 57 } 58 if (tag[index]!=0) 59 push_down(index,r-l+1); 60 int m=(l+r)>>1; 61 if (s<=m) 62 update(index<<1,l,m,s,t,v); 63 if (m<t) 64 update(index<<1|1,m+1,r,s,t,v); 65 sum[index]=sum[index<<1]+sum[index<<1|1]; 66 } 67 68 int query(int index,int l,int r,int s,int t) 69 { 70 if (s<=l && r<=t) 71 return sum[index]; 72 if (tag[index]!=0) 73 push_down(index,r-l+1); 74 if (r<s || l>t) 75 return 0; 76 else 77 { 78 int m=(l+r)>>1; 79 return query(index<<1,l,m,s,t)+query(index<<1|1,m+1,r,s,t); 80 } 81 } 82 83 int main() 84 { 85 int t,T,n,q,x,y,v; 86 scanf("%d",&t); 87 for (T=1;T<=t;T++) 88 { 89 scanf("%d",&n); 90 build(1,1,n); 91 scanf("%d",&q); 92 while (q--) 93 { 94 scanf("%d%d%d",&x,&y,&v); 95 update(1,1,n,x,y,v); 96 } 97 printf("Case %d: The total value of the hook is %d.\n",T,query(1,1,n,1,n)); 98 } 99 return 0; 100 }
标签:查询 bsp string namespace col names || fine cas
原文地址:https://www.cnblogs.com/cmyg/p/9516635.html