diff --git a/HDOJ/1166.cpp b/HDOJ/1166.cpp new file mode 100644 index 0000000..33f2e73 --- /dev/null +++ b/HDOJ/1166.cpp @@ -0,0 +1,92 @@ +#include +#include +#include +using namespace std; + + +int C[131072]; + +char cmd[32]; + +int getsum(int left,int right,int pos,int leftbound,int rightbound) +{ + if(left<=leftbound&&right>=rightbound) + { + return C[pos]; + } + if(rightrightbound) + { + return 0; + } + int a=getsum(left,right,2*pos+1,leftbound,(leftbound+rightbound)/2); + int b=getsum(left,right,2*pos+2,(leftbound+rightbound)/2+1,rightbound); + return a+b; +} +int main() +{ + int t; + scanf("%d",&t); + for(int itt=1;itt<=t;itt++) + { + printf("Case %d:\n",itt); + int N; + scanf("%d",&N); + int realn=1; + while(realn0) + { + int L=start+1; + for(int i=0;i0) + { + C[pos]+=b; + pos=(pos-1)/2; + } + C[0]+=b; + } + else if(strcmp(cmd,"Sub")==0) + { + int pos=realn-1+a-1; + while(pos>0) + { + C[pos]-=b; + pos=(pos-1)/2; + } + C[0]-=b; + } + } + }/// end of for(...) + + return 0; +}