#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. day-4

    /* 早上黑板上的倒计时变成了120小时 嗯 很快就要结束了 上午考试 据老师说很简单 老师 :"我就说说~"..... 下午改题 T3好辣脑子 感觉智商不够了 T2dp写丑了 然 ...

  2. iOS-开发记录-UIView属性

    UIView属性 1.alpha 设置视图的透明度.默认为1. // 完全透明 view.alpha = ; // 不透明 view.alpha = ; 2.clipsToBounds // 默认是N ...

  3. java web环境配置类型问题

    一, cmd查看jdk版本 java -version cmd查看jdk安装路径 java -verbose 二, 如果出现了上述的错误按照如下的3个步骤解决:1.首先关闭MyEclipse工作空间. ...

  4. Cogs 1008. 贪婪大陆(树状数组)

    贪婪大陆 难度等级 ★★ 时间限制 1000 ms (1 s) 内存限制 128 MB 测试数据 10 简单对比 输入文件:greedisland.in 输出文件:greedisland.out 简单 ...

  5. leetcode345——Reverse Vowels of a String(C++)

    Write a function that takes a string as input and reverse only the vowels of a string. Example 1:Giv ...

  6. 绑定本地Service并与之通信

    绑定Service需要调用 public boolean bindService (Intent service, ServiceConnection conn, int flags): 传入一个Se ...

  7. 网站开发常用jQuery插件总结(五)滚动条插件nanoscroller

    网站在展示信息时,如果信息量过大,解决方法主要有三种.1.分页,将信息分页显示.2.整页显示,但是页面过长,影响浏览体验.3.使用滚动条,而默认滚动条样式太单一,用户体验不友好.所以我们需要美化滚动条 ...

  8. .NET异步操作学习之一:Async/Await中异常的处理

    以前的异常处理,习惯了过程式的把出现的异常全部捕捉一遍,然后再进行处理.Async/Await关键字出来之后的确简化了异步编程,但也带来了一些问题.接下来自己将对这对关键字进行学习.然后把研究结果放在 ...

  9. php Static静态关键字

    静态属性与方法可以在不实例化类的情况下调用,直接使用类名::方法名的方式进行调用.静态属性不允许对象使用->操作符调用. class Car { private static $speed =  ...

  10. Yum安装Memcache

    rpm -qa | grep libevent       yum install libevent -y rpm -qa | grep memcached yum install memcached ...