LibreOJ β Round #2 A
拿到这道题一脸蒙蔽,决策单调性二分处理所有的输入?看来一下数据规模:
1≤x≤n≤10^4 ,0≤m≤10^5
官方题解:直接 O(n2+m)O( n^2 + m )O(n2+m) 暴力即可,大家要知道 LOJ 是非常快的~
(⊙o⊙)…
非常快
非常快
非常快
非常快
非常快
更气的是读入优化忘写负数了,WA了两发。
#pragma GCC optimize("-O2") #include<bits/stdc++.h> #define getchar nc #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define sight(c) ('0'<=c&&c<='9') #define swap(a,b) a^=b,b^=a,a^=b #define LL long long #define deg printf #define dput put #define dputc putchar #define N 10007 #define db double #define eho(x) for(int i=head[x];i;i=net[i]) inline char nc(){ static char buf[1000000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++; } inline void read(int &x){ static char c;static int b; for (b=1,c=getchar();!sight(c);c=getchar())if (c=='-') b=-1; for (x=0;sight(c);c=getchar())x=x*10+c-48; x*=b; } void write(int x){if (x<10) {putchar('0'+x); return;} write(x/10); putchar('0'+x%10);} inline void writeln(int x){ if (x<0) putchar('-'),x*=-1; write(x); putchar('\n'); } inline void writel(int x){ if (x<0) putchar('-'),x*=-1; write(x); putchar(' '); } using namespace std; int a[N],sum[N],f[N],x,n,m; signed main() { read(n); read(m); memset(f,128,sizeof f); for (int i=1;i<=n;i++) read(a[i]),sum[i]=sum[i-1]+a[i]; for (int i=1;i<=n;i++) for (int j=0;j<i;j++) f[i-j]=max(f[i-j],sum[i]-sum[j]); for (int i=n;i;i--) f[i]=max(f[i],f[i+1]); while (m--) read(x),writeln(f[x]); return 0; }