【poj2828】Buy Tickets (segment tree+贪心)

VS Code Live Share 实时协作原理与工程实践指南 Live Share 是基于 Visual Studio Code 的实时协同开发协议,其核心并非远程桌面或云端托管,而是依托 Language Server Protocol(LSP)和 Debug Adapter Protocol(DAP)实现语义级代码共享,通过 WebRTC 建立 Host-Guest 端到端直连,保障源码不离本地、权限精细可控。该技术显著提升结对编程、远程调试与代码评审效率,适用于跨时区团队、安全敏感场景及新人上手等典型工程需求,是现代 IDE 协作范式的关键基础设施。 阅读详情

F - Buy Tickets
Time Limit:4000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Submit

Status
Description
Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue…

The Lunar New Year was approaching, but unluckily the Little Cat still had schedules going here and there. Now, he had to travel by train to Mianyang, Sichuan Province for the winter camp selection of the national team of Olympiad in Informatics.

It was one o’clock a.m. and dark outside. Chill wind from the northwest did not scare off the people in the queue. The cold night gave the Little Cat a shiver. Why not find a problem to think about? That was none the less better than freezing to death!

People kept jumping the queue. Since it was too dark around, such moves would not be discovered even by the people adjacent to the queue-jumpers. “If every person in the queue is assigned an integral value and all the information about those who have jumped the queue and where they stand after queue-jumping is given, can I find out the final order of people in the queue?” Thought the Little Cat.

Input
There will be several test cases in the input. Each test case consists of N + 1 lines where N (1 ≤ N ≤ 200,000) is given in the first line of the test case. The next N lines contain the pairs of values Posi and Vali in the increasing order of i (1 ≤ i ≤ N). For each i, the ranges and meanings of Posi and Vali are as follows:

Posi ∈ [0, i − 1] — The i-th person came to the queue and stood right behind the Posi-th person in the queue. The booking office was considered the 0th person and the person at the front of the queue was considered the first person in the queue.
Vali ∈ [0, 32767] — The i-th person was assigned the value Vali.
There no blank lines between test cases. Proceed to the end of input.

Output
For each test cases, output a single line of space-separated integers which are the values of people in the order they stand in the queue.

Sample Input
4
0 77
1 51
1 33
2 69
4
0 20523
1 19243
1 3890
0 31492
Sample Output
77 33 69 51
31492 20523 3890 19243
Hint
The figure below shows how the Little Cat found out the final order of people in the queue described in the first test case of the sample input.

题意:顺序插队,输出队列。
思路:
1.倒序判断; (无后效性)
2.线段树实现sequence 的空空间;

#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<map>
#define lson (id*2)
#define rson (id*2+1)
using namespace std;
struct node{
    int x,y;
} aa[300000];
int tree[800005];
int n;
map<int,int> ans;
void push_up(int id)
{
    tree[id]=tree[lson]+tree[rson];
}
void build(int id,int l,int r)
{
    if(l==r)
    {
        tree[id]=1;
        return ;
    }
    int mid=(l+r)>>1;
    build(lson,l,mid);
    build(rson,mid+1,r);
    push_up(id);
}
void add(int id,int l,int r,int pos,int V)
{
    if(l==r)
    {
        ans[l]=V;
        tree[id]--;
        return;
    }
    int mid=(l+r)>>1;
    if(tree[lson]<pos) add(rson,mid+1,r,pos-tree[lson],V);  //倒着走能往前站往前站 
    else  add(lson,l,mid,pos,V);
    push_up(id);
}
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        build(1,1,n);
        for(int i=1;i<=n;i++)   scanf("%d%d",&aa[i].x,&aa[i].y);

        for(int i=n;i>=1;i--)
        {
            aa[i].x++;
            add(1,1,n,aa[i].x,aa[i].y);
        }
        for(int i=1;i<=n;i++)
        printf("%d ",ans[i]);
        printf("\n");
    }
}

再插个逆序对贪心

和排队似的倒序插入
ZYB’s Premutation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 207 Accepted Submission(s): 93

Problem Description
ZYB has a premutation P,but he only remeber the reverse log of each prefix of the premutation,now he ask you to
restore the premutation.

