标签:
http://acm.bnu.edu.cn/v3/problem_show.php?pid=27853
Since you are at a pub, it was decided that the penalty for a wrong answer is to drink a pint of beer. You are worried this could affect you negatively at the next day‘s contest, and you don‘t want to check if Ballmer‘s peak theory is correct. Fortunately, your friends gave you the right to use your notebook. Since you trust more your coding skills than your math, you decided to write a program to help you in the game.
4 6 -2 6 0 -1 C 1 10 P 1 4 C 3 7 P 2 2 C 4 -5 P 1 4 5 9 1 5 -2 4 3 P 1 2 P 1 5 C 4 -5 P 1 5 P 4 5 C 3 0 P 1 5 C 4 -5 C 4 -5
0+- +-+-0
#include<iostream> #include<cstdio> #define maxn 1000005 struct node { int left,right; int num; }tree[3*maxn]; int out=1; void build(int left,int right,int i) { tree[i].left=left; tree[i].right=right; tree[i].num=0; if(tree[i].left==tree[i].right) return ; int mid=(left+right)/2; build(left,mid,2*i); build(mid+1,right,2*i+1); } void insert(int id,int i,int j) { if(tree[id].left==i&&tree[id].right==i) { tree[id].num=j; } if(tree[id].left==tree[id].right) return ; if(i>tree[id].right) return; if(i<tree[id].left) return; int mid=(tree[id].left+tree[id].right)/2; if(i<=mid) insert(id*2,i,j); else insert(id*2+1,i,j); tree[id].num=tree[2*id].num*tree[2*id+1].num; } void sum(int id,int i,int j) { int mid=(tree[id].left+tree[id].right)/2; if(tree[id].left==i&&tree[id].right==j) { out*=tree[id].num; return ; } if(j<=mid) sum(id*2,i,j); else if(i>mid) sum(id*2+1,i,j); else { sum(id*2,i,mid); sum(id*2+1,mid+1,j); } } int main() { int i,x,y,n,m,u,num; while(~ scanf("%d%d",&n,&m)) { char str[1000006]; build(1,n,1); for(i=1;i<=n;i++) { scanf("%d",&u); if(u>0) u=1; else if(u==0) u=0; else u=-1; // printf("u=%d\n",u); insert(1,i,u); } char p; int r=0; for(i=1;i<=m;i++) { // printf("AAA\n"); getchar(); scanf("%c",&p); //printf("p=%c\n",p); if(p==‘C‘) { scanf("%d%d",&x,&y); if(y>0) y=1; else if(y==0) y=0; else y=-1; // printf("y=%d\n",y); //printf("aa\n"); insert(1,x,y); } if(p==‘P‘) { scanf("%d%d",&x,&y); sum(1,x,y); // printf("out=%d\n",out); if(out>0) { str[r++]=‘+‘; // printf("+\n"); } else if(out<0) { str[r++]=‘-‘; // printf("-\n"); } else { str[r++]=‘0‘; // printf("0\n"); } out=1; } } str[r] = ‘\0‘; printf("%s\n",str); } return 0; }
标签:
原文地址:http://www.cnblogs.com/cancangood/p/4712584.html