#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 200010
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1 int sum[N<<],tag[N/];
int n,q,cnt; void PushUp(int rt)
{
sum[rt]=sum[rt<<]+sum[rt<<|];
} void build(int l,int r,int rt)
{
if(l==r)
{
if((l>=N-n)&&l<N)
sum[rt]=,tag[++cnt]=l;
return;
}
int m=(l+r)>>;
build(lson);
build(rson);
PushUp(rt);
} void update(int i,int c,int l,int r,int rt)
{
if(l==r)
{
sum[rt]=c;
return;
}
int m=(l+r)>>;
if(tag[i]<=m)
update(i,c,lson);
else update(i,c,rson);
PushUp(rt);
} int query(int L,int R,int l,int r,int rt)
{
if(L<=l&&R>=r)
return sum[rt];
int m=(l+r)>>;
int res=;
if(L<=m)
res+=query(L,R,lson);
if(R>m)
res+=query(L,R,rson);
return res;
} int main(void)
{
int T,x;
scanf("%d",&T);
while(T--)
{
memset(sum,,sizeof(sum));
memset(tag,,sizeof(tag));
int pre;
scanf("%d%d",&n,&q);
cnt=;
build(,N-,);
pre=tag[];
while(q--)
{
scanf("%d",&x);
int ans=;
if(pre<=tag[x]-)
{ update(x,,,N-,);
ans=query(pre,tag[x]-,,N-,),tag[x]=--pre,update(x,,,N-,);}
printf("%d%c",ans,!q?'\n':' ');
}
}
return ;
}

UVA 1513 Movie collection的更多相关文章

  1. UVA 1513 - Movie collection(树状数组)

    UVA 1513 - Movie collection option=com_onlinejudge&Itemid=8&page=show_problem&category=5 ...

  2. UVA 1513 Movie collection (树状数组+反向存储)

    题意:给你n盘歌碟按照(1....n)从上到下放,接着m个询问,每一次拿出x碟,输出x上方有多少碟并将此碟放到开头 直接想其实就是一线段的区间更新,单点求值,但是根据题意我们可以这样想 首先我们倒着存 ...

  3. UVA - 1513 Movie collection (树状数组)

    题意:有n个影碟,标号为1~n,位置为0~n-1,每次取出一个影碟看完后,将其放在最前面(标号为0处),问每个影碟取出前,其位置之前有多少个影碟. 分析: 1.数组大小开为100000*2,后1000 ...

  4. uva 1513(线段树)

    题目链接:1513 - Movie collection 题意:有一堆电影,按1-n顺序排,有m次操作,每次询问第ai个电影之前有多少个电影,然后将其抽出放在堆顶. 分析:线段树应用. 因为每次查询后 ...

  5. UVA - 11987 Almost Union-Find[并查集 删除]

    UVA - 11987 Almost Union-Find I hope you know the beautiful Union-Find structure. In this problem, y ...

  6. UVA 1456 六 Cellular Network

    Cellular Network Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit S ...

  7. UVA 10798 - Be wary of Roses (bfs+hash)

    10798 - Be wary of Roses You've always been proud of your prize rose garden. However, some jealous f ...

  8. POJ 1873 UVA 811 The Fortified Forest (凸包 + 状态压缩枚举)

    题目链接:UVA 811 Description Once upon a time, in a faraway land, there lived a king. This king owned a ...

  9. Java基础Collection集合

    1.Collection是所有集合的父类,在JDK1.5之后又加入了Iterable超级类(可以不用了解) 2.学习集合从Collection开始,所有集合都继承了他的方法 集合结构如图:

随机推荐

  1. Java Socket简例

    Socket IO工具类: package com.test.util; import java.io.DataInputStream; import java.io.DataOutputStream ...

  2. mysql数据库时间、字符串类型互转

    时间格式转换: select DATE_FORMAT(NOW(),"%y-%m-%d %H:%i:%s") 字符串转时间: select STR_TO_DATE("201 ...

  3. YII数据库操作(CURD操作)

    数据库操作 获得模型对象 $model = 模型名::model();或$model = new 模型名(); 1.查询多条记录(返回值:二维数组) $result = $model->find ...

  4. bootstrap--组件之按钮式下拉菜单

    把任意一个按钮放入 .btn-group 中,然后加入适当的菜单标签,就可以让按钮作为菜单的触发器了. 简单的实现如下 Code<div class="btn-group"& ...

  5. struts中调用servlet的两种方法——IcC方式和非IoC方式的代码demo

    package com.java1234.action;//所在的包 import java.sql.Connection;//数据库连接的类 import java.util.ArrayList;/ ...

  6. Java Mybatis 传参方式

    一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...

  7. html-----016---HTTP 状态消息

    HTTP 状态消息 当浏览器从 web 服务器请求服务时,可能会发生错误. 从而有可能会返回下面的一系列状态消息: 1xx: 信息 消息: 描述: 100 Continue 服务器仅接收到部分请求,但 ...

  8. VBA 打印设置相关属性及方法

    打印设置说明,以下均为默认值. With ActiveSheet.PageSetup .PrintTitleRows = "" '工作表打印标题:顶端标题行(R) .PrintTi ...

  9. C++ 引用(&)

    #include <iostream> void sort(int &a, int &b){ if (a>=b) { return; } if (a<b) { ...

  10. docker 中搭建tomcat

    关于docker中tomcat的搭建,没有什么多说的,直接下载官方镜像 docker pull tomcat  (可能会下载到好几个镜像,就是tag不同,有知道为什么的可以告诉我) 然后我看的  ht ...