uva 1513 - Movie collection--树状数组--预留前n个位置
来源:互联网 发布:知乎回答排序规则 编辑:程序博客网 时间:2024/05/20 06:04
//// main.cpp// uva 1513 - Movie collection--树状数组--预留前n个位置//// Created by XD on 15/9/10.// Copyright (c) 2015年 XD. All rights reserved.///* 树状数组 做法就是预留前m个位置给后面的要看的的video,因为他们要移到顶端,所以我们就可以使用header表示现在最前端的在哪个位置 使用flag[i]表示标号为i的位置在哪 。对于一个询问,就可以将时间复杂度降到logn级别。 */#include <iostream>#include <queue>#include <stack>#include <stdio.h>#include <stdlib.h>#include <math.h>#include<vector>#include <string.h>#include <algorithm>#include <set>#include <map>#include <cstdio>#define ll long longusing namespace std ;const int maxn = 100000 *2+10 ;int flag[101010] ;int c[maxn] ;int head ;int mn ;int lowerbit(int x){ return x&(-x) ;}void update(int x, int v){ while (x <= maxn){ c[x] += v ; x += lowerbit(x) ; }}int sum(int x){ int ret =0 ; while (x > 0) { ret += c[x] ; x -= lowerbit(x) ; } return ret ;}int main(int argc, const char * argv[]) { int n ,T,m,pos; scanf("%d" , &T) ; while (T--) { memset(c, 0, sizeof(c)) ; scanf("%d%d" , &n , &m) ; for (int i = 1; i <= n ; i++) { flag[i] = i + m + 5 ; update( i+ m + 5, 1) ; } head = m + 1 ; for (int i = 0 ; i < m-1; i++) { scanf("%d" , &pos) ; printf("%d " , sum(flag[pos])-1) ; update(flag[pos], -1) ; flag[pos] = head-- ; update(flag[pos], 1) ; } scanf("%d" , &pos) ; printf("%d\n" , sum(flag[pos])-1) ; } return 0;}
0 0
- uva 1513 - Movie collection--树状数组--预留前n个位置
- UVA 1513 - Movie collection(树状数组)
- 【UVA】1513-Movie collection(树状数组)
- uva 1513 - Movie collection(树状数组)
- UVA 1513-Movie collection(树状数组)
- UVA 1513 - Movie collection(树状数组)
- UVa 1513 Movie collection (树状数组)
- UVa 1513 / UVALive 5902 Movie collection (树状数组)
- UVa 1513 / UVALive 5902 Movie collection (树状数组)
- UVA 1513—— Movie collection(树状数组)
- uva 1513 - Movie collection
- UVa:1513 Movie collection
- Uva-1513-Movie collection
- UVa-1513-Movie collection
- UVA 1513 Movie collection
- UVA 1513 Movie collection
- uva 1513 Movie collection
- UVA 1513 Movie collection
- C++ explicit
- JavaScript 原生和JQuery 的Ajax
- Android Studio系列教程一--下载与安装
- uva489 - Hangman Judge
- strstr实现(练习KMP算法的好例子)
- uva 1513 - Movie collection--树状数组--预留前n个位置
- 抽象类与接口的区别
- HTML-CSS
- BAE(疑惑)
- no JSTAF in java.library.path
- 为Cordova + Ionic + AngularJS 应用添加微信分享功能
- poj 2431 贪心(最少的加油次数)
- 一个rails项目连多个mongo数据库
- Myeclipse10下搭建SSH框架(图解)Struts2.1+Spring3.0+Hibernate3.3