zoukankan      html  css  js  c++  java
  • ACM

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    
    #define MAX 100010
    using namespace std;
    
    int n,k,qr,ql,v,p;
    
    int father[MAX*4];
    
    char str[MAX * 4];
    int query(int o,int l,int r)
    {
        int m = (l+r) / 2;
        int ans = 1;
        if(ql <= l && r <= qr)
            return father[o];
        if(ql<=m)
            ans*=query(o*2,l,m);
        if(m < qr)
            ans*=query(o*2+1,m+1,r);
        return ans;
    
    }
    
    void change(int o,int l,int r)
    {
        int m = (l+r)/2;
        if(l==r)
            father[o] = v;
        else
        {
            if(p<=m)
                change(o*2,l,m);
            else
                change(o*2+1,m+1,r);
            father[o] = father [o*2]*father [o*2+1];
        }
    }
    void build(int l,int r,int o)
    {
        int m = (l+r)/2;
        if(l==r)
        {
            int t;
            scanf("%d",&t);
            if(t>0)
                father[o] = 1;
            else if(t==0)
                father[o] = 0;
            else if(t<0)
                father[o] = -1;
            return;
        }
        build(l,m,o*2);
        build(m+1,r,o*2+1);
        father[o] = father [o*2] * father [o*2+1];
    }
    
    
    char ans[MAX*4];
    
    int main()
    {
    
        while(~scanf("%d %d",&n,&k))
        {
            build(1,n,1);
            char s[5];
            int c = 0;
            for(int i =0; i < k; i++)
            {
                scanf("%s",s);
                if(s[0] == 'C')
                {
                    scanf("%d%d",&p,&v);
                    if(v > 0)
                        v = 1;
                    else if (v < 0 )
                        v = -1;
                    change(1,1,n);
                }
                else if(s[0]=='P')
                {
                    scanf("%d%d",&ql,&qr);
                    if(query(1,1,n)==0)
                        printf("0");
                    else if(query(1,1,n)>0)
                        printf("+");
                    else if(query(1,1,n)<0)
                        printf("-");
                }
            }
            puts("");
    
    
        }
        return 0;
    }
    View Code
    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



    用个堆来记录就好了



  • 相关阅读:
    eclipse 构建 jpa project 所需的用户库(vendor: EclipseLink)
    <mvc:resources mapping="/xxx/**" location="/xxx/"/>无效,可能和Controller的URL模式有关
    面向对象设计的基本原则
    MySql数据库时区异常,java.sql.SQLException: The server time zone value '?й???׼ʱ?' is unrecognized or represents more than one time zone.
    elasticsearch kibana + 分词器安装详细步骤
    neo4j企业版集群搭建
    Elasticsearchdump 数据导入/导出
    Hive环境搭建和SparkSql整合
    Hadoop 集群搭建和维护文档
    HBase 安装snappy压缩软件以及相关编码配置
  • 原文地址:https://www.cnblogs.com/wejex/p/3390296.html
Copyright © 2011-2022 走看看