Problem Description
Data structure is one of the basic skills for Computer Science students, which is a particular way of storing and organizing data in a computer so that it can be used efficiently. Today let me introduce a data-structure-like problem for you.

Original, there are N numbers, namely 1, 2, 3...N. Each round, iSea find out the Ki-th smallest number and take it away, your task is reporting him the total sum of the numbers he has taken away.
 

Input
The first line contains a single integer T, indicating the number of test cases.

Each test case includes two integers N, K, K indicates the round numbers. Then a line with K numbers following, indicating in i (1-based) round, iSea take away the Ki-th smallest away.

Technical Specification

1. 1 <= T <= 128

2. 1 <= K <= N <= 262 144

3. 1 <= Ki <= N - i + 1
 

Output
For each test case, output the case number first, then the sum.
 

Sample Input

2
3 2
1 1
10 3
3 9 1
 

Sample Output

Case 1: 3

Case 2: 14

这题是简单的插空问题,只要维护每条线段还剩多少空就行,坑点是要用__int64,wa了两次。。

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<algorithm>
using namespace std;
__int64 sum;
struct node{
int l,r,num;
}b[8*300000]; void build(int l,int r,int i)
{
int mid;
b[i].l=l;b[i].r=r;b[i].num=r-l+1;
if(l==r)return;
mid=(l+r)/2;
build(l,mid,i*2);
build(mid+1,r,i*2+1);
} void question(int index,int i)
{
int mid;
if(b[i].l==b[i].r){
sum+=b[i].l;
b[i].num=0;return;
}
if(b[i*2].num>=index)question(index,i*2);
else question(index-b[i*2].num,i*2+1);
b[i].num=b[i*2].num+b[i*2+1].num;
} int main()
{
int n,m,i,j,T,num1=0,c;
scanf("%d",&T);
while(T--)
{
num1++;
//printf("\n",num1);
scanf("%d%d",&n,&m);
build(1,n,1);
sum=0;
for(i=1;i<=m;i++){
scanf("%d",&c);
question(c,1);
}
printf("Case %d: %I64d\n",num1,sum);
}
return 0;
}

hdu4217 Data Structure?的更多相关文章

  1. [LeetCode] All O`one Data Structure 全O(1)的数据结构

    Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...

  2. [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  3. [LeetCode] Two Sum III - Data structure design 两数之和之三 - 数据结构设计

    Design and implement a TwoSum class. It should support the following operations:add and find. add - ...

  4. Finger Trees: A Simple General-purpose Data Structure

    http://staff.city.ac.uk/~ross/papers/FingerTree.html Summary We present 2-3 finger trees, a function ...

  5. Mesh Data Structure in OpenCascade

    Mesh Data Structure in OpenCascade eryar@163.com 摘要Abstract:本文对网格数据结构作简要介绍,并结合使用OpenCascade中的数据结构,将网 ...

  6. ✡ leetcode 170. Two Sum III - Data structure design 设计two sum模式 --------- java

    Design and implement a TwoSum class. It should support the following operations: add and find. add - ...

  7. leetcode Add and Search Word - Data structure design

    我要在这里装个逼啦 class WordDictionary(object): def __init__(self): """ initialize your data ...

  8. Java for LeetCode 211 Add and Search Word - Data structure design

    Design a data structure that supports the following two operations: void addWord(word)bool search(wo ...

  9. HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...

随机推荐

  1. ruby+watir安装指南

    安装ruby+watir一共需要下面几个步骤 1. 安装ruby: 2. 升级Rubygems:Rubygems(简称 gems)是一个用于对 Ruby组件进行打包的 Ruby 打包系统. 它提供一个 ...

  2. 计网Q1:多个方面比较电路交换、报文交换和分组交换的主要优缺点

    网上看到的带佬儿的帖子......膜过来<doge 原文链接: https://blog.csdn.net/njchenyi/article/details/1540657 电路交换: 由于电路 ...

  3. ASP.NET Core错误处理中间件[3]: 异常处理器

    DeveloperExceptionPageMiddleware中间件错误页面可以呈现抛出的异常和当前请求上下文的详细信息,以辅助开发人员更好地进行纠错诊断工作.ExceptionHandlerMid ...

  4. 3A的限流芯片PW1503

    PW1503是超低RDS(ON)开关,具有可编程的电流限制,以保护电源于过电流和短路情况.它具有超温保护以及反向闭锁功能. PW1503采用薄型(1毫米)5针薄型SOT封装,提供可调版本. 特征    ...

  5. React 入门-redux 和 react-redux

    React 将页面元素拆分成组件,通过组装展示数据.组件又有无状态和有状态之分,所谓状态,可以简单的认为是组件要展示的数据.React 有个特性或者说是限制单向数据流,组件的状态数据只能在组件内部修改 ...

  6. Kubernetes集群管理工具kubectl命令技巧大全

    一. kubectl概述 Kubectl是用于控制Kubernetes集群的命令行工具,通过kubectl能够对集群本身进行管理,并能够在集群上进行容器化应用的安装部署. kubectl命令的语法如下 ...

  7. CentOS系统内核升级(在线 离线)

    为什么要升级内核? Docker 在CentOS系统中需要安装在 CentOS 7 64 位的平台,并且内核版本不低于 3.10:CentOS 7.× 满足要求的最低内核版本要求,但由于 CentOS ...

  8. 夯实基础系列四:Linux 知识总结

    前言 前三节内容传送门: 夯实基础系列一:Java 基础总结 夯实基础系列二:网络知识总结 夯实基础系列三:数据库知识总结 现在很多公司项目部署都使用的是 Linux 服务器,互联网公司更是如此.对于 ...

  9. :setting:`task_soft_time_limit` celery 异步任务 执行时间限制 内存限制

    https://docs.celeryproject.org/en/stable/userguide/configuration.html?highlight=control_exchange#new ...

  10. (Sql Server)存储过程(转载)

    SQL Server 存储过程 Transact-SQL中的存储过程,非常类似于Java语言中的方法,它可以重复调用.当存储过程执行一次后,可以将语句缓存中,这样下次执行的时候直接使用缓存中的语句.这 ...