码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #585 (Div. 2)

时间:2020-01-22 20:22:03      阅读:97      评论:0      收藏:0      [点我收藏+]

标签:for   pac   type   code   names   print   ble   open   inf   


B. The Number of Products
递推:ne[i]表示以ai结尾的负区间个数,po[i]表示以ai结尾的负区间个数

/**/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <queue>

typedef long long LL;
typedef unsigned long long ULL;
using namespace std;

bool Sqrt(LL n) { return (LL)sqrt(n) * sqrt(n) == n; }
const double PI = acos(-1.0), ESP = 1e-10;
const LL INF = 99999999999999;
const int inf = 999999999, N = 2e5 + 24;
int n;
LL a[N], po[N], ne[N];

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    while(scanf("%d", &n) == 1) {
        for(int i = 0; i < n; i++) scanf("%lld", &a[i]);
        memset(po, 0, sizeof po); 
        memset(ne, 0, sizeof ne);
        if(a[0] < 0) ne[0] = 1;
        else po[0] = 1;
        for(int i = 1; i < n; i++) {
            if(a[i] < 0) {
                po[i] = ne[i - 1];
                ne[i] = po[i - 1] + 1;
            }
            else {
                po[i] = po[i - 1] + 1;
                ne[i] = ne[i - 1];
            }
        }
        for(int i = 0; i < n; i++) {
            po[n] += po[i];
            ne[n] += ne[i];
        }
        printf("%lld %lld\n", ne[n], po[n]);
    }

    return 0;
}
/*
    input:
    output:
    modeling:
    methods:
    complexity:
    summary:
*/

Codeforces Round #585 (Div. 2)

标签:for   pac   type   code   names   print   ble   open   inf   

原文地址:https://www.cnblogs.com/000what/p/12229358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!