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

8 篇文章 0 订阅

D. Welfare State

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

There is a country with nn citizens. The ii-th of them initially has aiai 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 xx are paid accordingly so that after the payout they have exactly xx 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 nn (1≤n≤2⋅1051≤n≤2⋅105) — the numer of citizens.

The next line contains nn integers a1a1, a2a2, ..., anan (0≤ai≤1090≤ai≤109) — the initial balances of citizens.

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

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

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

Output

Print nn 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

题意:给你 n 个数的数组,接下来有q次操作,若为 1 表示将某个数改为某个值即若输入 1 p x 则原数组a[p] = x;若为操作 2则将所有小于输入值的值改为输入值,即 2 x 则原数组  a[i] = x (a'[i] < x)

思路:第一种情况,如果值中途没有改变,那么它只会和2操作的最大值进行比较并且做出相应改或不改的操作,第二种情况如果值发生了改变,那么改变的值如果想和操作2的某个值做出相应选择的话,只可能是与这次操作之后的某次操作做比较了。利用一点点floodfill思想填充每位置的修改值,将某次操作之后大于它的数当作这个值,因为这次操作之后必定会进行覆盖,然后对于修改的值,记录他的在操作序列中的下标,便于后续判断,没有修改的值就赋为0(floodfill后修改序列的第一个必定是最大值)

#include<vector>
 #include<iostream>
  #include<cstdio>
   #include<cstring>
    #include<string>
     #include<map>
      #include<algorithm>
       #include<cmath>
using namespace std;
  typedef long long ll;
    typedef vector<int> vec;
      typedef pair<int,int> pr;
        typedef vector<pr> vecpr;
        void init_cin()
        {
          std::ios::sync_with_stdio(false);
           std::cin.tie(0);
            std::cout.tie(0);
        }
    const ll MAXN = (ll(1e5) << 1) + 5;
    ll d[MAXN] , dex[MAXN] , mdf[MAXN];
    int main()
    {
       int n,q;
         init_cin();
           cin >> n;
          for(int i = 1 ; i <= n ; ++ i)
              cin >> d[i];
               cin >> q;
            for(int i = 1 ; i <= q ; ++ i)
            {
                int op;
                  cin >> op;
                    if(op == 1)
                    {
                        int temp;
                         int x;
                          cin >> temp;
                           cin >> d[temp];
                            dex[temp] = i;
                    }else
                    {
                        cin >> mdf[i];
                    }
            }
         for(int i = q ; i >= 1 ; i--) mdf[i] = max(mdf[i],mdf[i+1]);
         for(int i = 1 ; i <= n ; ++ i) if(d[i] < mdf[dex[i]+1]) d[i] = mdf[dex[i]+1];
         for(int i = 1 ; i <= n ; ++ i) cout << d[i] << ' ';
         cout << endl;

    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值