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 ...
随机推荐
- linux网卡eth1如何修改为eth0
ifconfig看到的ip不是我想要的ip,而且显示的第一块网卡也是eth1 ,这明显是有问题的, vim /etc/sysconfig/network-script/ifcfg-eth0 看到的ip ...
- 依赖反转Ioc和unity,autofac,castle框架教程及比较
1.依赖倒置的相关概念 http://www.cnblogs.com/fuchongjundream/p/3873073.html IoC模式(依赖.依赖倒置.依赖注入.控制反转) 2.依赖倒置的方式 ...
- Vue系列之 => 组件切换
组件切换方式一 <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...
- html5-样式的三种方式
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- EasyUI表格DataGrid前端分页和后端分页的总结
Demo简介 Demo使用Java.Servlet为后台代码(数据库已添加数据),前端使用EasyUI框架,后台直接返回JSON数据给页面 1.配置Web.xml文件 <?xml version ...
- 【2017-2-23】C#switch case分支语句,for循环语句
switch case分支语句 switch(一个变量值) { case 值:要执行的代码段;break; case 值:要执行的代码段;break; … default:代码段;break;(def ...
- 吴恩达深度学习笔记(deeplearning.ai)之卷积神经网络(CNN)(上)
作者:szx_spark 1. Padding 在卷积操作中,过滤器(又称核)的大小通常为奇数,如3x3,5x5.这样的好处有两点: 在特征图(二维卷积)中就会存在一个中心像素点.有一个中心像素点会十 ...
- js相关(easyUI),触发器,ant,jbpm,hibernate二级缓存ehcache,Javamail,Lucene,jqplot,WebService,regex,struts2,oracle表空间
*********************************************js相关********************************************* // 在指 ...
- Step7:SQL Server 多实例下的复制
一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 搭建步骤(Procedure) 注意事项(Attention) 二.背景(Contexts) ...
- Java学习路线教程之JDBC基本操作
为了帮助大家熟练应用JDBC编程,接下来,在本节将通过一个综合案例来讲解JDBC的基本操作,确保大家能够深刻理解JDBC的增.删.改.查,灵活利用JDBC完成对数据库的各项操作. 1. 创建一个Jav ...