CF1179C.Serge and Dining Room

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Serge came to the school dining room and discovered that there is a big queue here. There are mm pupils in the queue. He's not sure now if he wants to wait until the queue will clear, so he wants to know which dish he will receive if he does. As Serge is very tired, he asks you to compute it instead of him.

Initially there are nn dishes with costs a1,a2,,ana_1, a_2, \ldots, a_n . As you already know, there are the queue of mm pupils who have b1,,bmb_1, \ldots, b_m togrogs respectively (pupils are enumerated by queue order, i.e the first pupil in the queue has b1b_1 togrogs and the last one has bmb_m togrogs)

Pupils think that the most expensive dish is the most delicious one, so every pupil just buys the most expensive dish for which he has money (every dish has a single copy, so when a pupil has bought it nobody can buy it later), and if a pupil doesn't have money for any dish, he just leaves the queue (so brutal capitalism...)

But money isn't a problem at all for Serge, so Serge is buying the most expensive dish if there is at least one remaining.

Moreover, Serge's school has a very unstable economic situation and the costs of some dishes or number of togrogs of some pupils can change. More formally, you must process qq queries:

  • change aia_i to xx . It means that the price of the ii -th dish becomes xx togrogs.
  • change bib_i to xx . It means that the ii -th pupil in the queue has xx togrogs now.

Nobody leaves the queue during those queries because a saleswoman is late.

After every query, you must tell Serge price of the dish which he will buy if he has waited until the queue is clear, or 1-1 if there are no dishes at this point, according to rules described above.

输入格式

The first line contains integers nn and mm ( 1n,m300 0001 \leq n, m \leq 300\ 000 ) — number of dishes and pupils respectively. The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai1061 \leq a_i \leq 10^{6} ) — elements of array aa . The third line contains mm integers b1,b2,,bmb_1, b_2, \ldots, b_{m} ( 1bi1061 \leq b_i \leq 10^{6} ) — elements of array bb . The fourth line conatins integer qq ( 1q300 0001 \leq q \leq 300\ 000 ) — number of queries.

Each of the following qq lines contains as follows:

  • if a query changes price of some dish, it contains 11 , and two integers ii and xx ( 1in1 \leq i \leq n , 1x1061 \leq x \leq 10^{6} ), what means aia_i becomes xx .
  • if a query changes number of togrogs of some pupil, it contains 22 , and two integers ii and xx ( 1im1 \leq i \leq m , 1x1061 \leq x \leq 10^{6} ), what means bib_i becomes xx .

输出格式

For each of qq queries prints the answer as the statement describes, the answer of the ii -th query in the ii -th line (the price of the dish which Serge will buy or 1-1 if nothing remains)

输入输出样例

  • 输入#1

    1 1
    1
    1
    1
    1 1 100
    

    输出#1

    100
    
  • 输入#2

    1 1
    1
    1
    1
    2 1 100
    

    输出#2

    -1
    
  • 输入#3

    4 6
    1 8 2 4
    3 3 6 1 5 2
    3
    1 1 1
    2 5 10
    1 1 6
    

    输出#3

    8
    -1
    4
    

说明/提示

In the first sample after the first query, there is one dish with price 100100 togrogs and one pupil with one togrog, so Serge will buy the dish with price 100100 togrogs.

In the second sample after the first query, there is one dish with price one togrog and one pupil with 100100 togrogs, so Serge will get nothing.

In the third sample after the first query, nobody can buy the dish with price 88 , so Serge will take it. After the second query, all dishes will be bought, after the third one the third and fifth pupils will by the first and the second dishes respectively and nobody will by the fourth one.

首页