hdu4217 Data Structure?
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.
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
3 2
1 1
10 3
3 9 1
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?的更多相关文章
- [LeetCode] All O`one Data Structure 全O(1)的数据结构
Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...
- [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计
Design a data structure that supports the following two operations: void addWord(word) bool search(w ...
- [LeetCode] Two Sum III - Data structure design 两数之和之三 - 数据结构设计
Design and implement a TwoSum class. It should support the following operations:add and find. add - ...
- 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 ...
- Mesh Data Structure in OpenCascade
Mesh Data Structure in OpenCascade eryar@163.com 摘要Abstract:本文对网格数据结构作简要介绍,并结合使用OpenCascade中的数据结构,将网 ...
- ✡ 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 - ...
- leetcode Add and Search Word - Data structure design
我要在这里装个逼啦 class WordDictionary(object): def __init__(self): """ initialize your data ...
- 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 ...
- HDU5739 Fantasia(点双连通分量 + Block Forest Data Structure)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5739 Description Professor Zhang has an undirect ...
随机推荐
- GMT UTC CST ISO 夏令时 时间戳,都是些什么鬼?
目录 ✍前言 本文提纲 版本约定 ✍正文 GMT:格林威治时间 凭什么格林威治作为标准时间? 地球自转 中国有哪几个时区? 美国有哪几个时区? GMT和Http协议的渊源 UTC:世界标准时间 UTC ...
- 【Linux】find删除365天以前的文件详细解析
find . -name "*" -mtime +365 -exec rm -rf {} \; -mtime +365 文件被修改的时间,最后一次发生到现在365天 -atime ...
- 设计一款兼容ST207和GD207的开发板
在MCU的学习中,大部分人都是学习别人的开发板,例如正点原子.野火等,优点是有可靠的教程和代码,缺点是容易让人有种自己全部都学会的了错觉,听了课程编写了代码,运行正常. 这个时候,可以尝试自已做一块属 ...
- 安装newman error:package exports for 'c:\nmp\node_modules\newman\node_module 解决办法
一.场景描述: 通过npm安装newman时,一直失败. 尝试了很多安装命令: npm install -g newman npm install -g newman --registry=http: ...
- LeetCode454. 四数相加 II
题目 给定四个包含整数的数组列表 A , B , C , D ,计算有多少个元组 (i, j, k, l) ,使得 A[i] + B[j] + C[k] + D[l] = 0. 分析 关键是如何想到用 ...
- Sentry(v20.12.1) K8S 云原生架构探索,JavaScript 性能监控之管理 Transactions
系列 Sentry-Go SDK 中文实践指南 一起来刷 Sentry For Go 官方文档之 Enriching Events Snuba:Sentry 新的搜索基础设施(基于 ClickHous ...
- 1V转5V芯片,三个元件即可组成完整的稳压方案
1V低电压要转成5V的电压,需要1V转5V的芯片,由于1V输入,所以不需要指望能输出多大的电流,压差和1V的供电电压意味着供电电流也是无法做大的了.一般1V转5V的输出电流在0MA-100mA,一般6 ...
- 判断最长回文串——暴力、延展、Manacher
1. 暴力 时间复杂度O(n^3). 2. 延展 以某一字符为中心,设置left, right两个变量同时向外扩,判断他们指向字符是否相同.注意分奇偶讨论.时间复杂度O(n^2). 3. Manach ...
- 从零搭建一个IdentityServer——项目搭建
本篇文章是基于ASP.NET CORE 5.0以及IdentityServer4的IdentityServer搭建,为什么要从零搭建呢?IdentityServer4本身就有很多模板可以直接生成一个可 ...
- Docker的Ubuntu镜像安装的容器无ifconfig命令和ping命令
就这三步骤,下面的是实例不看也罢. apt-get update ###第一步一定要先执行这个更新下.不更新下面的安装命令会显示找不到网络包 //ifconfig apt install net-to ...