hdu 3577 线段树

题意:一列经过1000000个站点的火车上最多同时乘坐 K 个人,有 Q 个乘客按照题目给出的顺序去买票,输出所有购票成功的乘客

做法:RMQ线段树 + 区间更新

  1 #include "bits/stdc++.h"
  2 using namespace std;
  3 #define lson l, m, rt<<1
  4 #define rson m + 1, r, rt<<1|1
  5 const int MAXN = 1000010;
  6 const int INF = 0x3f3f3f3f;
  7 
  8 struct Node
  9 {
 10     int Max;
 11 
 12     int add;
 13     bool same;
 14     int sameVal;
 15 }node[MAXN<<2];
 16 
 17 inline void PushDown(int rt, int segLen)
 18 {
 19     if (node[rt].same) {
 20         node[rt<<1].Max = node[rt].sameVal;
 21         node[rt<<1|1].Max = node[rt].sameVal;
 22 
 23         node[rt<<1].same = node[rt<<1|1].same = true;
 24         node[rt<<1].sameVal = node[rt<<1|1].sameVal = node[rt].sameVal;
 25         node[rt].same = false;
 26     }
 27     if(node[rt].add) {
 28         node[rt<<1].Max += node[rt].add;
 29         node[rt<<1|1].Max += node[rt].add;
 30 
 31         node[rt<<1].add += node[rt].add;
 32         node[rt<<1|1].add += node[rt].add;
 33         node[rt].add = 0;
 34     }
 35 }
 36 
 37 inline void PushUp(int rt)
 38 {
 39     node[rt].Max = max(node[rt<<1].Max, node[rt<<1|1].Max);
 40 }
 41 
 42 void Build(int l, int r, int rt)
 43 {
 44     node[rt].same = false;
 45     node[rt].add = 0;
 46 
 47     if (l == r) {
 48 //        scanf("%d", &node[rt].Max);
 49         node[rt].Max = 0;
 50         return ;
 51     }
 52     int m = (l + r)>>1;
 53     Build(lson);
 54     Build(rson);
 55 
 56     PushUp(rt);
 57 }
 58 
 59 void UpdateAdd(int p, int add, int l, int r, int rt)
 60 {
 61     if (l == r) {
 62         node[rt].Max += add;
 63         return ;
 64     }
 65     PushDown(rt, r - l + 1);
 66     int m = (l + r) >> 1;
 67     if (p <= m) {
 68         UpdateAdd(p, add, lson);
 69     }
 70     else {
 71         UpdateAdd(p, add, rson);
 72     }
 73 
 74     PushUp(rt);
 75 }
 76 
 77 void UpdateModify(int p, int newVal, int l, int r, int rt)
 78 {
 79     if (l == r) {
 80         node[rt].Max = newVal;
 81         return ;
 82     }
 83     PushDown(rt, r - l + 1);
 84     int m = (l + r) >> 1;
 85     if (p <= m) {
 86         UpdateModify(p, newVal, lson);
 87     }
 88     else {
 89         UpdateModify(p, newVal, rson);
 90     }
 91 
 92     PushUp(rt);
 93 }
 94 
 95 void UpdateAdd_Seg(int L, int R, int add, int l, int r, int rt)
 96 {
 97     if (L <= l && r <= R) {
 98         node[rt].Max += add;
 99 
100         node[rt].add += add;
101         return ;
102     }
103 
104     PushDown(rt, r - l + 1);
105     int m = (l + r) >> 1;
106     if (L <= m) {
107         UpdateAdd_Seg(L, R, add, lson);
108     }
109     if (R > m) {
110         UpdateAdd_Seg(L, R, add, rson);
111     }
112 
113     PushUp(rt);
114 }
115 
116 void UpdateModify_Seg(int L, int R, int newVal, int l, int r, int rt)
117 {
118     if (L <= l && r <= R) {
119         node[rt].Max = newVal;
120 
121         node[rt].same = true;
122         node[rt].sameVal = newVal;
123         return ;
124     }
125 
126     PushDown(rt, r - l + 1);
127     int m = (l + r) >> 1;
128     if (L <= m) {
129         UpdateModify_Seg(L, R, newVal, lson);
130     }
131     if (R > m) {
132         UpdateModify_Seg(L, R, newVal, rson);
133     }
134 
135     PushUp(rt);
136 }
137 
138 
139 int Query(int L, int R, int l, int r, int rt)
140 {
141     if (L <= l && r <= R) {
142         return node[rt].Max;
143     }
144     PushDown(rt, r - l + 1);
145     int m = (l + r) >> 1;
146     int ans = -INF;
147     if (L <= m) {
148         ans = max(ans, Query(L, R, lson));
149     }
150     if (R > m) {
151         ans = max(ans, Query(L, R, rson));
152     }
153     return ans;
154 }
155 
156 int n, m;
157 int POS, ADD, NewVal, L, R;
158 
159 int main()
160 {
161     int t, T, K, Q;
162     scanf("%d", &T);
163     for (t = 1; t <= T; ++t) {
164         Build(1, 1000000, 1);
165         scanf("%d%d", &K, &Q);
166         int index = 0;
167         printf("Case %d:\n", t);
168         while (Q--) {
169             ++index;
170             scanf("%d%d", &L, &R);
171             if(Query(L, R - 1, 1, 1000000, 1) < K) {
172                 printf("%d ", index);
173                 UpdateAdd_Seg(L, R - 1, 1, 1, 1000000, 1);
174             }
175         }
176         printf("\n\n");
177     }
178 }

 

