A12764 | Serge and Dining Room
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Serge came to the school dining room and discovered that there is a big queue here. There are $m$ 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 $n$ dishes with costs $a_1, a_2, \ldots, a_n$ . As you already know, there are the queue of $m$ pupils who have $b_1, \ldots, b_m$ togrogs respectively (pupils are enumerated by queue order, i.e the first pupil in the queue has $b_1$ togrogs and the last one has $b_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 $q$ queries:
- change $a_i$ to $x$ . It means that the price of the $i$ -th dish becomes $x$ togrogs.
- change $b_i$ to $x$ . It means that the $i$ -th pupil in the queue has $x$ 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$ if there are no dishes at this point, according to rules described above.
Initially there are $n$ dishes with costs $a_1, a_2, \ldots, a_n$ . As you already know, there are the queue of $m$ pupils who have $b_1, \ldots, b_m$ togrogs respectively (pupils are enumerated by queue order, i.e the first pupil in the queue has $b_1$ togrogs and the last one has $b_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 $q$ queries:
- change $a_i$ to $x$ . It means that the price of the $i$ -th dish becomes $x$ togrogs.
- change $b_i$ to $x$ . It means that the $i$ -th pupil in the queue has $x$ 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$ if there are no dishes at this point, according to rules described above.
输入格式
The first line contains integers $n$ and $m$ ( $1 \leq n, m \leq 300\ 000$ ) — number of dishes and pupils respectively. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^{6}$ ) — elements of array $a$ . The third line contains $m$ integers $b_1, b_2, \ldots, b_{m}$ ( $1 \leq b_i \leq 10^{6}$ ) — elements of array $b$ . The fourth line conatins integer $q$ ( $1 \leq q \leq 300\ 000$ ) — number of queries.
Each of the following $q$ lines contains as follows:
- if a query changes price of some dish, it contains $1$ , and two integers $i$ and $x$ ( $1 \leq i \leq n$ , $1 \leq x \leq 10^{6}$ ), what means $a_i$ becomes $x$ .
- if a query changes number of togrogs of some pupil, it contains $2$ , and two integers $i$ and $x$ ( $1 \leq i \leq m$ , $1 \leq x \leq 10^{6}$ ), what means $b_i$ becomes $x$ .
Each of the following $q$ lines contains as follows:
- if a query changes price of some dish, it contains $1$ , and two integers $i$ and $x$ ( $1 \leq i \leq n$ , $1 \leq x \leq 10^{6}$ ), what means $a_i$ becomes $x$ .
- if a query changes number of togrogs of some pupil, it contains $2$ , and two integers $i$ and $x$ ( $1 \leq i \leq m$ , $1 \leq x \leq 10^{6}$ ), what means $b_i$ becomes $x$ .
输出格式
For each of $q$ queries prints the answer as the statement describes, the answer of the $i$ -th query in the $i$ -th line (the price of the dish which Serge will buy or $-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 $100$ togrogs and one pupil with one togrog, so Serge will buy the dish with price $100$ togrogs.
In the second sample after the first query, there is one dish with price one togrog and one pupil with $100$ togrogs, so Serge will get nothing.
In the third sample after the first query, nobody can buy the dish with price $8$ , 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.
In the second sample after the first query, there is one dish with price one togrog and one pupil with $100$ togrogs, so Serge will get nothing.
In the third sample after the first query, nobody can buy the dish with price $8$ , 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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted