QOJ.ac

QOJ

时间限制: 1.5 s 内存限制: 512 MB 总分: 100

#17611. 影响

统计

在一个遥远的国家有 $n$ 个城市,编号为 $1$ 到 $n$。在 $m$ 对不同的城市之间建立了航线——双向的每日航班。某些城市是“枢纽城市”,航空公司对它们给予更多的关注和资源。最后,每个城市都有一定数量的潜在乘客,随着时间的推移,这个数量可能会发生变化。

图 1:第一个样例测试数据的插图:城市 3 的当前影响力为 22,城市 6 的当前影响力为 8。

对于一个特定的枢纽城市 $a$,其影响力定义为:当前位于城市 $a$ 的潜在乘客数量,加上能够通过一系列航班到达城市 $a$ 且中途不经过任何其他枢纽城市(且不从任何其他枢纽城市出发)的潜在乘客总数。给定航空网络,其中标记了哪些城市是枢纽城市,以及每个城市的初始潜在乘客数量。此外,还给出了 $q$ 个事件,每个事件是以下之一:

  • 1 a pa” —— 城市 $a$ 的潜在乘客数量发生改变,现在变为 $p_a$。
  • 2 a” —— 我们想知道枢纽城市 $a$ 的当前影响力。

请找出所有第二类事件的答案。

输入格式

第一行包含自然数 $n$ 和 $m$ —— 城市数量和航线数量。

第二行包含一个由 $n$ 个整数组成的序列 $k_1, k_2, \dots, k_n$ —— 如果城市 $j$ 是枢纽城市,则 $k_j = 1$,否则 $k_j = 0$。

第三行包含一个由 $n$ 个整数组成的序列 $p_1, p_2, \dots, p_n$ ($0 \le p_j \le 10^9$) —— $p_j$ 是城市 $j$ 的初始潜在乘客数量。

接下来的 $m$ 行中,第 $j$ 行包含两个不同的自然数 $a_j$ 和 $b_j$ ($1 \le a_j, b_j \le n$) —— 表示由航线直接连接的城市。城市和航线不一定构成连通图。

下一行包含一个自然数 $q$ —— 事件的数量。

接下来的 $q$ 行中,第 $j$ 行包含第 $j$ 个事件。每个事件要么是 “1 a pa” 的形式,其中 $a$ 是城市编号 ($1 \le a \le n$),$p_a$ 是新的潜在乘客数量 ($0 \le p_a \le 10^9$);要么是 “2 a” 的形式,其中 $a$ 是一个枢纽城市的编号。保证至少有一个事件是第 2 类。

输出格式

输出的行数与输入中第 2 类事件的数量相同。在第 $j$ 行中,输出输入中第 $j$ 个第 2 类事件所查询的枢纽城市的影响力。

数据范围

子任务 分值 数据范围
1 10 $1 \le n, m, q \le 1000$
2 20 $1 \le n, m, q \le 200\,000$ 且每个事件都是第 2 类
3 70 $1 \le n, m, q \le 200\,000$

样例

输入样例 1

6 7
0 0 1 0 0 1
4 3 0 9 6 2
1 2
2 3
4 3
4 1
5 3
5 6
3 6
2
2 3
2 6

输出样例 1

22
8

输入样例 2

6 6
1 0 1 1 0 0
1 2 4 3 5 6
1 2
1 3
3 2
6 5
4 5
1 6
8
2 3
1 2 7
2 3
2 1
1 6 0
1 4 9
2 1
2 4

输出样例 2

6
11
19
13
14

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.