题目描述
You are a denizen of Linetopia, whose n major cities happen to be equally spaced along an east-west line. In fact, they are often 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 Shielding Lives and Protecting Citizens initiative, you have been called upon to process information about Trapezoid troop movements so we can determine which cities have been hardest hit and know where to send reinforcements.
Linetopia intelligence has discovered that the Trapezoid forces are attacking in the following pattern. They are sending massive aircraft to drop troops on Linetopia cities. Each aircraft starts at some city i, dropping s soldiers. The aircraft then proceeds to fly 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 will be receiving intel updates that inform you of the specs of each Trapezoid aircraft passing over Linetopia. You want to answer queries that ask how many Trapezoid troops have been dropped on a particular city. Are you up to the task?
输入
The first line of input 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 ≤ 10,000), the number of updates and queries and n (1 ≤ n ≤ 500,000), the number of cities in Linetopia.
The next m lines of input are either updates or queries. Update lines begin with a capital U, then contain either a capital E (east) or W (west) to indicate direction, and then contain four integers i (1 ≤ i ≤ n), s (1 ≤ s ≤ 10,000), a (0 ≤ a ≤ 10,000), and d (1 ≤ d ≤ n). These integers signify the starting city, the starting number of soldiers, the increase in soldiers per city, and the number of drops, respectively. You can assume d never results in an aircraft flying to the west of city 1 or to the east of city n.
Query lines begin with a capital Q, and then contain a single integer i (1 ≤ i ≤ n) indicating the city being queried.
输出
For each query in the input, output a single line containing the number of Trapezoid troops dropped in that city.
思路:当每次遇到询问时,遍历所有操作
# include <iostream>
# include <cstdio>
# include<algorithm>
# include <cstring>
# include <string>
# include<map>
#define ll long long
char str[100],dir[100];
using namespace std;
struct node{
ll loc,a0,d,len,cnt;
}q1[1008611],q2[1008611];
ll ans;
int main(){
int t;
ll m,n,r;
scanf("%d",&t);
while(t--){
scanf("%lld%lld",&m,&n);
ll k1=0,k2=0;
while(m--){
ans=0;
scanf("%s",str);
if(str[0]=='U'){
scanf("%s",dir);
if(dir[0]=='E'){
scanf("%lld%lld%lld%lld",&q1[k1].loc,&q1[k1].a0,&q1[k1].d,&q1[k1].len);
k1++;
}
else{
scanf("%lld%lld%lld%lld",&q2[k2].loc,&q2[k2].a0,&q2[k2].d,&q2[k2].len);
k2++;
}
}
else{
scanf("%lld",&r);
for(int i=0;i<k1;i++){
if(q1[i].loc+q1[i].len-1>=r&&q1[i].loc<=r){
ans+=q1[i].a0+(r-q1[i].loc)*q1[i].d;
}
}
for(int i=0;i<k2;i++){
if(q2[i].loc-q2[i].len+1<=r&&q2[i].loc>=r){
ans+=q2[i].a0+(q2[i].loc-r)*q2[i].d;
}
}
printf("%lld\n",ans);
}
}
}
return 0;
}