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 概述了复制集,整体上对复制集有了个概念,但是复制集最重要的功能之——自动故障转移是怎么实现的呢?数据 ...
随机推荐
- k8s之自定义指标API部署prometheus
1.自定义指标-prometheus node_exporter是agent;PromQL相当于sql语句来查询数据; k8s-prometheus-adapter:prometheus是不能直接解析 ...
- echarts 根据经纬度坐标在地图上描点
var mapData = [ {'latitude':30.67, 'longitude':104.07}, {'latitude':34.76, 'longitude':113.65}, {'la ...
- Django rest-framework框架-CSRF验证
settings.py里面有一个中间件 django.middleware.csrf.CsrfViewmiddleware #如果注释掉全站不需要csrf验证 如果打开全站都要csrf验证 全局使 ...
- vue组件之间的传值
vue中组件之间的传值有好几种情况 1.父向子传值 父组件向子组件传值使用props,直接上实例 city.vue是父组件,list.vue是子组件city.vue里定义cities和hotCitie ...
- 2018 年 IoT 那些事儿
本文作者:murphyzhang.xmy.fen @腾讯安全云鼎实验室 2018年,是 IoT 高速发展的一年,从空调到电灯,从打印机到智能电视,从路由器到监控摄像头统统都开始上网.随着5G网络的 ...
- Lab2 Report
1.安装SeleniumIDE插件 a)安装Firefox 17.0 - 56.*版本的firefox,下载地址为:http://ftp.mozilla.org/pub/firefox/release ...
- 【转】SpringBoot+SpringCloud实现登录用户信息在微服务之间的传递
实现思路: 1:准备一个ThreadLocal变量,供线程之间共享. 2:每个微服务对所有过来的Feign调用进行过滤,然后从请求头中获取User用户信息,并存在ThreadLocal变量中. 3:每 ...
- JAVA对ArrayList排序
ava如何对ArrayList中对象按照该对象某属性排序 增加排序功能,打印时:输出学生对象的时候,需要先按照年龄排序,如果年龄相同,则按照姓名排序,如果姓名也相同,则按照学号排序. Code hig ...
- HashMap闭环(死循环)的详细原因(转)
为何出现死循环简要说明 HashMap是非线程安全的,在并发场景中如果不保持足够的同步,就有可能在执行HashMap.get时进入死循环,将CPU的消耗到100%. HashMap采用链表解决Hash ...
- rabbitmq 使用PhpAmqpLib
rabbitmq类 rabbitmq.php <?php require_once __DIR__ . '/vendor/autoload.php'; use PhpAmqpLib\Connec ...