转载于:https://www.cnblogs.com/AC-Phoenix/p/4686449.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
东南亚位于我国倡导推进的“一带一路”海陆交汇地带,作为当今全球发展最为迅速的地区之一,近年来区域内生产总值实现了显著且稳定的增长。根据东盟主要经济体公布的最新数据,印度尼西亚2023年国内生产总值(GDP)增长5.05%;越南2023年经济增长5.05%;马来西亚2023年经济增速为3.7%;泰国2023年经济增长1.9%;新加坡2023年经济增长1.1%;柬埔寨2023年经济增速预计为5.6%。 东盟国家在“一带一路”沿线国家中的总体GDP经济规模、贸易总额与国外直接投资均为最大,因此有着举足轻重的地位和作用。当前,东盟与中国已互相成为双方最大的交易伙伴。中国-东盟贸易总额已从2013年的443亿元增长至 2023年合计超逾6.4万亿元,占中国外贸总值的15.4%。在过去20余年中,东盟国家不断在全球多变的格局里面临挑战并寻求机遇。2023东盟国家主要经济体受到国内消费、国外投资、货币政策、旅游业复苏、和大宗商品出口价企稳等方面的提振,经济显现出稳步增长态势和强韧性的潜能。 本调研报告旨在深度挖掘东南亚市场的增长潜力与发展机会,分析东南亚市场竞争态势、销售模式、客户偏好、整体市场营商环境,为国内企业出海开展业务提供客观参考意见。 本文核心内容: 市场空间:全球行业市场空间、东南亚市场发展空间。 竞争态势:全球份额,东南亚市场企业份额。 销售模式:东南亚市场销售模式、本地代理商 客户情况:东南亚本地客户及偏好分析 营商环境:东南亚营商环境分析 本文纳入的企业包括国外及印尼本土企业,以及相关上下游企业等,部分名单 QYResearch是全球知名的大型咨询公司,行业涵盖各高科技行业产业链细分市场,横跨如半导体产业链(半导体设备及零部件、半导体材料、集成电路、制造、封测、分立器件、传感器、光电器件)、光伏产业链(设备、硅料/硅片、电池片、组件、辅料支架、逆变器、电站终端)、新能源汽车产业链(动力电池及材料、电驱电控、汽车半导体/电子、整车、充电桩)、通信产业链(通信系统设备、终端设备、电子元器件、射频前端、光模块、4G/5G/6G、宽带、IoT、数字经济、AI)、先进材料产业链(金属材料、高分子材料、陶瓷材料、纳米材料等)、机械制造产业链(数控机床、工程机械、电气机械、3C自动化、工业机器人、激光、工控、无人机)、食品药品、医疗器械、农业等。邮箱:market@qyresearch.com

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值