首页 > 代码库 > Codeforces 21C Stripe 2 卧槽,出题人母语绝对不是English啊

Codeforces 21C Stripe 2 卧槽,出题人母语绝对不是English啊

sum = sigma num[i] (1 <= i <= n)。

s[i] = sigam num[j] (1<= j <= i)。

找到所有满足s[i]*2 =sum-s[i] ,s[i] = 2*(sum-s[i])。然后枚举累加一下。

卧槽,可是题意里明明说每个 piece 里 都要有positive interge。

可是去了这个限制就过了啊。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <ctime>
#include <iomanip>

#pragma comment(linker, "/STACK:1024000000");
#define EPS (1e-6)
#define _LL long long
#define ULL unsigned long long
#define LL __int64
#define INF 0x3f3f3f3f
#define Mod 1000000007

/** I/O Accelerator Interface .. **/
#define g (c=getchar())
#define d isdigit(g)
#define p x=x*10+c-'0'
#define n x=x*10+'0'-c
#define pp l/=10,p
#define nn l/=10,n
template<class T> inline T& RD(T &x)
{
    char c;
    while(!d);
    x=c-'0';
    while(d)p;
    return x;
}
template<class T> inline T& RDD(T &x)
{
    char c;
    while(g,c!='-'&&!isdigit(c));
    if (c=='-')
    {
        x='0'-g;
        while(d)n;
    }
    else
    {
        x=c-'0';
        while(d)p;
    }
    return x;
}
inline double& RF(double &x)      //scanf("%lf", &x);
{
    char c;
    while(g,c!='-'&&c!='.'&&!isdigit(c));
    if(c=='-')if(g=='.')
        {
            x=0;
            double l=1;
            while(d)nn;
            x*=l;
        }
        else
        {
            x='0'-c;
            while(d)n;
            if(c=='.')
            {
                double l=1;
                while(d)nn;
                x*=l;
            }
        }
    else if(c=='.')
    {
        x=0;
        double l=1;
        while(d)pp;
        x*=l;
    }
    else
    {
        x=c-'0';
        while(d)p;
        if(c=='.')
        {
            double l=1;
            while(d)pp;
            x*=l;
        }
    }
    return x;
}
#undef nn
#undef pp
#undef n
#undef p
#undef d
#undef g
using namespace std;

LL num[100010];
LL ans[2][100010] = {{0},{0}};
LL sum[2][100010] = {{0},{0}};
LL dis[100010] = {0};

int mark[2][100010] = {{0},{0}};

int main()
{
    int n;

    scanf("%d",&n);

    int i;

    for(i = 1;i <= n; ++i)
        scanf("%I64d",&num[i]);

    for(i = 1;i <= n; ++i)
        sum[0][i] = sum[0][i-1] + num[i];
    for(i = n;i >= 1; --i)
        sum[1][i] = sum[1][i+1] + num[i];

    for(i = 1;i <= n; ++i)
            ans[0][i] = ans[0][i-1] + (num[i] >= 0 ? 1 : 0);
    for(i = n;i >= 1; --i)
            ans[1][i] = ans[1][i+1] + (num[i] >= 0 ? 1 : 0);

    LL S = sum[0][n];

    for(i = 1;i <= n; ++i)
        if(sum[0][i]*2 == S-sum[0][i] )
            mark[0][i] = 1;
    for(i = n;i >= 1; --i)
        if(sum[1][i]*2 == S-sum[1][i])
            mark[1][i] = 1;
    for(i = 1;i <= n; ++i)
        dis[i] = dis[i-1] + mark[0][i];

    LL anw = 0;

    for(i = 2;i <= n; ++i)
        if(mark[1][i])
            anw += dis[i-2];
    printf("%I64d\n",anw);
    return 0;
}
















Codeforces 21C Stripe 2 卧槽,出题人母语绝对不是English啊