zoukankan      html  css  js  c++  java
  • The Number of Products

    https://vjudge.net/contest/365698#problem/J

    l[i]表示以a[i]为右端点的为负数的情况,r[i]表示为整数。

    转移就是这样:
    if(a[i]<0){
    l[i]=r[i-1]+1;
    r[i]=l[i-1];
    }
    else{
    l[i]=l[i-1];
    r[i]=r[i-1]+1;
    }

    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    #define inf 2147483647
    #define N 1000010
    #define p(a) putchar(a)
    #define For(i,a,b) for(long long i=a;i<=b;++i)
    
    using namespace std;
    long long T;
    long long n,ans;
    long long a[N],l[N],r[N],x,y;
    
    void in(long long &x){
        long long y=1;char c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
        while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
        x*=y;
    }
    void o(long long x){
        if(x<0){p('-');x=-x;}
        if(x>9)o(x/10);
        p(x%10+'0');
    }
    
    signed main(){
        in(n);
        For(i,1,n) in(a[i]);
        For(i,1,n){
            if(a[i]<0){
                l[i]=r[i-1]+1;
                r[i]=l[i-1];
            }
            else{
                l[i]=l[i-1];
                r[i]=r[i-1]+1;
            }
        }
        For(i,1,n){
            x+=l[i];
            y+=r[i];
        }
        o(x);p(' ');o(y);
        return 0;
    }
  • 相关阅读:
    Github国内mirror加速
    通过node-inspector或VSCode调试服务器上代码
    node nvm 常见命令
    HBuilderX 修改默认的终端
    LLVM 工具使用
    LLVM 获取Value Type
    LLVM Constant Value to c++ value
    Bison 命名位置
    llvm block
    vscode use cl.exe build C/C++
  • 原文地址:https://www.cnblogs.com/war1111/p/12628643.html
Copyright © 2011-2022 走看看