UVA 1513 树状数组
来源:互联网 发布:js onchange没进去 编辑:程序博客网 时间:2024/05/19 03:30
传送门:UVA 1513
题意
给m个movie, 编号一到m, 1在上, 每次把要看的movie看完后放在最上面, 查询每次要看之前上面有几个movie
题解
每次更新把上个位置去掉, 新的位置可以通过扩展数组实现, 因为r <= 100000干脆数组开两倍, 最上面的movie更新放在后面, 这样每次更新前查询就可以了
AC code:
/* adrui's submission Language : C++ Result : Accepted Favorite : Dragon Balls Love : yy Motto : Choose & Quit Standing in the Hall of Fame*/#include<iostream>#include<cstring>using namespace std;const int maxn(100005);int m, r, c[maxn << 1], cnt[maxn];#define debug 0#define lowbit(x) (x & (-x))#define M(a, b) memset(a, b, sizeof(a))void add(int x, int v) { while (x <= maxn << 1) { //这里要是maxn 因为没有指定m, r关系 c[x] += v; x += lowbit(x); }}int getSum(int x) { int res = 0; while (x) { res += c[x]; x -= lowbit(x); } return res;}int main() {#if debug freopen("in.txt", "r", stdin);#endif //debug cin.tie(0); cin.sync_with_stdio(false); int t; cin >> t; while (t--) { cin >> m >> r; M(c, 0); for (int i = 1; i <= m; ++i) { cnt[i] = m + 1 - i; add(cnt[i], 1); } int tot = m + 1, a; while (r--) { cin >> a; cout << m - getSum(cnt[a]) << (r ? " " : "\n");//查询 add(cnt[a], -1); //消去上一个位置 cnt[a] = tot++; //更新后位置移到后面 add(cnt[a], 1); //更新新位置 } } return 0;}
0 0
- UVA 1513 树状数组
- UVA - 1513(树状数组优化)
- UVA 1513(树状数组)
- 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 12086 树状数组
- UVA 12086 - Potentiometers(树状数组)
- UVA 11525 - Permutation(树状数组)
- UVA 11525 Permutation(树状数组)
- uva 12086 - Potentiometers(树状数组)
- uva 12086 - Potentiometers (树状数组)
- uva 12086 - Potentiometers--树状数组
- UVA 12086 - Potentiometers(树状数组)
- UVA 12086 (树状数组)
- Machine vision
- 堆排序——C++关于堆排序的库函数排序
- [堆] POJ 3481 Double Queue
- 转账业务的实现
- iOS简单的键盘弹出输入框上移
- UVA 1513 树状数组
- 一种互联网应用的分布式架构模式微服务应用框架的实现(gradle,dubbo,zookeeper,springmmvc)
- Java编程基础-面向对象(上)
- 镜头面面观
- Js DOM对象控制HTML
- xml解析-2 SAX解析
- 转载随笔
- hdu 5895 (2016icpc亚洲区域赛青岛站D题 Lucky coins)
- 第14周 项目3 -是否二叉排列序