CCC '17 S5 - RMT

View as PDF

Submit solution


Points: 20 (partial)
Time limit: 7.0s
Memory limit: 1G

Author:
Problem type
Canadian Computing Competition: 2017 Stage 1, Senior #5

The Rail Metro Transit (RMT) operates a very unusual subway system. There are N subway stations numbered from 1 to N. There are M subway lines numbered from 1 to M, 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 S, the next station after S is the station on the same line with the next largest number, unless S is the greatest number of a station in the line, in which case the next station after S 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 i, there are A_i passengers in the train at station i. The volunteers do not leave their assigned trains throughout the entire duration of the load test.

Throughout the test, RMT will perform Q actions. Each of the Q 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 r; or they will operate all the trains on some line x. When a train on line x 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 N, M, and Q (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 1 to N belongs to: L_1, L_2, \ldots, L_N. The third line will contain N integers A_1, A_2, \ldots, A_N (1 \le A_i \le 7\,000) representing the initial number of passengers at each station from 1 to N.

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

  • 1\ \ell\ r, which represents a survey (1 \le \ell \le r \le N).
  • 2\ x, which represents RMT operating line x (1 \le x \le M).

For 2 of the 15 available marks, N \le 1\,000 and Q \le 1\,000.
For an additional 2 of the 15 available marks, L_i \le L_{i+1} (1 \le i < N).
For an additional 3 of the 15 available marks, M \le 200.
For an additional 3 of the 15 available marks, there will be no more than 200 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

Sample Output 1

15
10
9

Explanation for Sample Output 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:

Initially, the number of passengers at each station is \{1, 2, 3, 4, 5\}.
The answer to the first survey is 1+2+3+4+5=15.
After line 1 is operated, the number of passengers at each station is \{3, 2, 1, 4, 5\}.
The answer to the second survey is 1+4+5=10.
After line 2 is operated, the number of passengers at each station is \{3, 5, 1, 2, 4\}.
The answer to the third survey is 3+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

Sample Output 2

114
109
101
114

Explanation for Sample Output 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:

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


Comments


  • 0
    cmcawesome  commented on Jan. 11, 2018, 1:12 p.m.

    -Spoilers-

    I have O(n) query and O(1) update, and I'm hitting TLE. Batch 2's constraints give an obvious solution to that set by saving line totals by ranges, but I don't see how that would apply to the later Batches when stations aren't continuous.

    Would any/all of the submitted answers finish in time for N=M=Q=150000 of only 1 1 150000? Am I missing a breakthrough or am I just not storing enough info to later reuse?

    I can think of small casing things that could improve times in special cases (keep a line's passengers + min and max station #, if min + max are in range just add the line's passengers; but flagging that you added each station would take as long as the lookup anyways, so you would need to do this for every line or no lines; but then you have lines that aren't fully contained in a range where you have to subtract... etc. etc.)

    I can't find the solutions anywhere else and this is bugging me, so any help is much appreciated.


  • 0
    Ninjaclasher  commented on Sept. 21, 2017, 8:44 a.m. edit 3

    nvm


    • 3
      wleung_bvg  commented on Sept. 21, 2017, 9:34 a.m. edit 2

      Well since N \leq 150000 and Q \leq 150000, Q updates taking N time would result in at least 2e10 operations per second in the worst case, and would almost certainly TLE.


  • 6
    CarlYu  commented on March 6, 2017, 7:26 p.m.

    Wait... there are at least 400 test cases... If all of them hits 7.0s exactly, that's like 47 minutes....


    • 16
      Xyene  commented on March 6, 2017, 7:40 p.m.

      And that there is why we have 4 judges.


      • -6
        sunnylancoder  commented on March 14, 2017, 9:35 p.m.

        Isn't that still still like 12 minutes per judge??


        • 4
          Kirito  commented on March 14, 2017, 10:09 p.m.

          Submissions only run on one judge at a time.