Pair (i,j)(i

#include<iostream>
#include<stdio.h>
#define lson (id*2)
#define rson (id*2+1)
using namespace std;
int T;
int n;
struct nod{
    int val;
}tree[50000*8];
int a[50005];
int ans[50005];
void push_up(int id)
{
    tree[id].val=tree[lson].val+tree[rson].val;
}
void build(int id,int l,int r)
{
    if(l==r)
    {
        tree[id].val=1;
        return ;
    }
    int mid=(l+r)>>1;
    build(lson,l,mid);
    build(rson,mid+1,r);
    push_up(id);
}
void add(int id,int l,int r,int pos,int V)
{
    if(l==r)
    {
        ans[V]=l;
        tree[id].val=0;
        return ;
    }
    int mid=(l+r)>>1;
    if(pos>tree[rson].val)
    {
        add(lson,l,mid,pos-tree[rson].val,V);//能往大求往大求!!!
    }
    else
    {
        add(rson,mid+1,r,pos,V);
    }
    push_up(id);
}
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        int bb,cc=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&bb);
            a[i]=bb-cc;
            cc=bb;
        }
        build(1,1,n);
        for(int i=n;i>=1;i--)
        {
            add(1,1,n,a[i]+1,i);
        }
        for(int i=1;i<=n;i++)
        {
            if(i!=1)
            {

                printf(" ");
            }
            printf("%d",ans[i]);
        }

        printf("\n");
    }
}
SSD2828QN4_1.0 (2013_02_03 18_51_31 UTC).pdf RGB转MIPI芯片手册SSD2828,应用场景RGB转MIPI信号,分辨率最大支持1920*1200 60Hz,信号是by pass,不支持放大缩小功能; 立即下载

相关推荐

从零开始:TexLive(Latex)安装与配置全指南

本文提供了一份详尽的TexLive(Latex)安装与配置全指南,旨在帮助用户从零开始快速搭建LaTeX工作环境。内容涵盖从镜像下载、安装步骤详解、环境验证到高效编辑器(如VS Code)配置,并特别强调了中文排版支持与宏包管理,确保用户能顺利处理学术论文等专业文档的排版需求。

weixin_29284885的博客 903

Buy Tickets (线段树)

题目:Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year was approaching, but unluckily the Little Cat still had schedules going here and there. Now, he had to travel by

qq_61037155的博客 282

PT静态时序分析实战:从基础命令到高级报告解析

本文详细介绍了PT(PrimeTime)静态时序分析(STA)的实战技巧,从基础命令如pt_shell和report_timing的使用,到高级报告解析与问题排查。通过丰富的实例和脚本示例,帮助工程师快速掌握时序分析的核心技能,提升芯片设计验证效率。

weixin_29289821的博客 954

poj 2828 Buy Tickets 线段树

&#13; 题意/Description:&#13;     Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue…&#13;     The Lunar New Year was appro...

peter_zhu01的博客 201

教你搞懂RT-Thread的移植和配置ENV工具环境

RT-Thread的移植和配置ENV工具环境

Troubadour~的博客 8263

syslog RFC5424协议详解

RFC5424协议解读与报文分析。

chenwr2018的博客 6690

【ECJTU_ACM 11级队员2012年暑假训练赛(8) - E - Buy Tickets】

Home Problems Status Contest Register Login B题要套一个数论的模版,注意m=1!! C题可以二分匹配,把行列看作点; 不能开百度,开谷歌搜题解,再次强调!一经发现,取消成绩! ECJTU_ACM 11级队员2012年暑假训练赛(8) 4:30:00 Overview Problem ...

weixin_33670713的博客 266

Manus通用AI智能体完全使用指南(2025最新版)——从注册到高阶技巧全解析

Manus通用AI智能体完全使用指南(2025最新版)——从注册到高阶技巧全解析

m0_69718028的博客 8116

Buy Tickets

Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year was approaching, but unluckily the Little Cat still had schedules going here and there. Now,

weixin_56432482的博客 278

【二.图像处理核心技术】【5.形态学操作:腐蚀/膨胀/开闭运算】

想象一下,你拍了一张布满雪花点的老照片,或者扫描了字迹断裂的文档,这时候形态学操作就是你的像素整形师!它们能让模糊的边界变清晰,把断裂的笔画连起来,甚至从X光片里揪出癌细胞。今天我们要聊的,是计算机视觉界的"广场舞双雄"——腐蚀和膨胀。这俩操作就像给像素点们请了个健身教练,要么集体减肥(腐蚀),要么组团增肌(膨胀)。下次当你用美颜相机时,不妨会心一笑——这看似魔法的背后,正是形态学在默默耕耘。腐蚀的规则很简单:如果一个像素点周围的邻居不全白,它就"狗带"(变黑)。:先用砂纸打磨(腐蚀),再喷漆填补(膨胀)

