The Preliminary Contest for ICPC China Nanchang National Invitational
Contest Info
[Practice Link](https://www.jisuanke.com/contest/2290?view=challenges)
Solved | A | B | C | D | E | F | G | H | I | J | K | L | M |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
8/13 | O | - | - | O | - | - | O | O | O | O | O | - | O |
- O 在比赛中通过
- Ø 赛后通过
- ! 尝试了但是失败了
- - 没有尝试
Solutions
A. PERFECT NUMBER PROBLEM
签到题。
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[] = {
6, 28, 496, 8128, 33550336
};
for (int i = 0; i < 5; ++i) {
printf("%d\n", a[i]);
}
return 0;
}
D. Match Stick Game
G. tsy's number
H. Coloring Game'
I. Max answer
题意:
定义一个区间\([l, r]\)的值为:
f(l, r) = (max_{i = l}^r a_i) \cdot (\sum\limits_{i = l}^r a_i)
\end{eqnarray*}
\]
思路一:
单调栈求出当前点左边第一个比它小的位置,当前点右边第一个比它小的位置。
然后就算出管辖范围,然后线段树维护一下最大最小区间前后缀即可。
代码一:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 500010
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
int n, a[N];
ll sum[N];
int f[N], g[N];
int Sta[N], top;
struct SEG {
struct node {
ll Max, Min;
node () {
Min = INFLL;
Max = -INFLL;
}
node (ll Max, ll Min) : Max(Max), Min(Min) {}
node operator + (const node &other) const {
node res = node();
res.Max = max(Max, other.Max);
res.Min = min(Min, other.Min);
return res;
}
}t[N << 2], res;
void build(int id, int l, int r) {
if (l == r) {
t[id] = node(sum[l], sum[l]);
return;
}
int mid = (l + r) >> 1;
build(id << 1, l, mid);
build(id << 1 | 1, mid + 1, r);
t[id] = t[id << 1] + t[id << 1 | 1];
}
void query(int id, int l, int r, int ql, int qr) {
if (ql > qr) {
return;
}
if (l >= ql && r <= qr) {
res = res + t[id];
return;
}
int mid = (l + r) >> 1;
if (ql <= mid) query(id << 1, l, mid, ql, qr);
if (qr > mid) query(id << 1 | 1, mid + 1, r, ql, qr);
}
}seg;
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
}
for (int i = 1; i <= n; ++i) {
sum[i] = sum[i - 1] + a[i];
}
seg.build(1, 1, n);
ll res = 0;
a[0] = a[n + 1] = -INF;
top = 0;
Sta[++top] = 0;
for (int i = 1; i <= n; ++i) {
while (a[i] <= a[Sta[top]]) {
--top;
}
f[i] = Sta[top];
Sta[++top] = i;
}
top = 0;
Sta[++top] = n + 1;
for (int i = n; i >= 1; --i) {
while (a[i] <= a[Sta[top]]) {
--top;
}
g[i] = Sta[top];
Sta[++top] = i;
}
// for (int i = 1; i <= n; ++i) {
// printf("%d %d %d\n", i, f[i], g[i]);
// }
for (int i = 1; i <= n; ++i) {
if (a[i] == 0) {
continue;
} else if (a[i] < 0) {
seg.res = SEG::node();
ll x = 0, y = 0;
seg.query(1, 1, n, f[i], i);
if (f[i] == 0) {
x = max(x, seg.res.Max);
} else {
x = seg.res.Max;
}
seg.res = SEG::node();
seg.query(1, 1, n, i, g[i] - 1);
y = seg.res.Min;
res = max(res, (y - x) * a[i]);
} else {
seg.res = SEG::node();
ll x = 0, y = 0;
seg.query(1, 1, n, f[i], i);
if (f[i] == 0) {
x = min(x, seg.res.Min);
} else {
x = seg.res.Min;
}
seg.res = SEG::node();
seg.query(1, 1, n, i, g[i] - 1);
y = seg.res.Max;
res = max(res, (y - x) * a[i]);
}
}
printf("%lld\n", res);
}
return 0;
}
思路二:
建出笛卡尔树,然后就确定了区间最小值,再考虑中序遍历是原序列。
那么左右子树分别维护区间和、区间最大最小前后缀,然后向上统计答案并合并
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 500010
#define INF 0x3f3f3f3f
int n, a[N];
ll res;
struct Cartesian_Tree {
struct node {
int id, val, fa;
// 0 前缀最值
// 1 后缀最值
ll Min[2], Max[2], sum;
int son[2];
node() {}
node (int id, int val, int fa) : id(id), val(val), fa(fa) {
memset(son, 0, sizeof son);
memset(Min, 0, sizeof Min);
memset(Max, 0, sizeof Max);
sum = 0;
}
bool operator < (const node &other) const {
return id < other.id;
}
}t[N];
int root;
void init() {
t[0] = node(0, -INF, 0);
}
void build(int n, int *a) {
for (int i = 1; i <= n; ++i) {
t[i] = node(i, a[i], 0);
}
for (int i = 1; i <= n; ++i) {
int k = i - 1;
while (t[k].val > t[i].val) {
k = t[k].fa;
}
t[i].son[0] = t[k].son[1];
t[k].son[1] = i;
t[i].fa = k;
t[t[i].son[0]].fa = i;
}
root = t[0].son[1];
}
void DFS(int u) {
if (!u) return;
int ls = t[u].son[0], rs = t[u].son[1];
DFS(ls); DFS(rs);
res = max(res, t[u].val * (t[u].val + t[ls].Min[1] + t[rs].Min[0]));
res = max(res, t[u].val * (t[u].val + t[ls].Max[1] + t[rs].Max[0]));
t[u].sum = t[ls].sum + t[rs].sum + t[u].val;
t[u].Min[0] = min(t[ls].Min[0], t[ls].sum + t[u].val + t[rs].Min[0]);
t[u].Min[1] = min(t[rs].Min[1], t[rs].sum + t[u].val + t[ls].Min[1]);
t[u].Max[0] = max(t[ls].Max[0], t[ls].sum + t[u].val + t[rs].Max[0]);
t[u].Max[1] = max(t[rs].Max[1], t[rs].sum + t[u].val + t[ls].Max[1]);
}
}CT;
int main() {
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
}
res = -1e18;
CT.init();
CT.build(n, a);
CT.DFS(CT.root);
printf("%lld\n", res);
}
return 0;
}
J. Distance on the tree
K. MORE XOR
M. Subsequence
题意:
给出串\(S\),以及若干串\(T_i\),每次询问\(T_i\)是否是\(S\)的一个子序列。
思路:
建出序列自动机,暴力跑即可。
时间复杂度:\(\mathcal{O}(26|S| + \sum T_i)\)
代码:
#include <bits/stdc++.h>
using namespace std;
#define N 100010
int n, m, q;
char s[N], t[N];
int T[N][30], nx[30];
int main() {
while (scanf("%s", s + 1) != EOF) {
n = strlen(s + 1);
for (int i = 0; i < 30; ++i) nx[i] = n + 1;
for (int i = n; i >= 0; --i) {
for (int j = 0; j < 26; ++j) {
T[i][j] = nx[j];
}
if (i) {
nx[s[i] - 'a'] = i;
}
}
scanf("%d", &q);
while (q--) {
scanf("%s", t + 1);
m = strlen(t + 1);
int it = 0;
for (int i = 1; i <= m; ++i) {
it = T[it][t[i] - 'a'];
if (it == n + 1) break;
}
puts(it == n + 1 ? "NO" : "YES");
}
}
return 0;
}
The Preliminary Contest for ICPC China Nanchang National Invitational的更多相关文章
- 2019The Preliminary Contest for ICPC China Nanchang National Invitational
The Preliminary Contest for ICPC China Nanchang National Invitational 题目一览表 考察知识点 I. Max answer 单调栈+ ...
- 计蒜客 38229.Distance on the tree-1.树链剖分(边权)+可持久化线段树(区间小于等于k的数的个数)+离散化+离线处理 or 2.树上第k大(主席树)+二分+离散化+在线查询 (The Preliminary Contest for ICPC China Nanchang National Invitational 南昌邀请赛网络赛)
Distance on the tree DSM(Data Structure Master) once learned about tree when he was preparing for NO ...
- The Preliminary Contest for ICPC China Nanchang National Invitational I. Max answer (单调栈+线段树)
题目链接:https://nanti.jisuanke.com/t/38228 题目大意:一个区间的值等于该区间的和乘以区间的最小值.给出一个含有n个数的序列(序列的值有正有负),找到该序列的区间最大 ...
- The Preliminary Contest for ICPC China Nanchang National Invitational and International Silk-Road Programming Contest
打网络赛 比赛前的准备工作要做好 确保 c++/java/python的编译器能用 打好模板,放在桌面 A. PERFECT NUMBER PROBLEM #include <cstdio> ...
- The Preliminary Contest for ICPC China Nanchang National Invitational I题
Alice has a magic array. She suggests that the value of a interval is equal to the sum of the values ...
- Max answer(The Preliminary Contest for ICPC China Nanchang National Invitational)
Alice has a magic array. She suggests that the value of a interval is equal to the sum of the values ...
- The Preliminary Contest for ICPC China Nanchang National Invitational I.Max answer单调栈
题面 题意:一个5e5的数组,定义一个区间的值为 这个区间的和*这个区间的最小值,注意数组值有负数有正数,求所有区间中最大的值 题解:如果全是正数,那就是原题 POJ2796 单调栈做一下就ok 我们 ...
- 2019 The Preliminary Contest for ICPC China Nanchang National Invitational(A 、H 、I 、K 、M)
A. PERFECT NUMBER PROBLEM 题目链接:https://nanti.jisuanke.com/t/38220 题意: 输出前五个完美数 分析: 签到.直接百度完美数输出即可 #i ...
- 计蒜客 38228. Max answer-线段树维护单调栈(The Preliminary Contest for ICPC China Nanchang National Invitational I. Max answer 南昌邀请赛网络赛) 2019ICPC南昌邀请赛网络赛
Max answer Alice has a magic array. She suggests that the value of a interval is equal to the sum of ...
随机推荐
- Thymeleaf模板引擎与springboot关联后,在html中无法使用el表达式获取model存的值
头部引入了thymeleaf <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thy ...
- python多线程爬取斗图啦数据
python多线程爬取斗图啦网的表情数据 使用到的技术点 requests请求库 re 正则表达式 pyquery解析库,python实现的jquery threading 线程 queue 队列 ' ...
- ubuntu下安装软件时报错解决:Unmet dependencies. Try 'apt-get -f install' with no packages
在错误后面运行以下代码,补全依赖项: sudo apt-get -f install
- 基于【 责任链模式】二 || 网关zuul过滤器封装
一.基于责任链模式封装网关拦截 上一篇文章中已经使用建造者模式对网关拦截进行封装,存在一个问题,在连接器build中,每一个拦截都要进行true判断,代码看起来冗余,下面使用责任链模式封装 1.基于责 ...
- putty使用方法
putty是一种体体积小,无需安装的一款免费安全使用方便的绿色软件,它主要用于远程控制linux系统,只要获取了远程的linux的地址,便可以远程控制linux系统以方便管理,越来越受到各方面的欢迎. ...
- Xcode11.1 踩坑备忘录
Xcode11.1 踩坑备忘录(mac系统10.15) 1 .环信ChatDemo2.0报错 这是环信ChatDemo2.0报错 NSInteger numberOfBeforeSection = [ ...
- linux sort命令用法
sort命令:用于将文本文件内容加以排序,sort可针对文本文件的内容,以行为单位来排序. 命令格式: sort [-bcdfimMnr][-o<输出文件>][-t<分隔字符> ...
- GitHub开源的10个超棒后台管理面板
目录1.AdminLTE 2.vue-Element-Admin 3.tabler 4.Gentelella 5.ng2-admin 6.ant-design-pro 7.blur-admin 8.i ...
- springboot系列(六) 使用模板引擎
这里就转载一篇大牛的文章 https://blog.csdn.net/caychen/article/details/79625927 这篇文章详细介绍了thymeleaf和freemarker引擎木 ...
- servlet版本与tomcat版本对应关系,各版本web.xml头信息写法
The mapping between the specifications and the respective Apache Tomcat versions is: Servlet Spec JS ...