首页 > 代码库 > LibreOJ #514. 「LibreOJ β Round #2」模拟只会猜题意
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; }
LibreOJ #514. 「LibreOJ β Round #2」模拟只会猜题意
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。