问题 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. laravel 之jwt认证使用详解

    转载 http://www.heibaiketang.com/blog/show/3.html https://packagist.org/packages/tymon/jwt-auth#1.0.0- ...

  2. ob

    可以利用ob_get_contens生成静态页面,应用场景 后台生成商品的时候 可以生成对应的前台页面,其他页面直接调用. $result = $goods->create(); if ($re ...

  3. (转)yuicompressor 与 maven结合,打包,压缩js,css (一)

    js,css代码压缩 web站点需要对js,css代码进行压缩,打包,下面是利用maven进行打包压缩的配置 将压缩后的代码打入到war包中,并且压缩后的js,css文件名不变 <plugins ...

  4. Unity shader学习之逐像素漫反射光照模型

    shader如下: Shader "Custom/Diffuse Fragment-Level" { Properties { _Diffuse (,,,) } SubShader ...

  5. Beta冲刺1.0

    1. 提供当天站立式会议照片一张 2. 每个人的工作 (有work item 的ID) 3. 发布项目燃尽图 4. 每人的代码/文档签入记录 (1)代码签入记录 (2)代码签入链接   链接1   链 ...

  6. RobotFrameWork(十三)RobotFramework与loadrunner性能测试结合(基于Remote库)

    一般我们进行完功能测试,都需要进行下性能测试,那么这章我来介绍下,RobotFramework与loadrunner性能测试的融合,即运行完自动化功能测试,借助RobotFramework的Remot ...

  7. Gardener Bo (树剖 + 问题分解)

    一开始没看懂计算答案的第四部和update2,很迷.然后一直推敲之后才发下我计算的时候漏掉一个关键点.没有把加值的影响放到父节点上. #include<bits/stdc++.h> #de ...

  8. 类中静态成员变量 && 无法解析的外部符号

    [1]如下代码及编译错误 如标题,不做赘述. [2]原因及解决方案 原因:之所以报如上编译错误,因为静态成员变量未初始化. 解决方案:类中静态成员需要在类外进行初始化.其格式为:类型 类名::静态成员 ...

  9. react修改app.js添加中文内容后中文部分乱码解决

    [问题]:配置完react后修改app.js内容时添加中文出现如下乱码的中文. [A解决]文档——文本编码——转换文本编码,在弹出窗口修改,确定,搞定 [B解决]首先在EditPlus内:工具——首选 ...

  10. WIN7系统怎样增加C盘空间

    具体操作参考:https://jingyan.baidu.com/article/215817f78e05c01eda142385.html