• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • YouClaw
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Warm up 13 [I] Interval Product

Interval Product
Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:65536KB
Total submit users: 39, Accepted users: 32
Problem 12756 : No special judgement
Problem description
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 mind sharp for the next day, you decided to play 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 product XI × 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 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.


Input
Each test case is described using several lines. The first line contains two integers N and K, indicating respectively 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 with an uppercase letter that is either "C" or "P". If the letter is "C", the line describes a change command, and the letter is followed by two integers I and V indicating that XI must receive the value V (1 ≤ I ≤ N and -100 ≤ V ≤ 100). If the letter is "P", the line describes a product command, and the letter is followed by two 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 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 in the test case. The i-th character of the string represents the result of the i-th 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 -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
Problem Source
Latin American 2012
 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include <map>
 3 #include <queue>
 4 #include <vector>
 5 #include <string>
 6 #include <cmath>
 7 #include <cstdio>
 8 #include <cstring>
 9 #include <iostream>
10 #include <algorithm>
11 using namespace std;
12 #define maxn 1000005
13 #define mod 1000000007
14 #define ll long long
15 #define INF 0x7fffffff
16 int n, m;
17 int x[maxn];
18 int sum[maxn];
19 void up(int rt){ sum[rt] = sum[rt << 1] * sum[rt << 1 | 1]; }
20 void build(int l, int r, int rt){
21     if (l == r){ scanf("%d", &sum[rt]); if (sum[rt] > 0)sum[rt] = 1; if (sum[rt] < 0)sum[rt] = -1; return; }
22     int m = (l + r) >> 1;
23     build(l, m, rt << 1);
24     build(m + 1, r, rt << 1 | 1);
25     up(rt);
26 }
27 void update(int p, int d, int l, int r, int rt){
28     if (l == r){ if(d>0)
29         sum[rt] = 1;
30         if (d<0)sum[rt] = -1;
31         if (d == 0)sum[rt] = 0;
32         return;
33     }
34     int m = (l + r) >> 1;
35     if (p <= m)update(p, d, l, m, rt << 1);
36     if (p>m)update(p, d, m + 1, r, rt << 1 | 1);
37     up(rt);
38 }
39 int query(int L, int R, int l, int r, int rt){
40     if (L <= l&&R >= r)return sum[rt];
41     int m = (l + r) >> 1;
42     int res = 1;
43     if (L <= m)res *= query(L, R, l, m, rt << 1);
44     if (R>m)res *= query(L, R, m + 1, r, rt << 1 | 1);
45     return res;
46 }
47 int main(){
48     int t;
49     while (~scanf("%d%d", &n,&m)){
50         build(1, n, 1);
51         while (m--){
52             char op[10];
53             int a,b;
54             scanf("%s%d%d", op, &a, &b);
55             if (op[0] == 'C')update(a, b, 1, n, 1);
56             else{
57                 t = query(a, b, 1, n, 1);
58                 if (t == 0)printf("0");
59                 if (t > 0)printf("+");
60                 if (t < 0)printf("-");
61             }
62         }
63         puts("");
64     }
65 }
View Code

 

posted @ 2013-10-26 18:05  HaibaraAi  阅读(138)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3