Ground Defense【不知道叫啥可能就是枚举】
问题 G: Ground Defense
时间限制: 1 Sec 内存限制: 128 MB
提交: 116 解决: 22
[提交] [状态] [命题人:admin]
题目描述
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;
}
Ground Defense【不知道叫啥可能就是枚举】的更多相关文章
- upc组队赛5 Ground Defense【枚举】
Ground Defense 题目描述 You are a denizen of Linetopia, whose n major cities happen to be equally spaced ...
- Stanford Local 2016 G "Ground Defense"(线段树)
传送门 题意: 有 n 个城市,编号 1~n: 有两种操作:Update,Query Update: E i s a d 更新区间[ i,i+d-1 ], i 节点降落 s 人, i+1 节点降落 s ...
- 在ASP.Net Core 中使用枚举类而不是枚举
前言:我相信大家在编写代码时经常会遇到各种状态值,而且为了避免硬编码和代码中出现魔法数,通常我们都会定义一个枚举,来表示各种状态值,直到我看到Java中这样使用枚举,我再想C# 中可不可以这样写,今天 ...
- 聊一下C#开发者如何过渡到JAVA 开发者
由于工作需要,最近也开始倒腾Java了.NET的话,从2012年测试版开始玩的,那个时候VB6比较熟悉,还天真的以为VB.NET以后会很火, 事实证明,也只是一厢情愿,有C#了,要VB.NET干什么? ...
- bzoj2669[cqoi2012]局部极小值 容斥+状压dp
2669: [cqoi2012]局部极小值 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 774 Solved: 411[Submit][Status ...
- 如何正确对用户密码进行加密?转自https://blog.csdn.net/zhouyan8603/article/details/80473083
本文介绍了对密码哈希加密的基础知识,以及什么是正确的加密方式.还介绍了常见的密码破解方法,给出了如何避免密码被破解的思路.相信读者阅读本文后,就会对密码的加密有一个正确的认识,并对密码正确进行加密措施 ...
- kruskal(拓展)
kruskal是最小生成树的一种做法,即严格按照贪心思想将边从小到大排序,一个一个枚举能不能加入图中,知道生成一棵树,显然树为最小树. 鄙人觉得kruskal做法远不止如此,那种严格从小到大选边的做法 ...
- CSU 1859 Gone Fishing(贪心)
Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的 ...
- 2.TypeScript 基础入门(二)
变量类型的那些事 1.基本注解 类型注解使用:TypeAnnotation 语法.类型声明空间中可用的任何内容都可以用作类型注解. const num: number = 123; function ...
随机推荐
- hibernate添加数据入门小案例
1.建立一个java项目,在目录下新建一个lib文件夹引入hibernate架包如图所示: 2. 新建com.LHB.domain包,在包中分别创建一个Employee.java和Employee.h ...
- 《大话设计模式》c++实现 建造者模式
一.UML图 关键词:Subject维护一个Observer列表,Subject执行Notify()时就执行列表中的每个Observer的Update(). 二.概念 观察者模式:定义了一种一对多的依 ...
- django 设置不带后缀的访问路径
在urls.py 设置空路径,并指向对应的html文件 url(r'^$', views.index),
- hdu5029 树链剖分 + 线段树
将树映射在线段上进行操作 然后每个 重链变成一个连续的区间 #include <iostream> #include <cstdio> #include <strin ...
- 特征点方法 - Harris和SURF的手工实现
整理去年做的小项目,纪念我的图像处理入门. 因为要在DSP上实现,所以完全手工C代码垒起来的,还要保证和PC端跑的结果一样,觉得可能特殊场景会有用,上传github,没有依赖任何库: 格式注释什么的暂 ...
- HTML转义符
空格的替代符号有以下几种: 名称 编号 描述 &#; 不断行的空白(1个字符宽度) &#; 半个空白(1个字符宽度) &#; 一个空白(2个字符宽度) & ...
- 关于SQL语句中的distinct和group by
两种都能实现去重功能.区别: distinct只是将重复的行从结果中出去: group by是按指定的列分组,一般这时在select中会用到聚合函数. distinct是把不同的记录显示出来 grou ...
- Linux下实现免密登录
过程如下: 1.Linux下生成密钥 通过命令”ssh-keygen -t rsa“ 2.1 通过ssh-copy-id的方式 命令: ssh-copy-id -i ~/.ssh/id_rsa.put ...
- Chrome浏览器相关细节整理
一.上传文件卡死 可能时由于输入法的原因导致上传文件浏览器卡死.将输入法改为英文模式再操作上传文件就不会卡死了.
- arcgis desktop 地理编码服务发布
1.创建地址定位器 2.创建复合地址定位器 3.鼠标右键,共享为,地理编码服务.