UVA-12532 Interval Product

Source: Internet
Author: User
Tags rounds uppercase letter

http://acm.bnu.edu.cn/v3/problem_show.php?pid=27853

Interval producttime limit:2000msmemory limit:131072kbthis problem would be judged onUVA. Original id:12532
64-bit integer IO format: %lld Java class name: Main Prevsubmit Status Statistics discuss Next

[PDF Link]

It's normal to feel worried and tense, the day before a programming contest. To relax, you went out for a drink with some friends in a nearby pub. To keep your-the-the-decided to play the following game. To start, your friends would give you a sequence of N integers x1, x2,..., XN. Then, there would be K rounds; At each round, your friends would issue a command, which can be:
    • A change command, when your friends want to change one of the values in the sequence;
    • A product command, when your friends give you II values I, J and ask you if the Prod UCT xI x xi+1 x ... x xJ-1 x xJ is positive, negative or zero.

Since you in a pub, it was decided that the penalty for a wrong answer be to drink a pint of beer. You is worried this could affect your 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 the right to use your notebook. Since you trust more your coding skills than your math, you decided to write a program to the game.

InputEach test case is described using several lines. The first line contains integers Nand K, indicating respectively the number of elements in the sequence and the number of rounds of the game ( 1 N, KThe second line contains NIntegers XI that represent the initial values of the sequence ( -100 XI100 for I= 1, 2,..., N). Each of the next KLines describes a command and starts with the uppercase letter it is either 'C' or 'P‘. If the letter is 'C', the line describes aChange command, and the letter was followed by integers i and V indicating that XI must receive the value V ( 1< C10>i N and -100 V100). If the letter was 'P', the line describes a product command, and the letter was followed by the integers i and J indicating that the product from xI to XJ, inclusive Must be calculated ( 1 I J N). Within each test case there was at least one product command.

output < Span class= "math" > For Each test case output a line with a string representing the result of the the product commands in th E test Case. The i -th character of the string represents the result of the i -t H product command. If The result of the command is positive the character must be ' + ' (plus); If the result is negative, the character must be ' - ' (minus); If the result is zero, the character must be ' 0 ' (zero).

Sample Input

4 6-2 6 0-1c 1 10P 1 4C 3 7P 2 2C 4-5p 1 5-2 4 3P 1 2P 1 5C 4-5p 1 5P 4 5C 3 0P 1 5C 4-5c 4-5

Sample Output

0+-+-+-0
#include <iostream>#include<cstdio>#defineMAXN 1000005structnode{intLeft,right; intnum;} tree[3*MAXN];int  out=1;voidBuildintLeftintRightinti) {Tree[i].left=Left ; Tree[i].right=Right ; Tree[i].num=0; if(tree[i].left==tree[i].right)return ; intMid= (left+right)/2; Build (Left,mid,2*i); Build (Mid+1, right,2*i+1);}voidInsertintIdintIintj) {      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; intMid= (tree[id].left+tree[id].right)/2; if(i<=mid) Insert (ID*2, i,j); ElseInsert (ID*2+1, i,j); Tree[id].num=tree[2*id].num*tree[2*id+1].num;}voidSumintIdintIintj) {    intMid= (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); }}intMain () {intI,x,y,n,m,u,num;  while(~ scanf ("%d%d",&n,&m)) {Charstr[1000006]; Build (1N1);  for(i=1; i<=n;i++) {scanf ("%d",&T); if(u>0) U=1; Else if(u==0) U=0; Elseu=-1; //printf ("u=%d\n", u);Insert1, I,u); }    Charp; intR=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; Elsey=-1; //printf ("y=%d\n", y); //printf ("aa\n");Insert1, 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]=' /'; printf ("%s\n", str); }     return 0;}

UVA-12532 Interval Product

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.