LibreOJ #514. 「LibreOJ β Round #2」模拟只会猜题意

二次联通门 : LibreOJ #514. 「LibreOJ β Round #2」模拟只会猜题意

 

 

 

 

/*

    LibreOJ #514. 「LibreOJ β Round #2」模拟只会猜题意
 
    本想打个暴力找找规律
    结果交上去就A了。。。
    
    读入所有数
    处理出前缀和
    
    然后枚举区间长度
    处理处1~n的答案
    后O(1)查询即可
    复杂度O(n^2 + m) 
*/
#include <iostream>
#include <cstring>
#include <cstdio>

void read (int &now)
{
    register char word = getchar ();
    int temp = 0;
    for (now = 0; !isdigit (word); word = getchar ())
        if (word == '-')
            temp = 1;
    for (; isdigit (word); now = now * 10 + word - '0', word = getchar ());
    if (temp)
        now = -now;
}

#define Max 100060

int number[Max];
int Answer[Max];

int sum[Max];

inline int max (int a, int b)
{
    return a > b ? a : b;
}

int main (int argc, char *argv[])
{
    int N, M;
    read (N);
    read (M);
    
    memset (Answer, -0x3f, sizeof Answer);
    
    register int i, j;
    for (i = 1; i <= N; ++ i)
    {
        read (number[i]);
        sum[i] = sum[i - 1] + number[i];
    }

    int Maxn = Answer[0];
    for (i = 1; i <= N; ++ i)
        for (j = 1; i + j - 1 <= N; ++ j)
            Answer[i] = max (Answer[i], sum[i + j - 1] - sum[j - 1]);
    
    for (i = N; i; -- i)
    {
        Maxn = max (Maxn, Answer[i]);
        Answer[i] = max (Answer[i], Maxn);
    }
    
    for (int x; M; -- M)
    {
        read (x);
        printf ("%d\n", Answer[x]);
    }
    return 0;
} 

 

posted @ 2017-08-08 21:36  ZlycerQan  阅读(192)  评论(0编辑  收藏  举报