## WOSS Dual Olympiad 2023 J3/S1: Moving Sand

View as PDF

Points: 7
Time limit: 10.0s
Memory limit: 1G

Authors:
Problem type

There are piles of sand in a line. The th pile from the left initially has units of sand. Answer queries, the th query contains integers , , and :

If is 1: move units of sand from the th pile to the ()th pile. ().

If is 2: move units of sand from the th pile to the ()th pile. ().

If is 3: find the total units of sand in all of the piles between pile and , inclusive. ().

The queries will never make you remove more sand from a pile than it contains, or move a negative amount of sand.

#### Constraints

All queries will have = .

#### Input Specification

The first line contains space-separated integers, and .

The second line contains space-separated integers, the th integer representing the units of sand in the th pile.

The next lines each contain space-separated integers: , , and .

#### Output Specification

For each query with , output a line containing a single integer: the total units of sand in all of the piles between pile and , inclusive.

5 6
4 2 10 3 4
3 2 4
1 2 2
2 3 8
3 1 3
2 1 4
3 2 5

15
8
21

#### Explanation for Sample

The piles are initially .

After the nd query they are .

After the rd query they are .

After the th query they are .