MemSQL Start[c]UP 2.0 - Round 1 F - Permutation 思维+线段树维护hash值
思路:对于当前的值x, 只需要知道x + k, x - k这两个值是否出现在其左右两侧,又因为每个值只有一个,
所以可以转换成,x+k, x-k在到x所在位置的时候是否都出现,或者都不出现,即出现情况相等,我们可以
用线段树维护hash值的方式来判断所有x+k, x-k的出现情况是否都一样。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define PLI pair<LL, int>
#define ull unsigned long long
using namespace std; const int N = 3e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int n;
ull Pow[N];
struct segmentTree {
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
struct info1 {
ull hs; int len;
info1 operator + (const info1 &rhs) {
return info1{hs+rhs.hs*Pow[len], len+rhs.len};
}
} a[N<<];
struct info2 {
ull hs; int len;
info2 operator + (const info2 &rhs) {
return info2{rhs.hs+hs*Pow[rhs.len], len+rhs.len};
}
} b[N<<];
void build(int l, int r, int rt) {
if(l == r) {
a[rt] = info1{, };
b[rt] = info2{, };
return;
}
int mid = l + r >> ;
build(lson); build(rson);
a[rt] = a[rt<<] + a[rt<<|];
b[rt] = b[rt<<] + b[rt<<|];
}
void update(int p, int l, int r, int rt) {
if(l == r) {
a[rt] = info1{, };
b[rt] = info2{, };
return ;
}
int mid = l + r >> ;
if(p <= mid) update(p, lson);
else update(p, rson);
a[rt] = a[rt<<] + a[rt<<|];
b[rt] = b[rt<<] + b[rt<<|];
}
info1 querya(int L, int R, int l, int r, int rt) {
if(l >= L && r <= R) return a[rt];
int mid = l + r >> ;
if(R <= mid) return querya(L, R, lson);
else if(L > mid) return querya(L, R, rson);
else return querya(L, R, lson) + querya(L, R, rson);
}
info2 queryb(int L, int R, int l, int r, int rt) {
if(l >= L && r <= R) return b[rt];
int mid = l + r >> ;
if(R <= mid) return queryb(L, R, lson);
else if(L > mid) return queryb(L, R, rson);
else return queryb(L, R, lson) + queryb(L, R, rson);
}
} seg; int main() {
for(int i=Pow[]=; i < N; i++) Pow[i]=Pow[i-]*;
scanf("%d", &n);
seg.build(, n, );
bool flag = false;
for(int i = ; i <= n; i++) {
int x; scanf("%d", &x);
int len = min(x-, n-x);
if(len && seg.querya(x-len, x-, , n, ).hs != seg.queryb(x+, x+len, , n, ).hs)
flag = true;
seg.update(x, , n, );
}
if(flag) puts("YES");
else puts("NO");
return ;
} /*
*/
MemSQL Start[c]UP 2.0 - Round 1 F - Permutation 思维+线段树维护hash值的更多相关文章
- Codeforces Round #321 (Div. 2) E Kefa and Watch (线段树维护Hash)
E. Kefa and Watch time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #271 (Div. 2) E题 Pillars(线段树维护DP)
题目地址:http://codeforces.com/contest/474/problem/E 第一次遇到这样的用线段树来维护DP的题目.ASC中也遇到过,当时也非常自然的想到了线段树维护DP,可是 ...
- Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake 线段树维护dp
D. Babaei and Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/D Description As you ...
- Educational Codeforces Round 6 E dfs序+线段树
题意:给出一颗有根树的构造和一开始每个点的颜色 有两种操作 1 : 给定点的子树群体涂色 2 : 求给定点的子树中有多少种颜色 比较容易想到dfs序+线段树去做 dfs序是很久以前看的bilibili ...
- Educational Codeforces Round 47 (Rated for Div. 2)F. Dominant Indices 线段树合并
题意:有一棵树,对于每个点求子树中离他深度最多的深度是多少, 题解:线段树合并快如闪电,每个节点开一个权值线段树,递归时合并即可,然后维护区间最多的是哪个权值,到x的深度就是到根的深度减去x到根的深度 ...
- 2018.9 ECNU ICPC/CCPC Trial Round #2 Query On Tree (树链剖分+线段树维护)
传送门:https://acm.ecnu.edu.cn/contest/105/problem/Q/ 一棵树,支持两种操作:给一条路径上的节点加上一个等差数列;求两点路径上节点和. 很明显,熟练剖分. ...
- MemSQL Start[c]UP 2.0 - Round 1(无聊练手B题)
http://codeforces.com/contest/452/problem/B B. 4-point polyline time limit per test 2 seconds memo ...
- MemSQL Start[c]UP 2.0 - Round 2 - Online Round
搞到凌晨4点一个没出,要gg了. A. Golden System http://codeforces.com/contest/458/problem/A #include<cstdio> ...
- MemSQL Start[c]UP 2.0 - Round 1
A. Eevee http://codeforces.com/contest/452/problem/A 字符串水题 #include<cstdio> #include<cstrin ...
随机推荐
- python使用数组作为索引遍历数组
python使用数组作为索引遍历数组 觉得有用的话,欢迎一起讨论相互学习~Follow Me python使用数组作为索引遍历数组 import numpy as np a=np.arange(0,5 ...
- windows下使用tftp工具下载文件到开发板(linux)
1.下载tftp工具,也可以上CSDN找个免费0积分的 http://www.52z.com/soft/11886.html 2.确保开发板和windows在同一网段 比如192.168.101.*段 ...
- static的局限
static 的缺陷: 1.它只能调用static 变量. 2.它只能调用static方法. 3.不能引用this super 4.static变量在定义时必须初始化,且初始化的时间要早于非静态变量 ...
- C++程序运行时间测定
From:http://www.cnblogs.com/killerlegend/p/3877703.html Author:KillerLegend Date:2014.7.30 此处程序的测试时间 ...
- [USACO5.3]量取牛奶Milk Measuring
https://daniu.luogu.org/problemnew/show/P2744 滚动数组压去第一维:前i种木桶 f[j] 量取体积j最少需要几种木桶 g[j] 体积j的最优解是否使用了第 ...
- Golang入门教程(一)GOPATH与工作空间(Windows)
https://github.com/astaxie/build-web-application-with-golang/blob/master/zh/01.2.md Windows 环境: 下面我就 ...
- HDU 1160 FatMouse's Speed (最长上升子序列)
题目链接 题意:n个老鼠有各自的重量和速度,要求输出最长的重量依次严格递增,速度依次严格递减的序列,n最多1000,重量速度1-10000. 题解:按照重量递增排序,找出最长的速度下降子序列,记录序列 ...
- Pythagorean Triples(Codeforces Round #368 (Div. 2) + 构建直角三角形)
题目链接: https://codeforces.com/contest/707/problem/C 题目: 题意: 告诉你直角三角形的一条边,要你输出另外两条边. 思路: 我们容易发现除2外的所有素 ...
- EOJ Monthly 2019.2 (based on February Selection) D.进制转换
题目链接: https://acm.ecnu.edu.cn/contest/140/problem/D/ 题目: 思路: 我们知道一个数在某一个进制k下末尾零的个数x就是这个数整除kx,这题要求刚好末 ...
- 20155303狄惟佳预备作业三Linux学习笔记
20155303狄惟佳预备作业三Linux学习笔记 初次接触Ubuntu系统以及Linux内核,了解了其产生的历史,从感性来讲,深深吸引我的是其中蕴含的珍贵的开源精神,以及Stallman等人对&qu ...