bzoj 2124 等差子序列 (线段树维护hash)
2124: 等差子序列
Time Limit: 3 Sec Memory Limit: 259 MB
Submit: 1922 Solved: 714
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
3
1 3 2
3
3 2 1
Sample Output
Y
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mid ll m = (l + r) >> 1
const ll M = 1e5+;
const ll md = 1e9+;
ll suml[M<<],sumr[M<<],a[M],pw[M];
void pushup(ll l,ll r,ll rt){
ll len = r - l + ;
ll m = len / ;
suml[rt] = (suml[rt<<]*pw[m]+suml[rt<<|])%md;
sumr[rt] = (sumr[rt<<|]*pw[len-m]+sumr[rt<<])%md;
return ;
} void update(ll p,ll l,ll r,ll rt){
if(l == r){
suml[rt] = sumr[rt] = ;
return ;
}
mid;
if(p <= m) update(p,lson);
else update(p,rson);
pushup(l,r,rt);
} ll queryl(ll L,ll R,ll l,ll r,ll rt){
if(L > R) return ;
if(L == l&&R == r) return suml[rt];
mid;
if(L > m) return queryl(L,R,rson);
else if(R <= m) return queryl(L,R,lson);
else return (queryl(L,m,lson)*pw[R-m]+queryl(m+,R,rson))%md;
} ll queryr(ll L,ll R,ll l,ll r,ll rt){
if(L > R) return ;
if(L == l&&R == r) return sumr[rt];
mid;
if(L > m) return queryr(L,R,rson);
else if(R <= m) return queryr(L,R,lson);
else return (queryr(L,m,lson)+queryr(m+,R,rson)*pw[m-L+])%md;
} int main()
{
ll t,n;
ios::sync_with_stdio();
cin.tie(); cout.tie();
cin>>t;
pw[] = ;
for(ll i = ;i <= ;i++)
pw[i] = (pw[i-]*)%md;
while(t--){
cin>>n;
memset(suml,,sizeof(suml));
memset(sumr,,sizeof(sumr));
memset(a,,sizeof(a));
ll flag = ;
for(ll i = ;i <= n;i ++) cin>>a[i];
for(ll i = ;i <= n;i ++){
ll len = min(a[i]-,n-a[i]);
ll t1 = queryl(a[i]-len,a[i]-,,n,);
ll t2 = queryr(a[i]+,a[i]+len,,n,);
if(t1!=t2){
flag = ;break;
}
update(a[i],,n,);
}
if(!flag) cout<<"Y"<<endl;
else cout<<"N"<<endl;
}
}
bzoj 2124 等差子序列 (线段树维护hash)的更多相关文章
- BZOJ 2124: 等差子序列 线段树维护hash
2124: 等差子序列 Description 给一个1到N的排列{Ai},询问是否存在1<=p1=3),使得Ap1,Ap2,Ap3,…ApLen是一个等差序列. Input 输入的第一行包含一 ...
- BZOJ 2124等差子序列 线段树&&hash
[题目描述 Description] 给一个 1 到 N 的排列{Ai},询问是否存在 1<=p1<p2<p3<p4<p5<…<pLen<=N(Len& ...
- bzoj2124: 等差子序列线段树+hash
bzoj2124: 等差子序列线段树+hash 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2124 思路 找大于3的等差数列其实就是找等于 ...
- BZOJ 2124: 等差子序列
Sol 线段树+Hash. 首先暴力 等差子序列至少3项就可以了,就枚举中项,枚举公差就可以了,只需要一个数在中项前出现,另一个数在中项前没出现过就可以了.复杂度 \(O(n^2)\) 然后我想了一个 ...
- cf213E 线段树维护hash
链接 https://codeforces.com/contest/213/problem/E 题目大意 给出两个排列a.b,长度分别为n.m,你需要计算有多少个x,使 得\(a_1 + x; a_2 ...
- MemSQL Start[c]UP 2.0 - Round 1 F - Permutation 思维+线段树维护hash值
F - Permutation 思路:对于当前的值x, 只需要知道x + k, x - k这两个值是否出现在其左右两侧,又因为每个值只有一个, 所以可以转换成,x+k, x-k在到x所在位置的时候是否 ...
- BZOJ2124:等差子序列(线段树,hash)
Description 给一个1到N的排列{Ai},询问是否存在1<=p1<p2<p3<p4<p5<…<pLen<=N (Len>=3), 使得A ...
- [bzoj2124]等差子序列——线段树+字符串哈希
题目大意 给一个1到N的排列\(A_i\),询问是否存在\(p_i\),\(i>=3\),使得\(A_{p_1}, A_{p_2}, ... ,A_{p_len}\)是一个等差序列. 题解 显然 ...
- bzoj 4184: shallot (线段树维护线性基)
题面 \(solution:\) 这一题绝对算的上是一道经典的例题,它向我们诠释了一种新的线段树维护方式(神犇可以跳过了).像这一类需要加入又需要维护删除的问题,我们曾经是遇到过的像莫对,线段树... ...
随机推荐
- [PLC]ST语言五:STL/RET/CMP/ZCP
一:STL/RET/CMP/ZCP 说明:简单的顺控指令不做其他说明. 控制要求:无 编程梯形图: 结构化编程ST语言: (*步进指令STL(EN,s);*) SET(M8002,S3); STL(T ...
- CentOS安装GoAccess
官网 https://goaccess.io/ yum -y install glib2 glib2-devel ncurses ncurses-devel GeoIP GeoIP-devel安装依赖 ...
- 自定义 vue switch 组件
<template> <div class="switch clearfix" @click="toggle" v-bind:style=&q ...
- 1.0 JAVA基础核心概念
JAVA基础知识 转载至:http://www.runoob.com/java/java-variable-types.html 对菜鸟教程进行核心整理: 一.JAVA理论概念 1.基础概念 Java ...
- C++ chrono 库中的 steady_clock 和 system_clock
C++11 中提供了一个计时的标准库 <chrono>; 里面有三种时钟 clock: steady_clock, system_clock 和 high_resolution_clock ...
- Python机器学习库SKLearn:数据集转换之管道和特征
转载自:https://blog.csdn.net/cheng9981/article/details/61918129 4.1 管道和特征:组合估计量 4.1.1 管道:链接估计 管道可以用于将多个 ...
- docker usage
docker ps -a 查看物理机上面所有容器信息列表 docker exec -it $docker_id /bin/bash 进入容器以默认帐号 docker exec -it -u root ...
- [T-ARA/超新星][TTL (Time To Love)]
歌词来源:http://music.163.com/#/song?id=5403002 作曲 : 金道勋 [作曲 : 金道勋] 作词 : Rhymer/Joosuc/황성진 [作词 : Rhymer/ ...
- JQuery ajax请求struts action实现异步刷新的小实例
这个样例是用JQuery ajax和struts来做的一个小样例,在这个样例中采用两种方式将java Util中的list转换成支json的格式,第一种是用json-lib.jar这个jar包来转换, ...
- eclipse在线安装maven插件
http://blog.csdn.net/xiaoxiaoyeyaya/article/details/17200987 在安装插件的时候将下面的contact all update sites du ...