商务合作|问题讨论|交流学习 请联系作者微信,加微信请务必注明来意,博客主页有联系方式 425

基于YOLO26深度学习框架的人脸识别门禁系统的算法研究实现方法

本文研究了基于YOLO26深度学习框架的人脸识别门禁系统实现方法。系统采用YOLO26目标检测算法,通过CSPDarknet53主干网络、特征金字塔结构和注意力机制实现高效人脸检测。研究内容包括数据预处理、模型训练优化和身份验证等关键技术,使用迁移学习策略和CIoU损失函数提升检测精度。该系统可应用于智能安防场景,具有实时性强、识别准确的特点,为门禁管理提供了智能化解决方案。

一键难忘的博客 766

SSD2828QN4调试技术经验分享第1节

相信大家能够搜索到这篇文章,应该是遇到了调试方面的问题。我先简单介绍一下SSD2828QN4的功能:● 输入信号RGB 16/18/24Bit  PCLK最大支持150Mhz;● 输出信号MIPI DSI 1.01 D-PHY1.00 , 4lanes mipi,每条lane速度最大为1GHz(需要更快可以用SSD2828TQL9);● 适用于屏必须是video mode mipi信号;● 封装为...

xiebo5244407的博客 1万+

13、7自由度机械臂混合逆运动学算法解析

本文介绍了一种针对7自由度机械臂的混合逆运动学算法,通过引入额外参数Φ解决冗余自由度问题,并实现了避障、避免关节超限和扩大工作空间。该方法采用解析逆运动学求解策略,克服了机械臂在奇异位姿时的配置不连续性问题。通过对比实验验证了该算法在腕部关节角度连续性和位姿可达性方面的优越性,同时结合躯干逆运动学显著扩展了机械臂的工作空间。

rgv23456789的博客 237

HDU 2828 Buy Tickets

Buy Tickets Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 7553 Accepted: 3599 Description Railway tickets were difficult to buy around the Lunar New Year...

weixin_30271335的博客 212

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Buy Tickets (线段树----容易理解的方法)

Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue…The Lunar New Year was approaching, but unluckily the Little Cat still had sched...

短发 1739

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

POJ 2828

Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 10746   Accepted: 5211 Description Railway tickets were difficult to buy around the Lunar New Yea

XMzhou的专栏 855

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

poj 2828 Buy Tickets -插队问题-单节点更新-线段树

Buy Tickets Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year was approaching, but unluckily the Little Cat still had schedules going here and there. Now, he had to t

ly59782的博客 671

poj2828--Buy Tickets(线段树+详解)

Buy Tickets Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 13618   Accepted: 6802 Description Railway tickets were difficult to buy around the Lunar New Yea

随风的专栏 4758

POJ 2828 排队插队(线段树_好题)

Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year was approaching, but unluckily the Little Ca

AK_HuangYC的博客 1758

POJ2828:Buy Tickets(线段树单点)

Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year was approaching, but unluckily the Little Ca

ACM!荣耀之路! 6498

nbut线段树专题M - Buy Tickets

DescriptionRailway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue…The Lunar New Year was approaching, but unluckily the Little Cat stil

Alex 603

POJ2828 Buy Tickets (权值线段树上二分)

Buy Tickets Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year was approaching, but unluckily the Little Cat st...

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz 226

poj-2828 Buy Tickets(线段树,排队问题,逆向思维)

题目地址:POJ 2828 Buy Tickets Description Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue… The Lunar New Year was appro...

weixin_30299539的博客 214

Buy Tickets (插队问题)

传送门HDU - 1754描述 Railway tickets were difficult to buy around the Lunar New Year in China, so we must get up early and join a long queue…The Lunar New Year was approachi...

测试 870

第五周周末总结

今天回老家回来有点晚了,先把代码敲出来,明天调吧,困死。。。 Buy Tickets Time Limit : 8000/4000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) Total Submission(s) : 18   Accepted Submission(s) : 8 Problem Descript

的博客 306
上一篇: 【codeforces 115E】Linear Kingdom Races (datestructs(seg.tree)+dp)
下一篇: NOI 2015 d1t2 洛谷 【P2146】 软件包管理器
ALPS233
博客等级 码龄11年 25粉丝 191原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值