upc组队赛5 Ground Defense【枚举】
Ground Defense
题目描述
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.
样例输入
1
8 3
U E 1 5 2 3
Q 1
Q 2
Q 3
U W 3 10 10 2
Q 1
Q 2
Q 3
样例输出
5
7
9
5
27
19
提示
Two aircrafts 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.
题解
每次更新的时候就用结构体存下来,
然后查的时候再遍历结构体计算
比赛的时候看这题这么少人过,觉得是我们想的太简单了、没怎么敢写,而且一直在怼另外那个E题
然而真的就是这样做= 。=
注意long long ,计算的过程中也要强制转换long long,这里WA了两发
代码
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;++i)
#define readc(x) scanf("%c",&x)
#define read(x) scanf("%d",&x)
#define sca(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define print(x) printf("%d\n",x)
#define mst(a,b) memset(a,b,sizeof(a))
#define lowbit(x) x&-x
#define lson(x) x<<1
#define rson(x) x<<1|1
#define pb push_back
#define mp make_pair
typedef pair<int,int> P;
typedef long long ll;
const int INF =0x3f3f3f3f;
const int inf =0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 105;
const int maxn = 10010;
struct node
{
int st;
int len;
int orient;
int a0;
int d;
}p[500005];
char s[5];
ll a,b,c,d;
int cnt ;
int main()
{
int t;
sca(t);
while(t--)
{
cnt = 0;
int m,n;
read2(m,n);
while(m--)
{
scanf("%s", s);
if(s[0] == 'U'){
scanf("%s",s);
p[cnt].orient = s[0] == 'E' ;
scanf("%d%d%d%d",&a,&b,&c,&d);
p[cnt].st = a;
p[cnt].a0 = b;
p[cnt].d = c;
p[cnt++].len = d;
}
else {
int x;
read(x);
ll ans = 0;
for(int i = 0; i < cnt ;i++){
if(p[i].orient && x >= p[i].st && x <= p[i].st + p[i].len - 1) {
ans += p[i].a0 + (ll)(x - p[i].st) * p[i].d;
}
else if(!p[i].orient && x <= p[i].st && x >= p[i].st - p[i].len + 1) {
ans += p[i].a0 + (ll)(p[i].st - x) * p[i].d;
}
}
printf("%lld\n",ans);
}
}
}
return 0;
}
upc组队赛5 Ground Defense【枚举】的更多相关文章
- upc组队赛6 GlitchBot【枚举】
GlitchBot 题目描述 One of our delivery robots is malfunctioning! The job of the robot is simple; it shou ...
- Ground Defense【不知道叫啥可能就是枚举】
问题 G: Ground Defense 时间限制: 1 Sec 内存限制: 128 MB 提交: 116 解决: 22 [提交] [状态] [命题人:admin] 题目描述 You are a ...
- upc组队赛17 Bits Reverse【暴力枚举】
Bits Reverse 题目链接 题目描述 Now given two integers x and y, you can reverse every consecutive three bits ...
- upc组队赛12 Cardboard Container【枚举】
Cardboard Container Problem Description fidget spinners are so 2017; this years' rage are fidget cub ...
- upc组队赛6 Odd Gnome【枚举】
Odd Gnome 题目描述 According to the legend of Wizardry and Witchcraft, gnomes live in burrows undergroun ...
- upc组队赛2 Super-palindrome【暴力枚举】
Super-palindrome 题目描述 You are given a string that is consisted of lowercase English alphabet. You ar ...
- upc 组队赛18 STRENGTH【贪心模拟】
STRENGTH 题目链接 题目描述 Strength gives you the confidence within yourself to overcome any fears, challeng ...
- upc组队赛16 Melody【签到水】
Melody 题目描述 YellowStar is versatile. One day he writes a melody A = [A1, ..., AN ], and he has a sta ...
- upc组队赛6 Bumped!【最短路】
Bumped! 题目描述 Peter returned from the recently held ACM ICPC World finals only to find that his retur ...
随机推荐
- svn设置文件提交过滤、svn设置classes文件提交
在svn提交文件的时候为了避免一些不必要的文件也提交到资源库 像编译后的.class文件 第一步:在文件中右击打开设置, 第二步:找到全局忽略样式 第三步:修改要过滤的文件 设置过滤通配符 *clas ...
- python-javascript之bom
BOM BOM介绍 全称 Browser Object Mode 浏览器对象模式 操作浏览器的API接口.比如浏览器自动滚动 Windows对象的顶层部分是BOM的顶层(核心)对象,所有的对象都是通过 ...
- 恐怖的奴隶主(bob)
题目描述 小L热衷于undercards. 在undercards中,有四个格子.每个格子要么是空的,要么住着一只BigBob. 每个BigBob有一个不超过k的血量:血量减到0视为死亡.那个格子随即 ...
- 使用phpexcel导入excel文件种的时期数据时数据导入格式
在使用phpexcel导入类似于 YYYY-MM-DD HH:ii:ss格式的数据时,导入成功以后会发现导入的数据其实是类似于42085.746516204格式的数据( excel在存储时间类型的数据 ...
- ZR-19CSP-S赛前冲刺
ZR-19CSP-S赛前冲刺 1 ZR-19CSP-S赛前冲刺 2 ZR-19CSP-S赛前冲刺 3 ZR-19CSP-S赛前冲刺 4 ZR-19CSP-S赛前冲刺 5 ZR-19CSP-S赛前冲刺 ...
- c# 编程--方法(函数)
方法(函数) 能够独立完成某项功能的模块 函数的四要素:函数名.输入.输出.函数体 函数定义.函数的调用 函数就是将一堆代码进行重用的一种机制,函数就是一段代码,这段代码可能有输入的值(参 ...
- Nginx的应用之安装配置
一.Nginx简述 Nginx是一个开源且高性能.可靠的Http Web服务.代理服务. 开源: 直接获取源代码 高性能: 支持海量并发 可靠: 服务稳定 我们为什么选择 Nginx服务 Nginx非 ...
- Linux下的上传和下载yum install -y lrzsz
先使用命令 yum install -y lrzsz rz 上传 或者直接拖动 sz 要下的文件 回车
- 浅谈JavaScript原型图与内存模型
js原型详解 1.内存模型: 1.原型是js中非常特殊一个对象,当一个函数(Person)创建之后,会随之就产生一个原型对象 2. 当通过这个函数的构造函数创建了一个具体的对象(p1)之后,在这个具体 ...
- hadoop 2.7 添加或删除datanode节点
1.测试环境 ip 主机名 角色 10.124.147.22 hadoop1 namenode 10.124.147.23 hadoop2 namenode 10.124.147.32 hadoop3 ...