7.20T1
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
inline ll read()
{
ll s=; bool f=; char ch=' ';
while(!isdigit(ch)) {f|=(ch=='-'); ch=getchar();}
while(isdigit(ch)) {s=(s<<)+(s<<)+(ch^); ch=getchar();}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<) {putchar('-'); x=-x;}
if(x<) {putchar(x+''); return;}
write(x/); putchar((x%)+'');
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const ll N=;
ll n,m;
struct Node
{
ll id,num,val;
}a[N];
inline bool cmpnum(Node a,Node b){return a.num<b.num;}
inline bool cmpid(Node a,Node b){return a.id<b.id;}
struct BIT
{
ll S[N<<];
#define lowbit(x) ((x)&(-x))
inline void Ins(int x,int v)
{
while(x<=n)
{
S[x]+=v; x+=lowbit(x);
}
}
inline int Que(int x)
{
ll ans=;
while(x>)
{
ans+=S[x]; x-=lowbit(x);
}
return ans;
}
}T,BT;
signed main()
{
freopen("sort.in","r",stdin);
freopen("sort.out","w",stdout);
ll i,cv=,ans=,now=,oo;
R(n); R(m);
for(i=;i<=n;i++) R(a[a[i].id=i].num);
sort(a+,a+n+,cmpnum);
a[].val=++cv;
for(i=;i<=n;i++)
{
if(a[i].num==a[i-].num) a[i].val=cv; else a[i].val=++cv;
}
sort(a+,a+n+,cmpid);
for(i=n;i>=;i--)
{
ans+=(oo=T.Que(a[i].val-));
BT.Ins(a[i].val,oo);
T.Ins(a[i].val,);
}
Wl(ans);
for(i=;i<=m;i++)
{
ll pos; R(pos);
if(now<a[pos].val)
{
ans-=(BT.Que(a[pos].val)-BT.Que(now)); now=a[pos].val;
}
Wl(ans);
}
return ;
}
/*
input
6 2
160 163 164 161 167 160
2
3
output
6
3
1
*/
7.20T1的更多相关文章
- Scala 中的函数式编程基础(三)
主要来自 Scala 语言发明人 Martin Odersky 教授的 Coursera 课程 <Functional Programming Principles in Scala>. ...
- curl请求的url中含有空格
curl请求的url中含有空格时(例如rul的参数是sql查询语句,url=www.tets.com/query.php?sql=select * from t1),curl_easy_perform ...
- MongoDB实战指南(七):MongoDB复制集之复制集工作机制
http://www.cnblogs.com/longshiyVip/p/5097336.html 概述了复制集,整体上对复制集有了个概念,但是复制集最重要的功能之——自动故障转移是怎么实现的呢?数据 ...
随机推荐
- go的命令行参数
package main import ( "fmt" "os" ) func main() { var s, sep string for i := 1; i ...
- Till I Collapse CodeForces - 786C (主席树区间加,二分最小值)
大意: 给定序列, 将序列划分为若干段, 使得每段不同数字不超过k, 分别求出k=1...n时的答案. 考虑贪心, 对于某个k 从1开始, 每次查询最后一个颜色数<=k的点作为一个划分, 直到全 ...
- Matlab函数kmeans
Matlab函数kmeans K-means聚类算法采用的是将N*P的矩阵X划分为K个类,使得类内对象之间的距离最大,而类之间的距离最小. 使用方法:Idx=Kmeans(X,K)[Idx,C]=Km ...
- empty和isset的区别
1.empty 判断一个变量是否为空 null.false.0.0.0.’0′.array() .' '.var $a 都会返回true. 2.isset 判断一个变量是否设置 0.00.’0′. ...
- 将二维数组转换成一维数组(基于reduce)
reduce:不改变原数组,返回一个新的数组.就是遍历数组元素,从头开始,依次往下,第一个参数是上一次的返回值,第二个参数是下一个数组元素,首次的时候第一个和第二个参数分别是 array[0], a ...
- ES6入门十一:Generator生成器、async+await、Promisify
生成器的基本使用 生成器 + Promise async+await Promise化之Promisify工具方法 一.生成器的基本使用 在介绍生成器的使用之前,可以简单理解生成器实质上生成的就是一个 ...
- PHP 求两个日期之间相差的天数、月数
<?php /** * 求两个日期之间相差的天数 * (针对1970年1月1日之后,求之前可以采用泰勒公式) * @param string $day1 * @param string $day ...
- [LeetCode] 40. Combination Sum II ☆☆☆(数组相加等于指定的数)
https://leetcode.wang/leetCode-40-Combination-Sum-II.html 描述 Given a collection of candidate numbers ...
- cent os 7.0 出现的问题解决方法
https://www.jb51.net/article/34012.htm python重编译,并进行安装 https://www.jb51.net/os/RedHat/211444.h ...
- Delphi 方法的声明