哪位大佬帮我看一下我的问题

P3368 【模板】树状数组 2

@[忠诚的程序猿](/space/show?uid=78791) 我的代码稍长 看看吧 ```cpp #include <cstdio> const int MAXN = 500001; int n,num[MAXN]; class T { public: int t1,t2; T() { t1 = 0; t2 = 0; } }Bit[MAXN]; inline int lowbit(int x) { return x & (-x); } inline void updateL(int Index,int delta) { for(;Index <= n;Index += lowbit(Index)) Bit[Index].t1 += delta; } inline void updateR(int Index,int delta) { for(;Index <= n;Index += lowbit(Index)) Bit[Index].t2 += delta; } inline int SumL(int Index) { int ans = 0; while(Index > 0) { ans += Bit[Index].t1; Index -= lowbit(Index); } return ans; } inline int SumR(int Index) { int ans = 0; while(Index > 0) { ans += Bit[Index].t2; Index -= lowbit(Index); } return ans; } int main() { int i,m; scanf("%d%d",&n,&m); for(i = 1;i <= n;i++) scanf("%d",&num[i]); while(m--) { int Condition; scanf("%d",&Condition); if(Condition == 1) { int L,R,delta; scanf("%d%d%d",&L,&R,&delta); updateL(L,delta); updateR(R,delta); } else { int Index; scanf("%d",&Index); int ans = SumL(Index) - SumR(Index - 1); printf("%d\n",ans + num[Index]); } } return 0; } ```
by resftlmuttmotw @ 2019-02-08 12:27:50


卧槽... 暴力!
by xhhkwy @ 2019-02-08 12:31:27


``` if(k==1) { int x,y,z; scanf("%d%d%d",&x,&y,&z); for(int j=x;j<=y;j++){ put(j,z); } } ``` hhh您是在钓鱼?
by xhhkwy @ 2019-02-08 12:32:42


@[resftlmuttmotw](/space/show?uid=73992) 谢谢大佬!
by Fractures @ 2019-02-08 12:32:49


@[xhhkwy](/space/show?uid=96592) emmmm……确实是有点……
by Fractures @ 2019-02-08 12:33:28


看起来是真的不会呀... 您写树状数组1的时候不会分析复杂度吗
by xhhkwy @ 2019-02-08 12:34:32


我还什么都没说呢???
by xhhkwy @ 2019-02-08 12:34:44


???????
by xhhkwy @ 2019-02-08 12:34:52


@[resftlmuttmotw](/space/show?uid=73992) 代码太强了我居然看不懂……
by Fractures @ 2019-02-08 12:34:53


@[xhhkwy](/space/show?uid=96592) ?????
by Fractures @ 2019-02-08 12:35:16


| 下一页