题意:

给n个数字的序列,C v p 把v位上的数字置成p , S l r代表求区间[l,r]各数字相乘得数的符号,对于每个S输出所得符号(’+‘,’-‘,’0‘)

分析:

开两个数组表示区间负数的个数、0的个数、当数字被改时,更新数组、查询时区间含0符号是0,再根据负数的个数的奇偶判断。

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
#define N 100010
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int zero[N],neg[N],n,m,a[N];
int sumn(int x){
int num=;
while(x>){
num+=neg[x];
x-=(x&(-x));
}
return num;
}
int sumz(int x){
int num=;
while(x>){
num+=zero[x];
x-=(x&(-x));
}
return num;
}
void add_init(int x){
if(a[x]<=){
int tmp=a[x];
while(x<=n){
if(tmp==)
zero[x]+=;
else
neg[x]+=;
x+=(x&(-x));
}
}
}
void add(int x,int d){
int tmp;
if(a[x]>){
a[x]=d;
if(d<=){
while(x<=n){
if(d<)
neg[x]+=;
else
zero[x]+=;
x+=(x&(-x));
}
}
}
else if(a[x]==){
a[x]=d;
if(d!=){
while(x<=n){
zero[x]-=;
if(d<)neg[x]+=;
x+=(x&(-x));
}
}
}
else{
a[x]=d;
if(d>=){
while(x<=n){
neg[x]-=;
if(d==)zero[x]+=;
x+=(x&(-x));
}
}
}
}
int main()
{
char op[];
string s;
while(~scanf("%d%d",&n,&m)){
s="";
memset(neg,,sizeof(neg));
memset(zero,,sizeof(zero));
int b;
for(int i=;i<=n;++i){
scanf("%d",&a[i]);
add_init(i);
}
/*for(int i=1;i<=n;++i)
cout<<sumn(i)<<" "<<sumz(i)<<endl;*/
int p,v;
while(m--){
scanf("%s%d%d",op,&p,&v);
if(op[]=='C'){
add(p,v);
}
else{
int tmp1=sumn(v)-sumn(p-);
int tmp2=sumz(v)-sumz(p-);
if(tmp2>)
s+='';
else{
if(tmp1%)
s+='-';
else s+='+';
}
}
}
cout<<s<<endl;
}
return ;
}

UVA 12532-Interval Product(BIT)的更多相关文章

  1. UVA 12532 Interval Product

    线段树水题,忽略每个数的大小,只记住他们的正负即可,规规矩矩的代码.不过这是我第一次完全自己写的一次A的代码了.纪念一下... #include <iostream> #include & ...

  2. CJOJ 1071 【Uva】硬币问题(动态规划)

    CJOJ 1071 [Uva]硬币问题(动态规划) Description 有n种硬币,面值分别为v1, v2, ..., vn,每种都有无限多.给定非负整数S,可以选用多少个硬币,使得面值之和恰好为 ...

  3. UVA 575 Skew Binary (水)

    题意:根据这种进制的算法,例如,给你一个左式,要求推出右式.(其实右式就是一个十进制数,根据这种进位的方法来转成特殊进制的数.) 思路:观察转换特点,有点类似于二进制,但是其在后面还减一了.比如25- ...

  4. UVa 1602 网格动物(回溯)

    https://vjudge.net/problem/UVA-1602 题意:计算n连通块不同形态的个数. 思路: 实在是不知道该怎么做好,感觉判重实在是太麻烦了. 判重就是判断所有格子位置是否都相同 ...

  5. Uva 12627 Erratic Expansion(递归)

    这道题大体意思是利用一种递归规则生成不同的气球,问在某两行之间有多少个红气球. 我拿到这个题,一开始想的是递归求解,但在如何递归求解的思路上我的方法是错误的.在研读了例题上给出的提示后豁然开朗(顺便吐 ...

  6. UVA - 11624 J - Fire! (BFS)

    题目传送门 J - Fire! Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the ...

  7. UVA - 11277 Cyclic Polygons(二分)

    题意:已知圆的内接多边形的各个边长,求多边形的面积. 分析: 1.因为是圆的内接多边形,将多边形的每个顶点与圆心相连,多边形的面积就等于被分隔成的各三角形之和. 2.根据海伦公式,任意一个三角形的面积 ...

  8. uva 11059 maximum product(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK

  9. UVa 221城市正视图(离散化)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. Android service的开启和绑定,以及调用service的方法

    界面: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android= ...

  2. 关于C#中timer类

    ·关于C#中timer类 在C#里关于定时器类就有3个 1.定义在System.Windows.Forms里 2.定义在System.Threading.Timer类里 3.定义在System.Tim ...

  3. Error: The VPN client agent was unable to create the interprocess communication depot.

    当安装Cisco AnyConnect VPN Client出现The VPN client agent was unable to create the interprocess communica ...

  4. 浅谈SQL语句优化经验

    (1) 选择最有效率的表名顺序(只在基于规则的seo/' target='_blank'>优化器中有效):ORACLE 的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后 ...

  5. iOS 开发--开源图片处理圆角

    概述 开源项目名称:HYBImageCliped 当前版本:2.0.0 项目用途:可给任意继承UIView的控件添加任意多个圆角.可根据颜色生成图片且可带任意个圆角.给UIButton设置不同状态下的 ...

  6. 244. Shortest Word Distance II

    题目: This is a follow up of Shortest Word Distance. The only difference is now you are given the list ...

  7. HDU5088——Revenge of Nim II(高斯消元&矩阵的秩)(BestCoder Round #16)

    Revenge of Nim II Problem DescriptionNim is a mathematical game of strategy in which two players tak ...

  8. android Json 使用

    http://www.cnblogs.com/mybkn/archive/2012/05/18/2508306.html http://www.cnblogs.com/haippy/archive/2 ...

  9. twitter bootstrap 2.x 3.x区别

    栅格系统 (Grid system)说个我认为比较重要的,相对于RC 1中的3层,现在有4层了 We now have .col-xs (phones), .col-sm (tablets), .co ...

  10. VS2005控制台程序修改nb0文件

    VS2005控制台程序修改nb0文件 我们要实现的功能就是通过CMD传递进来的值来在nb0文件末尾增加版本信息,新建控制台程序,自动生成的main函数如下,默认的代码非常简单: int _tmain( ...