It’s normal to feel worried and tense the day before a programming contest. To relax, you went out fora drink with some friends in a nearby pub. To keep your mind sharp for the next day, you decided toplay the following game. To start, your friends will give you a sequence of N integers X1, X2, . . . , XN.Then, there will be K rounds; at each round, your friends will issue a command, which can be:• a change command, when your friends want to change one of the values in the sequence; or• a product command, when your friends give you two values I, J and ask you if the productXI × XI+1 × . . . × XJ−1 × XJ is positive, negative or zero.Since you are at a pub, it was decided that the penalty for a wrong answer is to drink a pint ofbeer. You are worried this could affect you negatively at the next day’s contest, and you don’t wantto check if Ballmer’s peak theory is correct. Fortunately, your friends gave you the right to use yournotebook. Since you trust more your coding skills than your math, you decided to write a program tohelp you in the game.

Input

Each test case is
described using several lines. The first line contains two integers N
and K, indicatingrespectively the number of elements in the sequence and
the number of rounds of the game (1 ≤N, K ≤ 105).
The second line contains N integers Xi that represent the initial
values of the sequence(−100 ≤ Xi ≤ 100 for i = 1, 2, . . . , N). Each of
the next K lines describes a command and starts withan uppercase letter
that is either ‘C’ or ‘P’. If the letter is ‘C’,
the line describes a change command, andthe letter is followed by two
integers I and V indicating that XI must receive the value V (1 ≤ I ≤
Nand −100 ≤ V ≤ 100). If the letter is ‘P’, the line describes a product
command, and the letteris followed by two integers
I and J indicating that the product from XI to XJ , inclusive must
becalculated (1 ≤ I ≤ J ≤ N). Within each test case there is at least
one product command.

Output

For each test case output
a line with a string representing the result of all the product
commands inthe test case. The i-th character of the string represents
the result of the i-th product command. If theresult
of the command is positive the character must be ‘+’ (plus); if the
result is negative the charactermust be ‘-’ (minus); if the result is
zero the character must be ‘0’ (zero).

Sample Input

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

Sample Output

0+-

+-+-0

题意:

给出一串数,有两种操作,C,I,V表示将I位置的数改为V;P,I,J表示求I到J位置的所有数的乘积的符号,+,-,0;

代码:

 /*
吧pushup 的求和改为求乘积即可,由于数据较大可以吧正数用1代替,负数用-1,代替,注意线段树数组要多开
大4倍。该题输出是一个一个输出的。
*/
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAX=;
int n,k;
int sum[MAX];
void pushup(int rt)
{
sum[rt]=sum[rt<<]*sum[rt<<|];
}
void build(int l,int r,int rt)
{
if(l==r)
{
scanf("%d",&sum[rt]);
if(sum[rt]>) sum[rt]=;
else if(sum[rt]<) sum[rt]=-;
else sum[rt]=;
return;
}
int mid=(l+r)>>;
build(l,mid,rt<<);
build(mid+,r,rt<<|);
pushup(rt);
}
void update(int id,int val,int l,int r,int rt)
{
if(l==r)
{
sum[rt]=val;
return;
}
int mid=(l+r)>>;
if(id<=mid)
update(id,val,l,mid,rt<<);
else
update(id,val,mid+,r,rt<<|);
pushup(rt);
}
int query(int L,int R,int l,int r,int rt)
{
if(L<=l&&R>=r)
return sum[rt];
int mid=(l+r)>>;
int s=;
if(L<=mid)
s*=query(L,R,l,mid,rt<<);
if(R>mid)
s*=query(L,R,mid+,r,rt<<|);
return s;
}
int main()
{
char ch[];
int I,J;
while(scanf("%d%d",&n,&k)!=EOF)
{
memset(sum,,sizeof(sum));
build(,n,);
while(k--)
{
scanf("%s%d%d",ch,&I,&J);
if(ch[]=='C')
{
if(J>)
update(I,,,n,);
else if(J<)
update(I,-,,n,);
else update(I,,,n,);
}
else if(ch[]=='P')
{
int num=query(I,J,,n,);
if(num>) printf("+");
else if(num<) printf("-");
else printf("");
}
}
printf("\n");
}
return ;
}

