#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. ibatis配置xml文件中CDATA的用法

    ibatis作为一种半自动化的OR Mapping工具,其灵活性日益体现出来,越来越多的人都倾向于在项目中使用.由于Sql中经常有与xml规范相冲突的字符对xml映射文件的合法性造成影响.许多人都知道 ...

  2. 多个线程访问url

    多个线程访问url package com.aig.ecompassios.ecard; import java.io.BufferedReader; import java.io.InputStre ...

  3. meteor中分页库alethes:pages用法汇总

    1.添加分页库: meteor add alethes:pages 2.新建分页: Pages = new Meteor.Pagination("collection-name") ...

  4. 广告系统中weak-and算法原理及编码验证

    wand(weak and)算法基本思路 一般搜索的query比较短,但如果query比较长,如是一段文本,需要搜索相似的文本,这时候一般就需要wand算法,该算法在广告系统中有比较成熟的应 该,主要 ...

  5. Oracle官网下载地址大全(包括11g、10g和9i)

    Oracle11g下载: Microsoft Windows(32 位)的 Oracle Database 11g 第 2 版 (11.2.0.1.0) http://download.oracle. ...

  6. xpath选择器

    一.xpath中节点关系 父(Parent):每个元素以及属性都有一个父 子(Children):元素节点可有零个.一个或多个子 同胞(Sibling):拥有相同的父的节点 先辈(Ancestor): ...

  7. 如何在Angular2中使用Forms

    在Angular2中形成两个基本对象是Control和ControlGroup. 控制用户输入 Control 一个控制表示一个输入字段(ngFormControl) 一个控制可以绑定到一个input ...

  8. Spring学习之代理

    Spring的核心就是IOC和AOP IOC就是控制反转:   就是用配置文件的方式给javabean 赋值. 正常的在程序里;用new 的方式创建一个对象的时候,他就固定了值, 如果是注入的方式的话 ...

  9. GIS科研站

    http://www.3sbase.com/3sbase/ 近年来,地理信息科学发展迅猛,科研人员日益增多,但目前尚缺乏良好的交流平台,致使优秀的科研成果难以推广.同时,对于大量的GIS学生而言,对国 ...

  10. 常用数据与VARIANT之间的转换---从网上整理

    //头文件 1 #pragma once class VariantConvert { public: VariantConvert(void); ~VariantConvert(void); pub ...