Under construction

Still being built. Things may change

RMT Subway Load Test

Time limit5sMemory limit512 MB

Summary
Each subway line is a cycle of stations; line operations rotate passenger counts around the cycle, and range-sum surveys must be answered online.
Level

Hard8 of 10

Topics
Segment tree, Prefix sum, Implementation, Math
Solved
No attempts yet

Problem

Rail Metro Transit (RMT) runs an unusual subway system. There are NN subway stations numbered from 11 to NN, and MM subway lines numbered from 11 to MM. Every station belongs to exactly one line, and every line has at least one station.

Each line is circular. For a station SS, the next station after SS is the station of the same line whose number is the smallest among those larger than SS. If SS already has the largest number among the stations of its line, the next station after SS is the station of that line with the smallest number.

RMT is running a load test with volunteer passengers. When the test starts, one train stands at every station, and the train at station ii carries AiA_i passengers. The volunteers stay on their own train until the test ends.

During the test, RMT performs QQ actions in order. Each action is one of two kinds:

  • a survey of the total number of passengers on the trains standing at stations ll through rr,
  • an operation of line xx, which sends every train of line xx to the next station of that line.

Report the answer of every survey.

Input

The first line contains three space separated integers NN, MM and QQ (1≤M≤N≤1500001 \le M \le N \le 150000, 1≤Q≤1500001 \le Q \le 150000).

The second line contains NN integers L1,L2,…,LNL_1, L_2, \dots, L_N (1≤Li≤M1 \le L_i \le M), where LiL_i is the line that station ii belongs to. Every line has at least one station.

The third line contains NN integers A1,A2,…,ANA_1, A_2, \dots, A_N (1≤Ai≤70001 \le A_i \le 7000), the number of passengers at each station when the test starts.

Each of the next QQ lines holds one action in one of these two forms:

  • 1 l r, a survey of stations ll through rr (1≤l≤r≤N1 \le l \le r \le N).
  • 2 x, an operation of line xx (1≤x≤M1 \le x \le M).

Output

For every survey, print its answer on its own line.

Hint

The first example is drawn below. The stations are numbered from 11 to 55, and every connection carries the number of the line it belongs to.

Subway map of the first example

At the start the passenger counts are {1, 2, 3, 4, 5}. The first survey answers 1+2+3+4+5=151 + 2 + 3 + 4 + 5 = 15.

Operating line 1 changes the counts to {3, 2, 1, 4, 5}, so the second survey answers 1+4+5=101 + 4 + 5 = 10.

Operating line 2 changes the counts to {3, 5, 1, 2, 4}, so the third survey answers 3+5+1=93 + 5 + 1 = 9.

The second example is drawn below. The stations are numbered from 11 to 33, and every connection belongs to line 1.

Subway map of the second example

Just before the first survey the counts are {114, 101, 109}. Just before the second survey they are {109, 114, 101}, just before the third survey {101, 109, 114}, and just before the fourth survey {114, 101, 109}.

Examples2

  1. Example 1

    Input
    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
    
    Expected output
    15
    10
    9
    
  2. Example 2

    Input
    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
    
    Expected output
    114
    109
    101
    114