存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 ...
随机推荐
- javase(6)_异常
一.异常的概念 1.java异常是Java提供的用于处理程序中错误的一种机制. 2.所谓错误是程序在运行过程中发生的一些异常事件(如:除0,数组下标越界,文件不存在等). 3.Java程序的执行过程中 ...
- Fortran学习笔记2(变量声明)
常数的申明方式 变量初始化 等价申明EQUIALENCE 类型转化 自定义类型 KIND用法 常数的申明方式 程序中所有处理的数据,有些事固定不变的常数,如圆周率π和重力加速度G等. 此时,程序员可以 ...
- LeetCode 最大子序和
给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输出: 6 解释: 连续子数组 ...
- Bluefruit LE Sniffer - Bluetooth Low Energy (BLE 4.0) - nRF51822 驱动安装及使用
BLE Sniffer https://www.adafruit.com/product/2269 Bluefruit LE Sniffer - Bluetooth Low Energy (BLE 4 ...
- verilog behavioral modeling --procedural assignments
1.procedural assignments are used for updating reg ,integer , time ,real,realtime and memory data ty ...
- python基础知识14-正则表达式
1.正则表达式 正则可以代替其他任何工具,但是其他工具不能完全代替正则. 1.匹配或提取字符串的工具,基于所有语言之上的工具. 正则表达式所面向的问题 判断一个字符串是否匹配给定的格式,如判断用户注册 ...
- gnu printf可变参数宏
可变参数的宏 标准C只支持可变参数的函数,意味着函数的参数可以是不固定的 例如printf()函数的原型是int printf(const char *format [,argument]...) 而 ...
- sql优化工具--美团SQLAdvisor
美团点评SQL优化工具SQLAdvisor开源 介绍 在数据库运维过程中,优化 SQL 是 DBA 团队的日常任务.例行 SQL 优化,不仅可以提升程序性能,还能够降低线上故障的概率. 目前常用的 S ...
- android 之 service
在Activity中设置两个按钮,分别为启动和关闭Service: bt01.setOnClickListener(new Button.OnClickListener() { @Override ...
- log4net.dll配置以及在项目中应用
1,首先在项目中引用log4net.dll,然后项目中添加一个配置文件log4net.config <?xml version="1.0" encoding="ut ...