luogu#P4807. [CCC 2017] 地铁交通
[CCC 2017] 地铁交通
Background
Abusing the judging system for this problem will result in your account being banned.
Problem Description
Translated from CCC2017 Senior T5 “RMT”.
RMT Subway Transit operates an unusual subway system. There are stations, numbered from to . There are subway lines, numbered from to . Each station belongs to exactly one line, and each line contains at least one station. The entire subway network is circular. That is, if there is a station numbered , then the next station on the same line is the station on that line with the smallest number that is greater than . Unless is the station with the largest number on that line, in which case its next station is the station with the smallest number on that line.
RMT is using volunteers to load-test their system. The test starts with one subway train at each station, and for each , there are volunteers on the test train at station . Throughout the test, volunteers will not leave their corresponding trains.
During the test, RMT will perform operations. Each operation is one of two types: either query the number of volunteers on the trains from station to station , or run all trains on line . When a train runs on line , it moves to the next station on that line.
You are a die-hard fan of RMT, so you volunteer to help them perform the operations and report the results.
Input Format
The first line contains three integers and .
The second line contains integers , indicating the line number that each station belongs to.
The third line contains integers , indicating the initial number of volunteers at each station.
The next lines are each in one of the following forms:
-
1 l r, indicating a query . -
2 x, indicating that RMT runs line .
Output Format
For each query, output one line containing the answer.
5 2 5
1 2 1 2 2
1 2 3 4 5
1 1 5
2 1
1 3 5
2 2
1 1 3
15
10
9
3 1 7
1 1 1
114 101 109
1 1 1
2 1
1 1 1
2 1
1 1 1
2 1
1 1 1
114
109
101
114
Hint
Sample Explanation 1
The subway system is shown in the figure below. Stations are numbered from to , and are connected by line or :

At the start, the number of volunteers at each station is .
The answer to the first query is .
After line is run, the number of volunteers at each station becomes .
The answer to the second query is .
After line is run, the number of volunteers at each station becomes .
The answer to the third query is .
Sample Explanation 2
The subway system is shown in the figure below. Stations are numbered from to , and only line connects them:

Before the first query, the number of volunteers at each station is .
Before the second query, the number of volunteers at each station is .
Before the third query, the number of volunteers at each station is .
Before the fourth query, the number of volunteers at each station is .
For of the testdata, .
For another of the testdata, .
For another of the testdata, .
For another of the testdata, each line has at most trains.
Translated by ChatGPT 5