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≤≤2⋅1051≤n≤2⋅105) — the numer of citizens.

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

The next line contains a single integer q (1≤≤2⋅1051≤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≤≤1≤p≤n, 0≤≤1090≤x≤109), or 2 x (0≤≤1090≤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

Copy

4
1 2 3 4
3
2 3
1 2 2
2 1

output

Copy

3 2 3 4

input

Copy

5
3 50 2 1 10
3
1 2 0
2 8
1 3 20

output

Copy

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

哭了哭了~~

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200010;
int a[maxn],last[maxn],b[maxn];//a为原数组,last[i]记录修改i节点的最后一个位置,b[i]代表从i时间点往后最大的补充x值
int main()
{
int n,q;
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
cin>>q;
for(int i=1;i<=q;i++){
int op,x,y;
cin>>op;
if(op==1){
cin>>x>>y;
a[x]=y;//修改原数组值
last[x]=i;//记录修改x下标的最后一个位置i
}
else{
cin>>b[i];//输入i时间点的补充值b[i]
}
}
for(int i=q-1;i>=0;i--)b[i]=max(b[i],b[i+1]);
for(int i=1;i<=n;i++)cout<<max(a[i],b[last[i]])<<" ";
cout<<endl;
return 0;
}

D. Welfare State的更多相关文章

  1. [Codeforces 1199D]Welfare State(线段树)

    [Codeforces 1199D]Welfare State(线段树) 题面 给出一个长度为n的序列,有q次操作,操作有2种 1.单点修改,把\(a_x\)修改成y 2.区间修改,把序列中值< ...

  2. Codeforces - 1199D - Welfare State - 单调栈 / 线段树

    https://codeforc.es/contest/1199/problem/D 其实后来想了一下貌似是个线段树的傻逼题. 单调栈是这样思考的,每次单点修改打上一个最终修改的时间戳.每次全体修改就 ...

  3. codeforces 1198B - Welfare State

    题目链接:http://codeforces.com/problemset/status 题目大意为有n个市民,每个市民有ai点数财富,以下有q次操作,操作类型为两类,1类:把第p个市民的财富改为x, ...

  4. Codeforces Round #576 (Div. 2) D. Welfare State

    http://codeforces.com/contest/1199/problem/D Examples input1 output1 input2 output2 Note In the firs ...

  5. B. Welfare State(RMQ问题的逆向考虑)

    \(对于操作1,我们只关心最后一次操作.\) \(对于操作2,我们只关心值最大的一次操作.\) \(也就是说,我们记录每个居民最后一次被修改的位置\) \(然后它的最终答案就是从这个位置起,max(操 ...

  6. 【CodeForces】CodeForcesRound576 Div1 解题报告

    点此进入比赛 \(A\):MP3(点此看题面) 大致题意: 让你选择一个值域区间\([L,R]\),使得序列中满足\(L\le a_i\le R\)的数的种类数不超过\(2^{\lfloor\frac ...

  7. Codeforces Round #576 (Div. 1)

    Preface 闲来无事打打CF,就近找了场Div1打打 这场感觉偏简单,比赛时艹穿的人都不少,也没有3000+的题 两三个小时就搞完了吧(F用随机水过去了) A. MP3 题意不好理解,没用翻译看了 ...

  8. Browse Princeton's Series (by Date) in Princeton Economic History of the Western World

    Browse Princeton's Series (by Date) in Princeton Economic History of the Western World Joel Mokyr, S ...

  9. Codeforces Round #576 (Div. 2) 题解

    比赛链接:https://codeforc.es/contest/1199 A. City Day 题意:给出一个数列,和俩个整数\(x,y\),要求找到序号最靠前的数字\(d\),使得\(d\)满足 ...

随机推荐

  1. python中的with用法

    with是从Python2.5引入的一个新的语法,它是一种上下文管理协议,目的在于从流程图中把 try,except 和finally 关键字和 资源分配释放相关代码统统去掉,简化try….excep ...

  2. golang实现单链表

    package main import "fmt" type Object interface{} type Node struct { data Object next *Nod ...

  3. jq切换选择项

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. SQL基础教程(第2版)第3章 聚合与排序:3-2 对表进行分组

    第3章 聚合与排序:3-2 对表进行分组 ● 使用GROUP BY子句可以像切蛋糕那样将表分割.通过使用聚合函数和GROUP BY子句,可以根据“商品种类”或者“登记日期”等将表分割后再进行汇总.● ...

  5. MySQL各种存储引擎对比总结

    1.MyISAM 是MySQL5.5版之前默认的存储引擎,特点:数据文件和索引文件可以放置在不同的目录,平局分布IO,获得更快的速度.不支持事务,不支持外键. 2.InnoDB 是 MySQL5.5版 ...

  6. 黑客攻防技术宝典web实战篇:测试后端组件习题答案

    随书答案. 某网络设备提供用于执行设备配置的 Web 界面.为什么这种功能通常易于受 到操作系统命令注入攻击? 用于配置网络设备的应用程序通常包含使用正常的 Web 脚本 API 无法轻松实 现的功能 ...

  7. vue项目 首页开发 part3

    da当拖动图标时候,只有上部分可以,下部分无响应 swiper 为根页面引用,其中的css为独立,点击swiper标签可以看见其包裹区域只有部分 那么需要修改 就需要穿透样式 外部  >> ...

  8. JavaScript—面向对象 贪吃蛇_3 蛇对象

    蛇对象 function Snake(element) { this.width = 20 this.height = 20 //蛇身 位置 颜色 this.body = [ {x: 6, y: 4, ...

  9. Django模板渲染——(二)

    模板标签 模板是由HTML代码和一些逻辑控制代码组成的,逻辑控制代码除了前面介绍的变量和过滤器,还要一个非常重要的模板标签.模板标签的语法规则是{% tag %},模板标签在渲染的过程中能提供任意的逻 ...

  10. linux-线程同步之信号量

    1.任务:用户从终端输入任意字符然后统计字符个数显示,输入end则结束 2.使用多线程实现:主线程获取用户输入并判断是否退出,子线程计数 #include <stdio.h> #inclu ...