UVA 1513 Movie collection
#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的更多相关文章
- UVA 1513 - Movie collection(树状数组)
UVA 1513 - Movie collection option=com_onlinejudge&Itemid=8&page=show_problem&category=5 ...
- UVA 1513 Movie collection (树状数组+反向存储)
题意:给你n盘歌碟按照(1....n)从上到下放,接着m个询问,每一次拿出x碟,输出x上方有多少碟并将此碟放到开头 直接想其实就是一线段的区间更新,单点求值,但是根据题意我们可以这样想 首先我们倒着存 ...
- UVA - 1513 Movie collection (树状数组)
题意:有n个影碟,标号为1~n,位置为0~n-1,每次取出一个影碟看完后,将其放在最前面(标号为0处),问每个影碟取出前,其位置之前有多少个影碟. 分析: 1.数组大小开为100000*2,后1000 ...
- uva 1513(线段树)
题目链接:1513 - Movie collection 题意:有一堆电影,按1-n顺序排,有m次操作,每次询问第ai个电影之前有多少个电影,然后将其抽出放在堆顶. 分析:线段树应用. 因为每次查询后 ...
- UVA - 11987 Almost Union-Find[并查集 删除]
UVA - 11987 Almost Union-Find I hope you know the beautiful Union-Find structure. In this problem, y ...
- UVA 1456 六 Cellular Network
Cellular Network Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit S ...
- 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 ...
- 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 ...
- Java基础Collection集合
1.Collection是所有集合的父类,在JDK1.5之后又加入了Iterable超级类(可以不用了解) 2.学习集合从Collection开始,所有集合都继承了他的方法 集合结构如图:
随机推荐
- PHP Fatal error问题处理
今天一个朋友公司网站遇到一个关于PHP的问题: PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to ...
- Dynamic CRM:解决在创建业务流程时无法选择部分实体
在使用Dynamic CRM 业务流程的时候,会现在无法在步骤创建里选择我们想要的实体(如订单产品) 解决方法: 在SQL Server 中CRM数据库中找到[MetadataSchema].[Ent ...
- C# MD5 16进制MD5对称加密法
/// <summary> /// MD5 16进制算法 /// </summary> /// <param name="str"></p ...
- 详说C#中的结构struct
一.结构和类的区别 1.结构的级别和类一致,写在命名空间下面,可以定义字段.属性.方法.构造方法也可以通过关键字new创建对象. 2.结构中的字段不能赋初始值. 3.无参数的构造函数无论如何C#编译器 ...
- WebView组件的应用
1.什么是WebView? WebView(网络视图)能加载显示网页,可以将其视为一个浏览器,它使用了WebKit渲染引擎加载显示网页. <?xml version="1.0" ...
- iOS开发——友盟分享
==========2016-01-29 更新=====刘成利 email:liu_cheng_li@qq.com========== 自己成功集成到公司的项目前,也已做了测试好的友盟分享demo 目 ...
- OC - 1.面向过程和面向对象的思想对比
一.面向过程 1> 思想 面向过程是一种以过程为中心的最基础编程思想,不支持面向对象的特性. 面向过程是一种模块化程序设计方法 2> 开发方法 面向过程的开发方法是以过程(也可以说是模块) ...
- .net 安卓IOS跨平台des加解密双向的(可以互相加解密)
#region 跨平台加解密(c# 安卓 IOS) // public static string sKey = "12345678"; // /// // /// 解密 // / ...
- html表格 第五节
表格: <html> <head> <title>表格实例</title> </head> <body> <center& ...
- 02_Jquery_02_元素选择器
[简述] 元素选择器就是通过元素名来查询元素 $("elementName")这里就可以通过元素名来获取jquery元素了. 但与id选择器不同的是,名称相同的元素有很多,所以获取 ...