CCCGuide

Problem S5: RMT

2017 · S5 · Original problem · DMOJ

Time limit: 5 seconds

Problem Description

The Rail Metro Transit (RMT) operates a very unusual subway system. There are NN subway stations numbered from 1 to NN. There are MM subway lines numbered from 1 to MM, with each station belonging to exactly one line and at least one station per line. The subway lines are circular. That is, if a station is numbered SS, the next station after SS is the station on the same line with the next largest number, unless SS is the greatest number of a station in the line, in which case the next station after SS is the station on the same line with the least number.

RMT is conducting a load test of their system using volunteer passengers to ride the subway trains. The test begins with one subway train in each station and for every ii, there are AiA_i passengers in the train at station ii. The volunteers do not leave their assigned trains throughout the entire duration of the load test.

Throughout the test, RMT will perform QQ actions. Each of the QQ actions is one of two types: either they will survey the total number of passengers in the trains at the stations numbered from ℓ\ell to rr; or they will operate all the trains on some line xx. When a train on line xx is operated, it goes to the next station in that line.

You are RMT’s biggest fan, so you have generously volunteered to keep track of RMT’s actions and report the answers to their surveys.

Input Specification

The first line will contain three space-separated integers NN, MM, and QQ (1≤M≤N≤150 000;1≤Q≤150 000)(1 \le M \le N \le 150\,000; 1 \le Q \le 150\,000). The second line will contain the subway line numbers that each station from 11 to NN belongs to: L1,L2,…,LNL_1, L_2, \ldots, L_N. The third line will contain NN integers A1,A2,…,ANA_1, A_2, \ldots, A_N (1≤Ai≤7 000)(1 \le A_i \le 7\,000) representing the initial number of passengers at each station from 11 to NN.

The next QQ lines will each have one of the following forms:

For 2 of the 15 available marks, N≤1 000N \le 1\,000 and Q≤1 000Q \le 1\,000. For an additional 2 of the 15 available marks, Li≤Li+1L_i \le L_{i+1} (1≤i<N)(1 \le i < N). For an additional 3 of the 15 available marks, M≤200M \le 200. For an additional 3 of the 15 available marks, there will be no more than 200200 trains on any single line.

Output Specification

For every survey, output the answer to the survey on a separate line.

Sample Input 1

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

Output for Sample Input 1

15
10
9

Explanation for Output for Sample Input 1

The subway system is illustrated below, with the stations numbered from 1 to 5 and the lines connecting stations marked as either being line 1 or line 2:

An arrow labelled 1 goes from Station 1 to Station 3 and also from Station 3 to Station 1. An arrow labelled 2 goes from Station 2 to Station 4, and also from Station 4 to Station 5, and from Station 5 to Station 2.

Initially, the number of passengers at each station is {1,2,3,4,5}\{1, 2, 3, 4, 5\}. The answer to the first survey is 1+2+3+4+5=151+2+3+4+5=15. After line 11 is operated, the number of passengers at each station is {3,2,1,4,5}\{3, 2, 1, 4, 5\}. The answer to the second survey is 1+4+5=101+4+5=10. After line 22 is operated, the number of passengers at each station is {3,5,1,2,4}\{3, 5, 1, 2, 4\}. The answer to the third survey is 3+5+1=93+5+1=9.

Sample Input 2

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

Output for Sample Input 2

114
109
101
114

Explanation for Output for Sample Input 2

The subway system is illustrated below, with the stations numbered from 1 to 3 and the lines connecting stations marked as all being line 1:

Arrows labelled 1 go from Station 1 to Station 2, from Station 2 to Station 3, and from Station 3 to Station 1.

Just before the first survey, the number of passengers at each station is {114,101,109}\{114, 101, 109\}. Just before the second survey, the number of passengers at each station is {109,114,101}\{109, 114, 101\}. Just before the third survey, the number of passengers at each station is {101,109,114}\{101, 109, 114\}. Just before the fourth survey, the number of passengers at each station is {114,101,109}\{114, 101, 109\}.