QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#3682. 长跑

统计

问题描述

某校开展了同学们喜闻乐见的阳光长跑活动。为了能“为祖国健康工作五十年”,同学们纷纷离开寝室,离开教室,离开实验室,到操场参加3000米长跑运动。一时间操场上熙熙攘攘,摩肩接踵,盛况空前。

为了让同学们更好地监督自己,学校推行了刷卡机制。

学校中有 $n$ 个地点,用 $1$ 到 $n$ 的整数表示,每个地点设有若干个刷卡机。有以下三类事件:

  1. 修建了一条连接 $A$ 地点和 $B$ 地点的跑道。
  2. $A$ 点的刷卡机台数变为了 $B$。
  3. 进行了一次长跑。问一个同学从 $A$ 出发,最后到达 $B$ 最多可以刷卡多少次。具体的要求如下:
    • 当同学到达一个地点时,他可以在这里的每一台刷卡机上都刷卡。但每台刷卡机只能刷卡一次,即使多次到达同一地点也不能多次刷卡。
    • 为了安全起见,每条跑道都需要设定一个方向,这条跑道只能按照这个方向单向通行。最多的刷卡次数即为在任意设定跑道方向,按照任意路径从A地点到B地点能刷卡的最多次数。

输入格式

输入的第一行包含两个正整数 $n,m$,表示地点的个数和操作的个数。

第二行包含 $n$ 个非负整数,其中第 $i$ 个数为第 $i$ 个地点最开始刷卡机的台数。

接下来有 $m$ 行,每行包含三个非负整数 $P,A,B$,$P$ 为事件类型,$A,B$为事件的两个参数。

  • 最初所有地点之间都没有跑道。
  • 每行相邻的两个数之间均用一个空格隔开。
  • 表示地点编号的数均在 $1$ 到 $n$ 之间,每个地点的刷卡机台数始终不超过 $10\,000$,$P \in \{1,2,3\}$。

输出格式

输出的行数等于第 $3$ 类事件的个数,每行表示一个第 $3$ 类事件。如果该情况下存在一种设定跑道方向的方案和路径的方案,可以到达,则输出最多可以刷卡的次数。如果 $A$ 不能到达 $B$,则输出 -1

样例输入

9 31
10 20 30 40 50 60 70 80 90
3 1 2
1 1 3
1 1 2
1 8 9
1 2 4
1 2 5
1 4 6
1 4 7
3 1 8
3 8 8
1 8 9
3 8 8
3 7 5
3 7 3
1 4 1
3 7 5
3 7 3
1 5 7
3 6 5
3 3 6
1 2 4
1 5 5
3 3 6
2 8 180
3 8 8
2 9 190
3 9 9
2 5 150
3 3 6
2 1 210
3 3 6

样例输出

-1
-1
80
170
180
170
190
170
250
280
280
270
370
380
580

数据规模及约定

对于 $100\%$ 的数据,$m \leq 5n$,任意时刻,每个地点的刷卡机台数不超过 $10\,000$。具体每组数据的规模如下

编号
$n$
编号
$n$
$1$
$10$
$6$
$5 \times 10^4$
$2$
$10^2$
$7$
$10^5$
$3$
$10^3$
$8$
$10^5$
$4$
$10^4$
$9$
$1.5 \times 10^5$
$5$
$2 \times 10^4$
$10$
$1.5 \times 10^5$
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.