博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Welfare State CodeForces - 1199D(线段树)
阅读量:4136 次
发布时间:2019-05-25

本文共 2615 字,大约阅读时间需要 8 分钟。

There is a country with n citizens. The i-th of them initially has ai money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioning the amount of money they currently have.

Sometimes the government makes payouts to the poor: all citizens who have strictly less money than x are paid accordingly so that after the payout they have exactly x money. In this case the citizens don’t send a receipt.

You know the initial wealth of every citizen and the log of all events: receipts and payouts. Restore the amount of money each citizen has after all events.

Input

The first line contains a single integer n (1≤n≤2⋅105) — the numer of citizens.

The next line contains n integers a1, a2, …, an (0≤ai≤109) — the initial balances of citizens.

The next line contains a single integer q (1≤q≤2⋅105) — the number of events.

Each of the next q lines contains a single event. The events are given in chronological order.

Each event is described as either 1 p x (1≤p≤n, 0≤x≤109), or 2 x (0≤x≤109). In the first case we have a receipt that the balance of the p-th person becomes equal to x. In the second case we have a payoff with parameter x.

Output

Print n integers — the balances of all citizens after all events.

Examples

Input
4
1 2 3 4
3
2 3
1 2 2
2 1
Output
3 2 3 4
Input
5
3 50 2 1 10
3
1 2 0
2 8
1 3 20
Output
8 8 20 8 10
Note
In the first example the balances change as follows: 1 2 3 4 → 3 3 3 4 → 3 2 3 4 → 3 2 3 4

In the second example the balances change as follows: 3 50 2 1 10 → 3 0 2 1 10 → 8 8 8 8 10 → 8 8 20 8 10

两种操作,一种就是单点更新,另一种就是将1~n之间权值小于x的更新为x。
第一种就是普通的线段树就能做到的。
主要是第二种操作,我一开始是随时更新到叶子节点,结果第五个就TLE了。
那么只能是延迟更新,维护一个最小值,如果最小值大于要更新成的x,就直接返回不更新。否则就将lazy标记为x,在update和Query里面去不断的往下推,去更新节点的值。pushdown函数里面要注意条件。嘤嘤嘤
代码如下:

#include
#include
#include
#include
#define ll long longusing namespace std;const int maxx=2e5+100;struct node{ int l; int r; int v; int lazy; int _min;}p[maxx<<2];int a[maxx];int n;inline void pushup(int cur){ p[cur]._min=min(p[cur<<1]._min,p[cur<<1|1]._min);}inline void pushdown(int cur){ //cout<
<
>1; build(l,mid,cur<<1); build(mid+1,r,cur<<1|1); pushup(cur);}inline void update(int x,int add,int cur){ int L=p[cur].l; int R=p[cur].r; if(L==R) { p[cur]._min=p[cur].v=add; return ; } pushdown(cur); int mid=L+R>>1; if(x<=mid) update(x,add,cur<<1); else update(x,add,cur<<1|1); pushup(cur);}inline void Update(int cur,int x){ if(p[cur]._min>=x) return ; if(p[cur]._min

努力加油a啊,(o)/~

转载地址:http://nfxvi.baihongyu.com/

你可能感兴趣的文章
USB OTG功能是什么意思?
查看>>
手机中电容屏和电阻屏有什么区别?
查看>>
Linux终端设备驱动 ----UART的驱动
查看>>
uCGUI使用
查看>>
Linux下SPI驱动的移植和应用程序的测试
查看>>
mini210使用tftp功能
查看>>
mini210的uboot编译使用
查看>>
Sizeof与Strlen的区别与联系
查看>>
Linux Kernel and Android 休眠与唤醒(request_suspend_state)
查看>>
mini210的串口驱动的应用程序
查看>>
Linux tar打包命令
查看>>
编译友善之背的mini210的android文件系统
查看>>
ucosII的CPU使用率查看即OSStatInit()函数的使用方法
查看>>
STM32上使用UCOSII--软件定时器和任务延时
查看>>
IAR上部分UCOS软定时器无法启动的问题
查看>>
ucosII的事件标志组的使用心得
查看>>
MINI210开发板的ADC驱动
查看>>
详解μC/OS-II如何检测任务堆栈实际使用情况——即如何设置ucosii任务堆栈大小
查看>>
MSP430 ADC12采样分析
查看>>
HDU 2522 求循环小数问题
查看>>