Handle updates that add an arithmetic sequence of troops along a line of cities in one direction, and answer queries for a city's running total.
Medium6Prefix sumImplementationMathArrayNo attempts yetTime limit2sMemory limit512 MBYou are a denizen of Linetopia, whose n major cities are equally spaced along an east-west line. They are numbered in order from 1 to n, where 1 is the westmost city and n is the eastmost city. Linetopia was a lovely place to live until forces from neighboring Trapez invaded. As part of Linetopia's citizen protection initiative, you have been asked to process information about Trapezoid troop movements, so that the government can determine which cities have been hit hardest and where to send reinforcements.
Linetopia intelligence has discovered that the Trapezoid forces attack in the following pattern. They send massive aircraft to drop troops on Linetopia's cities. Each aircraft starts at some city i and drops s soldiers there. The aircraft then flies either east or west. Each time it flies over another city, it drops a more soldiers than it dropped on the previous city it passed. After performing d drops, the aircraft returns to Trapez to resupply.
You receive intel updates that give the specs of each Trapezoid aircraft passing over Linetopia. You must also answer queries that ask how many Trapezoid troops have been dropped on a particular city so far.
The first line contains a single integer T (1≤T≤10), the number of test cases. The first line of each test case contains two integers: m (1≤m≤10000), the total number of updates and queries, and n (1≤n≤500000), the number of cities in Linetopia.
Each of the next m lines is either an update or a query. An update line begins with a capital U, followed by a capital E (east) or W (west) that gives the direction, followed by four integers i (1≤i≤n), s (1≤s≤10000), a (0≤a≤10000), and d (1≤d≤n). These are the starting city, the number of soldiers in the first drop, the increase in soldiers per city, and the number of drops, respectively. An aircraft never flies west of city 1 or east of city n during its d drops.
A query line begins with a capital Q, followed by a single integer i (1≤i≤n), the city being queried.
For each query, in input order, print one line with the number of Trapezoid troops dropped on that city up to that point.
In the sample, two aircraft fly over Linetopia. The first starts at city 1 and heads east. It drops 5 soldiers on city 1, 7 soldiers on city 2, and 9 soldiers on city 3. The second starts at city 3 and flies west. It drops 10 soldiers on city 3 and 20 soldiers on city 2.