AT_abc467_f.Email Scheduling Optimization

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

You are given length-NN sequences of positive integers A=(A1,A2,…,AN)A=(A_1,A_2,\dots,A_N) and B=(B1,B2,…,BN)B=(B_1,B_2,\dots,B_N).
You are given QQ queries.
Each query is of one of the following two types.

  • 1 i x : Change AiA_i to xx.
  • 2 i x : Change BiB_i to xx.

After processing each query, solve the following problem.

Takahashi needs to send an email to each of NN companies and receive a reply from each of them.
Writing the email to send to the jj-th company takes AjA_j minutes, and the reply arrives BjB_j minutes after it is sent.
He starts writing emails at time 00.
He can write the NN emails in any order he likes, but he cannot write two or more emails simultaneously.
Find the minimum possible time at which he finishes receiving all of the replies.
Assume that the time taken to send emails is negligible.

给你两个长度为 NN 的正整数序列 A=(A1,A2,…,AN)A=(A_1,A_2,\dots,A_N) 和 B=(B1,B2,…,BN)B=(B_1,B_2,\dots,B_N)。
你将收到 QQ 个查询。
每个查询属于以下两种类型之一:

  • 1 i x:将 AiA_i 修改为 xx。
  • 2 i x:将 BiB_i 修改为 xx。

在处理完每个查询后,请解决如下问题:

高桥需要向 NN 家公司分别发送一封电子邮件,并从每家公司各收到一封回信。
向第 jj 家公司发送邮件需耗时 AjA_j 分钟,且该邮件发出后 BjB_j 分钟会收到回信。
他从时刻 00 开始撰写邮件。
他可以按任意顺序撰写这 NN 封邮件,但不能同时撰写多封邮件。
求他收齐所有回信的最早可能时刻。
假设发送邮件本身所需时间可忽略不计。

输入格式

The input is given from Standard Input in the following format:

NN QQ
A1A_1 A2A_2 …\ldots ANA_N
B1B_1 B2B_2 …\ldots BNB_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

For each query queryq\mathrm{query}_q, the type of the query (11 or 22), ii, and xx are given in this order, separated by spaces.
That is, each query is given in one of the following two formats:

11 ii xx

22 ii xx

输入从标准输入给出,格式如下:

NN QQ
A1A_1 A2A_2 …\ldots ANA_N
B1B_1 B2B_2 …\ldots BNB_N
query1\mathrm{query}_1
query2\mathrm{query}_2
⋮\vdots
queryQ\mathrm{query}_Q

对于每个查询 queryq\mathrm{query}_q,按顺序给出查询类型(11 或 22)、ii 和 xx,以空格分隔。
即,每个查询以以下两种格式之一给出:

11 ii xx

22 ii xx

输出格式

Output the answers in a total of QQ lines. The qq-th line should contain the answer to the problem after processing the qq-th query.

在总共 QQ 行中输出答案。第 qq 行应包含处理完第 qq 个查询后的答案。

输入输出样例

  • 输入#1

    3 3
    4 6 7
    4 6 7
    1 2 1
    2 3 7
    2 3 1

    输出#1

    16
    16
    13

说明/提示

Sample 1 Explanation:
After processing the first query, A=(4,1,7)A=(4,1,7) and B=(4,6,7)B=(4,6,7).
If Takahashi starts writing the email to send to company 33 at time 00, finishes writing it at time 77, and sends it to company 33, he receives the reply at time 1414.
If he starts writing the email to send to company 22 at time 77, finishes writing it at time 88, and sends it to company 22, he receives the reply at time 1414.
If he starts writing the email to send to company 11 at time 88, finishes writing it at time 1212, and sends it to company 11, he receives the reply at time 1616.

Constraints

  • 1≤N≤1051 \leq N \leq 10^5
  • 1≤Q≤1051 \leq Q \leq 10^5
  • 1≤Aj,Bj≤1091 \leq A_j,B_j \leq 10^9
  • In each query, 1≤i≤N1 \leq i \leq N.
  • In each query, 1≤x≤1091 \leq x \leq 10^9.
  • All input values are integers.

样例 1 解释:
处理第一个查询后,A=(4,1,7)A=(4,1,7),B=(4,6,7)B=(4,6,7)。
若高桥在时刻 00 开始撰写发给公司 33 的邮件,于时刻 77 完成撰写并发出,则他在时刻 1414 收到回复。
若他在时刻 77 开始撰写发给公司 22 的邮件,于时刻 88 完成撰写并发出,则他在时刻 1414 收到回复。
若他在时刻 88 开始撰写发给公司 11 的邮件,于时刻 1212 完成撰写并发出,则他在时刻 1616 收到回复。

限制条件

  • 1≤N≤1051 \leq N \leq 10^5
  • 1≤Q≤1051 \leq Q \leq 10^5
  • 1≤Aj,Bj≤1091 \leq A_j,B_j \leq 10^9
  • 每个查询中,1≤i≤N1 \leq i \leq N。
  • 每个查询中,1≤x≤1091 \leq x \leq 10^9。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页