UVA12532 线段树(单点更新,区间求乘积的正负)的更多相关文章

  1. POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化)

    POJ.2299 Ultra-QuickSort (线段树 单点更新 区间求和 逆序对 离散化) 题意分析 前置技能 线段树求逆序对 离散化 线段树求逆序对已经说过了,具体方法请看这里 离散化 有些数 ...

  2. HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)

    HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对) 题意分析 给出n个数的序列,a1,a2,a3--an,ai∈[0,n-1],求环序列中逆序对 ...

  3. POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和)

    POJ.3321 Apple Tree ( DFS序 线段树 单点更新 区间求和) 题意分析 卡卡屋前有一株苹果树,每年秋天,树上长了许多苹果.卡卡很喜欢苹果.树上有N个节点,卡卡给他们编号1到N,根 ...

  4. hdu 1166线段树 单点更新 区间求和

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  5. hdu1166(线段树单点更新&区间求和模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1166 题意:中文题诶- 思路:线段树单点更新,区间求和模板 代码: #include <iost ...

  6. hdu2795(线段树单点更新&区间最值)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题意:有一个 h * w 的板子,要在上面贴 n 条 1 * x 的广告,在贴第 i 条广告时要 ...

  7. hihoCoder #1586 : Minimum-结构体版线段树(单点更新+区间最值求区间两数最小乘积) (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1586 : Minimum Time Limit:1000ms Case Time Limit:1000ms Memory Limit:256MB Description You are give ...

  8. HDU 3308 LCIS(线段树单点更新区间合并)

    LCIS Given n integers. You have two operations: U A B: replace the Ath number by B. (index counting ...

  9. 【HDU】1754 I hate it ——线段树 单点更新 区间最值

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  10. hdu 1754 I Hate It 线段树 单点更新 区间最值

    线段树功能:update:单点更新 query:区间最值 #include <bits/stdc++.h> #define lson l, m, rt<<1 #define r ...

随机推荐

  1. json对象的解析

    json对象数据: { "status": "200", "code": "", "msg": &q ...

  2. LoadRunner上传文件脚本

  3. Eclipse如何替换android应用图标

    打开你的项目 我们看到项目里有 res这个文件夹里有以下文件夹. drawable-hdpi     -------高分辨率 drawable-ldpi      -------中分辨率 drawab ...

  4. PHP学习笔记(一)

    by Alina.Xia, dated on 2016.11.27 一.MyAql数据库PHP在开发web站点或管理一些系统时,需要对大量的数据进行保存.XML文件和文本文件虽然可以作为数据的整体,但 ...

  5. 单机c1000k连接

    单机c1000k连接即单机实现百万连接,首先要注意的是连接是虚拟的逻辑的,连接最终落于 网卡,清晰概念才能更深入更清晰的想出问题的解决办法. 参考 http://www.ideawu.net/blog ...

  6. 20145223《Java程序程序设计》第10周学习总结

    20145223<Java网络编程> 一.Java的网络编程 ·网络编程是指编写运行在多个设备(计算机)的程序,这些设备都通过网络连接起来. ·java.net包中J2SE的API包含有类 ...

  7. Delphi中Messagedlg用法

    if MessageDlg('Welcome to my Delphi application. Exit now?', mtConfirmation, [mbYes, mbNo], 0) = mrY ...

  8. iOS 初学UITableView、UITableViewCell、Xib

    注意事项: 1.一个.xib里面最多设置一个cell 2.要仔细调整自动布局,其实它不太好用 3.记得设置<UITableViewDataSource>委托 4.记得在ViewContro ...

  9. Linux crontab 定时任务命令详解

    一.简介 crontab 命令用于设置周期性被执行的指令.该命令从标准输入设备读取指令,并将其存放于 crontab 文件中,以供之后读取和执行.通常,crontab 储存的指令被守护进程激活, cr ...

  10. Python安装pandas

    http://blog.sina.com.cn/s/blog_a73687bc0101eenc.html 安装vcforpython: http://www.microsoft.com/en-us/d ...