问题 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【不知道叫啥可能就是枚举】的更多相关文章

  1. upc组队赛5 Ground Defense【枚举】

    Ground Defense 题目描述 You are a denizen of Linetopia, whose n major cities happen to be equally spaced ...

  2. 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 ...

  3. 在ASP.Net Core 中使用枚举类而不是枚举

    前言:我相信大家在编写代码时经常会遇到各种状态值,而且为了避免硬编码和代码中出现魔法数,通常我们都会定义一个枚举,来表示各种状态值,直到我看到Java中这样使用枚举,我再想C# 中可不可以这样写,今天 ...

  4. 聊一下C#开发者如何过渡到JAVA 开发者

    由于工作需要,最近也开始倒腾Java了.NET的话,从2012年测试版开始玩的,那个时候VB6比较熟悉,还天真的以为VB.NET以后会很火, 事实证明,也只是一厢情愿,有C#了,要VB.NET干什么? ...

  5. bzoj2669[cqoi2012]局部极小值 容斥+状压dp

    2669: [cqoi2012]局部极小值 Time Limit: 3 Sec  Memory Limit: 128 MBSubmit: 774  Solved: 411[Submit][Status ...

  6. 如何正确对用户密码进行加密?转自https://blog.csdn.net/zhouyan8603/article/details/80473083

    本文介绍了对密码哈希加密的基础知识,以及什么是正确的加密方式.还介绍了常见的密码破解方法,给出了如何避免密码被破解的思路.相信读者阅读本文后,就会对密码的加密有一个正确的认识,并对密码正确进行加密措施 ...

  7. kruskal(拓展)

    kruskal是最小生成树的一种做法,即严格按照贪心思想将边从小到大排序,一个一个枚举能不能加入图中,知道生成一棵树,显然树为最小树. 鄙人觉得kruskal做法远不止如此,那种严格从小到大选边的做法 ...

  8. CSU 1859 Gone Fishing(贪心)

    Gone Fishing [题目链接]Gone Fishing [题目类型]贪心 &题解: 这题要先想到枚举走过的湖,之后才可以贪心,我就没想到这,就不知道怎么贪心 = = 之后在枚举每个湖的 ...

  9. 2.TypeScript 基础入门(二)

    变量类型的那些事 1.基本注解 类型注解使用:TypeAnnotation 语法.类型声明空间中可用的任何内容都可以用作类型注解. const num: number = 123; function ...

随机推荐

  1. anconda1.8+cuda9.0+cudnn7.0.5+tensorflow1.7(win10)安装

    1.下载安装cuda9.0 https://developer.nvidia.com/cuda-90-download-archive 2.下载cudnn7.0.5,下载cuda9.0的对应版本 ht ...

  2. Linux 运维测试及第三应用及测试工具

    一 .第三方应用及测试工具链接地址 https://pan.baidu.com/s/1rLQ5NCZvxcy93YQ4fGFaBQ 1.linux LSI系列raid卡监测工具 1)使用参数详解链接: ...

  3. NSOperation、NSOperationQueue(III)

    NSOperation.NSOperationQueue 常用属性和方法归纳 NSOperation 常用属性和方法 a. 取消操作方法 //可取消操作,实质是标记 isCancelled 状态. - ...

  4. Visual Assist 10.9.2248 破解版(支持VS2017)

    [1]下载安装包 下载地址:https://download.csdn.net/download/qq_20044811/10597708 [2]安装与破解方法 第一步:关闭VS所有打开窗体 第二步: ...

  5. 面试题-JAVA算法题

    1.编写一个程序,输入n,求n!(用递归的方式实现). public static long fac(int n){ if(n<=0) return 0; else if(n==1) retur ...

  6. RN与android原生开发混合后的环境报错问题

    RN与android原生开发混合后的环境报错问题 需要先安装nodejs$ yarn --version1.12.1更新当前版本yarn upgrade --latest安装 | Yarnhttps: ...

  7. jar包读取jar包内部和外部的配置文件,springboot读取外部配置文件的方法

    jar包读取jar包内部和外部的配置文件,springboot读取外部配置文件的方法 用系统属性System.getProperty("user.dir")获得执行命令的目录(网上 ...

  8. Mybatis+MySQL动态分页查询

    https://blog.csdn.net/qq_34137397/article/details/63289621 mybatis有两种分页方法 1.内存分页,也就是假分页.本质是查出所有的数据然后 ...

  9. 算法提高 P0102

    用户输入三个字符,每个字符取值范围是0-9,A-F.然后程序会把这三个字符转化为相应的十六进制整数,并分别以十六进制,十进制,八进制输出,十六进制表示成3位,八进制表示成4位,若不够前面补0.(不考虑 ...

  10. <转>jmeter(十三)常见问题及解决方法

    本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...