bx值
bx值
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
,从小到大排序之后为ap
1
,a
p
2
,...,a
p
n
,定义它的bx值为满足ap
i
≠a
p
i−1
+1,1<i<=n的i 的个数。
给定n个数的一个排列,你需要计算它所有连续子序列的bx值之和。
对于每组数据,第一行一个整数n,第二行n个整数,表示n个数的一个排列。
1 <= T= < 20
1 <= n <= 100000
1 <= a
<= n
3
1 2 3
4
3 1 4 2
5
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <cassert>
#include <ctime>
#define rep(i,m,n) for(i=m;i<=(int)n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define sys system("pause")
#define ls rt<<1
#define rs rt<<1|1
#define all(x) x.begin(),x.end()
const int maxn=1e5+;
const int N=5e2+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qmul(ll p,ll q,ll mo){ll f=;while(q){if(q&)f=(f+p)%mo;p=(p+p)%mo;q>>=;}return f;}
ll qpow(ll p,ll q,ll mo){ll f=;while(q){if(q&)f=qmul(f,p,mo)%mo;p=qmul(p,p,mo)%mo;q>>=;}return f;}
int n,m,k,t,pos[maxn];
int main()
{
int i,j;
while(~scanf("%d",&t))
{
while(t--)
{
scanf("%d",&n);
rep(i,,n)scanf("%d",&j),pos[j]=i;
ll ret=;
rep(i,,n)ret+=1LL*(n-i+)*(i-);
rep(i,,n-)ret-=1LL*min(pos[i],pos[i+])*(n-max(pos[i],pos[i+])+);
printf("%I64d\n",ret);
}
}
return ;
}
bx值的更多相关文章
- 2017华南理工华为杯H bx值(容斥问题)
题目描述 对于一个nnn个数的序列 a1,a2,⋯,ana_1,a_2,\cdots,a_na1,a2,⋯,an,从小到大排序之后为ap1,ap2,⋯,apna_{p_1},a_{p ...
- 2017杭电ACM集训队单人排位赛 - 6
2017杭电ACM集训队单人排位赛 - 6 排名 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 59 1 X X 1 1 X X 0 1 ...
- DOS程序员手册(十四)
附录A ASCII字符集 十进制 十六进制 二进制 AscII 控制 按键 X10 X16 ...
- DOS程序员手册(十二)
DOS可安全使用 610页 在DOS控制台I/O操作进行轮询循环时,有规律地调用中断,以便允许终止 并驻留(TSR)程序(如适用于DOS的实用程序PRINT.COM),知道它可安全 地使用文件操作和其 ...
- 【自制操作系统06】终于开始用 C 语言了,第一行内核代码!
一.整理下到目前为止的流程图 写到这,终于才把一些苦力活都干完了,也终于到了我们的内核代码部分,也终于开始第一次用 c 语言写代码了!为了这个阶段性的胜利,以及更好地进入内核部分,下图贴一张到目前为止 ...
- YOLOv4全文阅读(全文中文翻译)
YOLOv4全文阅读(全文中文翻译) YOLOv4: Optimal Speed and Accuracy of Object Detection 论文链接: https://arxiv.org/pd ...
- arm汇编进入C函数分析,C函数压栈,出栈,传参,返回值
环境及代码介绍 环境和源码 由于有时候要透彻的理解C里面的一些细节问题,所有有必要看看汇编,首先这一切的开始就是从汇编代码进入C的main函数过程.这里不使用编译器自动生成的这部分汇编代码,因为编译器 ...
- wpf comboBox取值问题
这是获取值后台代码 private void button1_Click(object sender, RoutedEventArgs e) { combBox = ...
- 7.5 [bx+idata] 书中错误
这节中的问题 7.1 有错误 题目和我自己的注释为: 用 Debug 查看内存,结果如下: 2000:1000 BE 00 06 00 00 00 ... 写出下面程序执行后,ax,bx,cx中的内容 ...
随机推荐
- luogu 3690 【模板】 Link Cut Tree (动态树)
原来的代码有一些问题. 主要是对于不一定存在的边如何去判断,首先要保证在一个splay里,然后保证彼此之间直接联通且x的右儿子是空的 #include<iostream> #include ...
- createrepo -g /enp/comps.xml .
cd /enp; createrepo -g /enp/comps.xml .
- html5做的一个激光条
<!DOCTYPE HTML><html lang="zh-cn"><head> <title>CSS3激光加载条</titl ...
- 关于CSS中float的两点心得以及清除浮动的总结
对一个元素运用float后,该元素将脱离正常文档流,这意味着: 1. 运用float后,该元素不再影响父元素的高度,如果一个元素的所有子元素都是float的话,那么该元素的高度是0,这样后面元素渲染的 ...
- Django与 Ajax
什么是json? 定义: JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式.它基于 ECMAScript (w3c制定的js规范)的一个子 ...
- 传值:web.xml传递参数 即在Servlet中获取web.xml里的值
传值:web.xml传递参数 在web.xml中的Servlet里配置多个init-param <servlet> ... <init-param> <param-nam ...
- servlet范围:数据共享
数据共享: 请求转发:request.getDispatcher("相对路径").forward(request,response) 重定向:response.sendRedire ...
- 354 Russian Doll Envelopes 俄罗斯娃娃信封
You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...
- linux如何更改yum源
更改linux yum源方法:第一步:进入yum配置文件目录:cd /etc/yum.repos.d/第二步:备份配置文件(如果后续出现了问题就可以恢复):mv CentOS-Base.repo Ce ...
- MyBatis分页组件--PageHelper
一.介绍 PageHelper是国内非常优秀的一款开源的 mybatis 分页插件,它支持基本主流与常用的数据库,例如 Oracle.Mysql.MariaDB.SQLite.Hsqldb 等. 官网 ...