HUD-4217-Data Structure?
来源:互联网 发布:德军总部2 知乎 编辑:程序博客网 时间:2024/05/16 01:02
//题意就是给你1-n的数,叫你每次删除第K小的数,求删除这些数的和//
AC代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long longconst int MAX=262145;int sum[MAX<<2];void build(int l,int r,int rt){ sum[rt]=r-l+1;//一共有多少个节点 if(l==r) { return; } int m=(l+r)>>1; build(lson); build(rson);}int updata(int x,int l,int r,int rt){ sum[rt]--; if(l==r) { return l; } int m=(l+r)>>1; if(sum[rt<<1]>=x) updata(x,lson); else updata(x-sum[rt<<1],rson);//x-sum[rt<<1]代表它在右边的第几小}int main(){ int t; scanf("%d",&t); int k=1; while(t--) { int n,m; scanf("%d%d",&n,&m); build(1,n,1); int i; int x; LL s=0; for(i=1;i<=m;i++) { scanf("%d",&x); s+=updata(x,1,n,1); } printf("Case %d: %lld\n",k++,s); } return 0;}
0 0
- HUD-4217-Data Structure?
- hdoj 4217 Data Structure?
- hdu-4217Data Structure?
- hdu 4217 Data Structure?
- HDOJ-4217 Data Structure
- HDU 4217 Data Structure?
- hdu 4217Data Structure?
- hdu 4217 Data Structure? treap
- hdu 4217 Data Structure?/SBT
- Data Structure
- Data structure
- Data Structure
- Data structure
- Data structure
- data structure
- Data Structure
- Data structure
- Data Structure
- Git合并特定commits 到另一个分支
- PL/SQL 数据表id自增
- 马云再一次颠覆革命!支付宝又逆天:不用钱包不用手机照样支付
- xp用户密码破解
- 面试题7:用两个栈实现队列,队列的声明如下,请实现它的两个函数appendTail和deleteHead, 分别完成在队列尾部插入结点和在队列头部删除节点的功能。
- HUD-4217-Data Structure?
- sem_init on OS X
- LeetCode题解:Factorial Trailing Zeroes
- JSTL标签结合EL表达式——java web前端瘦身器
- 20Valid Parentheses
- 10+统计整数的二进制中1的个数
- [java基础] &和&&的区别。
- bind port打印时:short 和 unsigned short的区别
- C++ 静态多态和动态多态 浅析