存code
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = ;
#define LL long long
int T,n,m,head1,head2,tail1,tail2;
int a[maxn];
int q1[maxn][],q2[maxn][];LL ans;
inline int read() {
int x=;
char c=getchar();
while(c>''||c<'')c=getchar();
while(c>=''&&c<='')x=x*x+c-'',c=getchar();
return x;
}
int main() {
T=read();
while(T--) {
n=read();
for(int i=;i<=n;i++)a[i]=read();
for(int k=;k<=n;k++)
{
ans=;int l=;
head1=head2=;tail1=tail2=;
memset(q1,,sizeof(q1));
memset(q2,,sizeof(q2));
for(int i=;i<=n;i++)
{
while(head1<=tail1&&q1[tail1][]>=a[i]) tail1--;
tail1++;
q1[tail1][]=a[i],q1[tail1][]=i;
while(head2<=tail2&&q2[tail2][]<=a[i]) tail2--;
tail2++;
q2[tail2][]=a[i],q2[tail2][]=i;
while(head1<=tail1 && head2<=tail2&&q2[head2][]-q1[head1][]>=k) {
l=min(q2[head2][],q1[head1][])+;
if(q2[head2][]<q1[head1][]) {
head2++;
} else if(q2[head2][]>q1[head1][]) {
head1++;
} else {
head1++;head2++;
}
}
ans+=i-l+;
}
printf("%lld\n",ans);
}
}
return ;
}
存code的更多相关文章
- [转]save all TWebbrowser Frame Sources?
注:有一定的参考价值,转存 // Code 1 uses ActiveX, MSHTML_TLB, ComCtrls, ComObj; function GetBrowserForFrame(Doc ...
- Android手机上Audio DSP频率低 memory小的应对措施
我在前面的文章(Android智能手机上的音频浅析)中说过Android手机上有一块专门用于音频处理的DSP,它的特点是频率低(一般几百MHZ).内部memory小(通常不超过100k word).要 ...
- POJ2533&&1836&&3176
终于写完了POJ的DP专题,然而都是水题233 这次也把题目分了一下,先挑3道特别简单的讲一下 2533 题意:求最长上升子序列. 很简单,用一般的DP或者二分优化都可以过去 这里懒得写一般DP了,其 ...
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...
- Visual Studio Code 使用Git进行版本控制
Visual Studio Code 使用Git进行版本控制 本来认为此类教程,肯定是满网飞了.今天首次使用VS Code的Git功能,翻遍了 所有中文教程,竟没有一个靠谱的.遂动笔写一篇. 请确保你 ...
- ASP.NET Core 中文文档 第二章 指南(1)用 Visual Studio Code 在 macOS 上创建首个 ASP.NET Core 应用程序
原文:Your First ASP.NET Core Application on a Mac Using Visual Studio Code 作者:Daniel Roth.Steve Smith ...
- Entity Framework Code First使用DbContext查询
DbContext.DbSet及DbQuery是Entity Framework Code First引入的3个新的类,其中DbContext用于保持数据库会话连接,实体变化跟踪及保存,DbSet用于 ...
- 設置Linux保留物理內存並使用 (1)
在Linux系統中可以通過memblock來設置系統保留物理內存,防止這些內存被內存管理系統分配出去. 作者: 彭東林 郵箱: pengdonglin137@163.com 平臺 硬件平臺: TQ24 ...
- Code First :使用Entity. Framework编程(8) ----转发 收藏
第8章 Code First将走向哪里? So far, this book has covered all of the Code First components that reached the ...
随机推荐
- 使用Auto Layout中的VFL(Visual format language)--代码实现自动布局
使用Auto Layout中的VFL(Visual format language)--代码实现自动布局 2014-12-09 10:56 编辑: zhiwupei 分类:iOS开发 来源:机智的新手 ...
- 674. Longest Continuous Increasing Subsequence@python
Given an unsorted array of integers, find the length of longest continuous increasing subsequence (s ...
- codevs 数字三角形集结
添在前面的一句话:初学DP,若有错误,请指出,不能误人子弟,欢迎大家提出意见.水平不高,博客写的比较粗糙,代码也挺丑,请见谅. 最原始的数字三角形: 1220 数字三角形 时间限制: 1 s 空间 ...
- Git学习——版本切换
版本回退 回退到前面几个版本的命令如下: git reset --hard HEAD^ //回退到前一个版本 git reset --hard HEAD^^ //回退到前前一个版本 git reset ...
- redux form
纯粹使用react进行表单校验: class MyForm extends React.Component{ constructor(props){ super(props) this.onAddrC ...
- 生物信息学练习2- Biom-format
The Biological Observation Matrix (BIOM) format http://biom-format.org/ biom-format有两种方式安装: 1. pytho ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
- PAT Basic 1017
1017 A除以B(20 分) 本题要求计算 A/B,其中 A 是不超过 1000 位的正整数,B 是 1 位正整数.你需要输出商数 Q 和余数 R,使得 A=B×Q+R 成立. 输入格式: 输入在一 ...
- Java web 服务启动时Xss溢出异常处理笔记
本文来自网易云社区 作者:王飞 错误日志 错误日志要仔细看,第一行不一定就是关键点,这个错误出现的时候,比较靠后,其中关键行就是下面这句. Caused by: java.lang.IllegalSt ...
- Laya Timer原理 & 源码解析
Laya Timer原理 & 源码解析 @author ixenos 2019-03-18 16:26:38 一.原理 1.将所有Handler注册到池中 1.普通Handler在handle ...