区间更新中 lazy标记的pushdown操作 风格还是傻崽的...感觉很好用...
/********************* Template ************************/ #include <set> #include <map> #include <list> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <bitset> #include <cstdio> #include <string> #include <vector> #include <cassert> #include <cstdlib> #include <cstring> #include <sstream> #include <fstream> #include <numeric> #include <iomanip> #include <iostream> #include <algorithm> #include <functional> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define BUG cout<<" BUG! "<<endl; #define LINE cout<<" ------------------ "<<endl; #define FIN freopen("in.txt","r",stdin); #define FOUT freopen("out.txt","w",stdout); #define mem(a,b) memset(a,b,sizeof(a)) #define FOR(i,a,b) for(int i = a ; i < b ; i++) #define read(a) scanf("%d",&a) #define read2(a,b) scanf("%d%d",&a,&b) #define read3(a,b,c) scanf("%d%d%d",&a,&b,&c) #define write(a) printf("%d ",a) #define write2(a,b) printf("%d %d ",a,b) #define write3(a,b,c) printf("%d %d %d ",a,b,c) #pragma comment (linker,"/STACK:102400000,102400000") template<class T> inline T L(T a) {return (a << 1);} template<class T> inline T R(T a) {return (a << 1 | 1);} template<class T> inline T lowbit(T a) {return (a & -a);} template<class T> inline T Mid(T a,T b) {return ((a + b) >> 1);} template<class T> inline T gcd(T a,T b) {return b ? gcd(b,a%b) : a;} template<class T> inline T lcm(T a,T b) {return a / gcd(a,b) * b;} template<class T> inline T Min(T a,T b) {return a < b ? a : b;} template<class T> inline T Max(T a,T b) {return a > b ? a : b;} template<class T> inline T Min(T a,T b,T c) {return min(min(a,b),c);} template<class T> inline T Max(T a,T b,T c) {return max(max(a,b),c);} template<class T> inline T Min(T a,T b,T c,T d) {return min(min(a,b),min(c,d));} template<class T> inline T Max(T a,T b,T c,T d) {return max(max(a,b),max(c,d));} template<class T> inline T exGCD(T a, T b, T &x, T &y){ if(!b) return x = 1,y = 0,a; T res = exGCD(b,a%b,x,y),tmp = x; x = y,y = tmp - (a / b) * y; return res; } typedef long long LL; typedef unsigned long long ULL; //typedef __int64 LL; typedef unsigned __int64 ULL; const LL LINF = 1LL << 60; const int MOD = 1000000007; const int INF = 0x7fffffff; const int MAXN = 105000; const double EPS = 1e-8; const double DINF = 1e15; const double PI = acos(-1.0); /********************* By F *********************/ int sum[MAXN*4]; int lazy[MAXN*4]; void pushup(int rt){ sum[rt] = sum[L(rt)] + sum[R(rt)]; } void pushdown(int rt,int val){ if(lazy[rt]){ lazy[L(rt)] = lazy[R(rt)] = lazy[rt]; sum[L(rt)] = (val - (val>>1)) * lazy[rt]; sum[R(rt)] = (val>>1) * lazy[rt]; lazy[rt] = 0; } } void build(int l,int r,int rt){ lazy[rt] = 0; sum[rt] = 1; if(l == r) return; int m = Mid(l,r); build(lson); build(rson); pushup(rt); } void update(int L,int R,int l,int r,int rt,int val){ if(L <= l && R >= r){ lazy[rt] = val; sum[rt] = val * (r-l+1); return; } pushdown(rt,r-l+1); int m = Mid(l,r); if(L <= m) update(L,R,lson,val); if(R > m) update(L,R,rson,val); pushup(rt); } int main(){ //FIN; //FOUT; int T,n,m,x,y,z; read(T); for(int cas = 1 ; cas <= T ; cas++){ read2(n,m); build(1,n,1); while(m--){ read3(x,y,z); update(x,y,1,n,1,z); } printf("Case %d: The total value of the hook is %d. ",cas,sum[1]); } return 0; }