UVALive 5902 Movie collection
来源:互联网 发布:开淘宝大概费用是多少 编辑:程序博客网 时间:2024/04/29 04:50
树状数组。一些电影盘摞成一摞,抽出第x个,输出它上边有多少个,再把x放到顶部。求x上面的盘的个数就是前缀和,就往树状数组上想。每次取出再放到顶上,我们不可能往0,-1,-2...上放,数组要反过来,下表从小到大表式光盘从最下边的到最上边的值(该盘上面的盘数,用总数减一下就可得到)。话句话说,每个点存的是它下面的盘数。取的时候,下面的值不变,上面的加一。
#pragma comment(linker, "/STACK:1024000000,1024000000")#include<algorithm>#include<iostream>#include<cstring>#include<cstdio>#include<vector>#include<string>#include<queue>#include<map>///LOOP#define REP(i, n) for(int i = 0; i < n; i++)#define FF(i, a, b) for(int i = a; i < b; i++)#define FFF(i, a, b) for(int i = a; i <= b; i++)#define FD(i, a, b) for(int i = a - 1; i >= b; i--)#define FDD(i, a, b) for(int i = a; i >= b; i--)///INPUT#define RI(n) scanf("%d", &n)#define RII(n, m) scanf("%d%d", &n, &m)#define RIII(n, m, k) scanf("%d%d%d", &n, &m, &k)#define RIV(n, m, k, p) scanf("%d%d%d%d", &n, &m, &k, &p)#define RV(n, m, k, p, q) scanf("%d%d%d%d%d", &n, &m, &k, &p, &q)#define RFI(n) scanf("%lf", &n)#define RFII(n, m) scanf("%lf%lf", &n, &m)#define RFIII(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)#define RFIV(n, m, k, p) scanf("%lf%lf%lf%lf", &n, &m, &k, &p)#define RS(s) scanf("%s", s)///OUTPUT#define PN printf("\n")#define PI(n) printf("%d\n", n)#define PIS(n) printf("%d ", n)#define PS(s) printf("%s\n", s)#define PSS(s) printf("%s ", s)#define PC(n) printf("Case %d: ", n)///OTHER#define PB(x) push_back(x)#define CLR(a, b) memset(a, b, sizeof(a))#define CPY(a, b) memcpy(a, b, sizeof(b))#define display(A, n, m) {REP(i, n){REP(j, m)PIS(A[i][j]);PN;}}#define lson l, m, rt << 1#define rson m + 1, r, rt << 1 | 1using namespace std;typedef long long LL;typedef pair<int, int> P;const int MOD = 1e9+7;const int INFI = 1e9 * 2;const LL LINFI = 1e17;const double eps = 1e-6;const int N = 222222;const int M = N << 2;const int move[8][2] = {0, 1, 0, -1, 1, 0, -1, 0, 1, 1, 1, -1, -1, 1, -1, -1};int c[N], mask[N];void add(int x, int v){ while(x < N) { c[x] += v; x += x & (-x); }}int sum(int x){ int s = 0; while(x > 0) { s += c[x]; x -= x & (-x); } return s;}int main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int t, n, m, a; RI(t); while(t--) { RII(n, m); CLR(c, 0); FFF(i, 1, n) { add(i, 1); mask[i] = n - i + 1; } while(m--) { RI(a); printf("%d%c", n - sum(mask[a]), m ? ' ' : '\n'); add(1, 1); add(mask[a], -1); mask[a] = ++n; add(mask[a], 1); } } return 0;}
- UVALive 5902 Movie collection
- UvaLive-5902-Movie collection
- UVALive 5902 Movie collection
- UVALive - 5902 Movie collection
- UVALive 5902 Movie collection
- UVALive - 5902 Movie collection 二叉索引树
- UVALive 5902 Movie collection(树状数组)
- UVa 1513 / UVALive 5902 Movie collection (树状数组)
- UVa 1513 / UVALive 5902 Movie collection (树状数组)
- Movie collection
- Movie collection
- LA 5902 Movie collection (树状数组)
- SPOJ NWERC11C Movie collection
- uva 1513 - Movie collection
- UVa:1513 Movie collection
- Uva-1513-Movie collection
- UVa-1513-Movie collection
- UVA 1513 Movie collection
- IIS & Application Pool & App Domain & ...
- tar 压缩和解压缩使用笔记
- android颜色对应的xml配置值,颜色表
- Log4j启动过程
- linux内核--进程地址空间(三)
- UVALive 5902 Movie collection
- SQL Server 查询条件是中文查不出来
- TLAB ( Thread Local Allocation Buffers )
- 学习笔记:修改网吧计费系统
- java自动生成mybatis新增sql语句
- Linux下nm和ldd 命令
- 广度优先遍历二叉树实现
- 状压dp-poj-1170-Shopping Offers
- 学习笔记:找回电脑开机密码