/*
先来说一下第一眼看到想出的奇葩方法23333..
找每个数左右有几个比他小的
前几天刚学了区间第k小的求法
然后...
枚举中间的那个点 对于左区间 二分找到他是第几大 右区间同理
然后 *起来
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 50010
#define maxm 50010*18*5
#define ll long long
using namespace std;
ll n,cnt,root[maxn],order[maxn],a[maxn],ans;
struct node{
ll lc,rc,sum;
}t[maxm];
ll init(){
ll x=;char s=getchar();
while(s<''||s>'')s=getchar();
while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
return x;
}
ll Build(ll S,ll L,ll R){
ll k=++cnt;t[k].sum=S;
t[k].lc=L;t[k].rc=R;
return k;
}
void Insert(ll &root,ll pre,ll pos,ll l,ll r){
root=Build(t[pre].sum+,t[pre].lc,t[pre].rc);
if(l==r)return;
ll mid=l+r>>;
if(pos<=mid)Insert(t[root].lc,t[pre].lc,pos,l,mid);
else Insert(t[root].rc,t[pre].rc,pos,mid+,r);
}
ll Query(ll L,ll R,ll k,ll l,ll r){
if(l==r)return l;
ll sum=t[t[R].lc].sum-t[t[L].lc].sum;
ll mid=l+r>>;
if(k<=sum)return Query(t[L].lc,t[R].lc,k,l,mid);
else return Query(t[L].rc,t[R].rc,k-sum,mid+,r);
}
int main()
{
//freopen("queueb.in","r",stdin);
//freopen("queueb.out","w",stdout);
n=init();
for(ll i=;i<=n;i++){
a[i]=init();
order[i]=a[i];
}
sort(order+,order++n);
ll num=n,pos,l,r,x,s1,s2;
for(ll i=;i<=n;i++){
pos=lower_bound(order+,order++n,a[i])-order;
Insert(root[i],root[i-],pos,,num);
}
for(ll i=;i<=n;i++){
x=a[i];s1=s2=;
l=;r=i;
while(l<=r){
ll mid=l+r>>;
pos=Query(root[],root[i],mid,,num);
if(order[pos]<x){
s1=mid;l=mid+;
}
else r=mid-;
}
l=;r=n-i+;
while(l<=r){
ll mid=l+r>>;
pos=Query(root[i-],root[n],mid,,num);
if(order[pos]<x){
s2=mid;l=mid+;
}
else r=mid-;
}
ans+=s1*s2;
}
printf("%lld\n",ans);
return ;
}
/*
其实求左右各有几个比他小的 可以用树状数组
逆序对是求左边几个比他大的这个一样啊
注意右边的时候离散化排序和左边不一样
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 50010
#define ll long long
using namespace std;
int n,b[maxn],t[maxn],l[maxn],r[maxn];
ll ans;
struct node{
int o,x;
}a[maxn];
int init(){
int x=;char s=getchar();
while(s<''||s>'')s=getchar();
while(s>=''&&s<=''){x=x*+s-'';s=getchar();}
return x;
}
int cmp1(const node &a,const node &b){
if(a.x==b.x)return a.o>b.o;
return a.x<b.x;
}
int cmp2(const node &a,const node &b){
if(a.x==b.x)return a.o<b.o;
return a.x<b.x;
}
void Add(int pos,int data){
while(pos<=n){
t[pos]+=data;
pos+=pos&(-pos);
}
}
int find(int pos){
int r=;
while(pos){
r+=t[pos];
pos-=pos&(-pos);
}
return r;
}
int main()
{
freopen("queueb.in","r",stdin);
freopen("queueb.out","w",stdout);
n=init();
for(int i=;i<=n;i++){
a[i].x=init();
a[i].o=i;
}
sort(a+,a++n,cmp1);
for(int i=;i<=n;i++)
b[a[i].o]=i;
for(int i=;i<=n;i++){
Add(b[i],);
l[i]=find(b[i]-);
}
memset(t,,sizeof(t));
sort(a+,a++n,cmp2);
for(int i=;i<=n;i++)
b[a[i].o]=i;
for(int i=n;i>=;i--){
Add(b[i],);
r[i]=find(b[i]-);
}
for(int i=;i<=n;i++)
ans+=(ll)l[i]*r[i];
printf("%lld\n",ans);
return ;
}

COGS 859. 数列的更多相关文章

  1. COGS 2638. 数列操作ψ 线段树

    传送门 : COGS 2638. 数列操作ψ 线段树 这道题让我们维护区间最大值,以及维护区间and,or一个数 我们考虑用线段树进行维护,这时候我们就要用到吉司机线段树啦 QAQ 由于发现若干次an ...

  2. cogs 264. 数列操作 单点修改 区间查询

    http://cogs.pro:8080/cogs/problem/problem.php?pid=pyNimmVeq 264. 数列操作 ★☆   输入文件:shulie.in   输出文件:shu ...

  3. cogs 1317. 数列操作C 区间修改 区间查询

    1317. 数列操作C ★★★   输入文件:shuliec.in   输出文件:shuliec.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 假设有一个长度为 n( ...

  4. cogs 1316. 数列操作B 区间修改 单点查询

    1316. 数列操作B ★★   输入文件:shulieb.in   输出文件:shulieb.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 假设有一个大小为 n(n ...

  5. COGS.1317.数列操作c(分块 区间加 区间求和)

    题目链接 #include<cmath> #include<cstdio> #include<cctype> #include<algorithm> u ...

  6. COGS.264.数列操作(分块 单点加 区间求和)

    题目链接 #include<cmath> #include<cstdio> #include<cctype> #include<algorithm> u ...

  7. COGS 264. 数列操作

    时间限制:1 s   内存限制:160 MB [问题描述] 假设有一列数 {Ai }(1 ≤ i ≤ n) ,支持如下两种操作: (1)将 A k 的值加 D .( k, D 是输入的数) (2) 输 ...

  8. 数据结构(Splay平衡树):COGS 339. [NOI2005] 维护数列

    339. [NOI2005] 维护数列 时间限制:3 s   内存限制:256 MB [问题描述] 请写一个程序,要求维护一个数列,支持以下 6 种操作:(请注意,格式栏 中的下划线‘ _ ’表示实际 ...

  9. cogs 66. [HAOI2004模拟] 数列问题

    66. [HAOI2004模拟] 数列问题 ★☆   输入文件:dfs3.in   输出文件:dfs3.out   简单对比时间限制:1 s   内存限制:128 MB 问题描述试编程将 1 至 N ...

随机推荐

  1. Day14 HTML补充

    一.认识前端 前端开发的核心语言: html - 超文本标记语言 结构 css - 层叠样式表 样式 javascript - 脚本语言 行为 <html></html> 双标 ...

  2. bzoj1311: 最优压缩

    Description  其中: Auv是与Aij相邻的像素(为了简化,认为(i-1,j),(i+1,j,(i,j-1),(i,j+1)为相邻元素); Wij取值0或者1,表示Aij修改后取V0或者V ...

  3. 使用 Scut 搭建通服架构

    整体通服的架构图如下: 整体思路: 尽量将公共的业务逻辑分拆到单个业务服务器: 公共业务RDB读写分离,提高IO并发量: 角色简要信息.角色战斗信息修改后将ID压入修改队列,简要信息每3分钟通知同步一 ...

  4. 专家解读Linux操作系统内核中的GCC特性

    专家解读Linux操作系统内核中的GCC特性   Linux内核使用GNU Compiler Collection (GCC)套件的几个特殊功能.这些功能包括提供快捷方式和简化以及向编译器提供优化提示 ...

  5. Node.js流

    什么是流? 流是可以从一个源读取或写入数据到连续的目标对象.在Node.js,有四种类型的数据流. Readable - 其是用于读操作. Writable - 用在写操作. Duplex - 其可以 ...

  6. NYOJ 540

    为了给学弟学妹讲课,我水了一道题…… import java.util.Arrays; import java.util.Scanner; public class NYOJ540 { public ...

  7. github Travis CI 持续集成

    一个项目如何保证代码质量是开发中非常重要的环节,对于开源项目来说更是如此,因为开源项目要面对的是来自不同水平开发者提交的代码.所以围绕开源做持续集成(Continuous Integration)变得 ...

  8. Microsoft Office 2013 激活方法

    Microsoft Office 2013 激活方法   Microsoft Office 2013是微软的新一代Office办公软件,全面采用Metro界面,包括Word.PowerPoint.Ex ...

  9. 构造函数语义学之Copy Constructor构建操作(1)

    一.Copy Constructor的构建操作 就像 default constructor 一样,如果class没有申明一个 copy constructor,就会隐含的声明或隐含的定义一个.生成的 ...

  10. 图论(二分图,KM算法):HDU 3488 Tour

    Tour Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...