问题 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. 如何重置Sitecore CMS中的管理员密码

    在Sitecore项目上工作时,有时管理员凭据会丢失或损坏.在这些情况下,重新获得快速访问权限以便不中断开发非常重要. 对Core数据库运行以下查询,您将能够admin/b再次使用以下命令登录Site ...

  2. Unicode字符需要几个字节来存储?

    0)学习笔记: 我们常说的这句话“Unicode字符是2个字节”这句话有毛病 Unicode目前规划的总空间有17个平面, 0x0000---0x10FFFF,每个平面有 65536 个码点. Uni ...

  3. 查看完整的 Unicode 字符集

    https://unicode-table.com/cn/ 这个链接是我想要查的 格式如下图 先放这里收藏,我也不知道怎么搜索

  4. python 读csv文件时,在csv类型上执行类型转换

    csv 产生的数据都是字符串类型的,它不会做任何其他类型的转换.如果需要做这样的类型转换,必须自己手动去实现 import csv,re from collections import namedtu ...

  5. ORM for Net主流框架汇总

    ORM框架:Object/Relation Mapping(对象/关系 映射)的缩写,易于理解的模型化数据的方法.简单的说就是把数据库的关系型数据类型转换为用对象型程序控制的框架类型. 框架优缺点分析 ...

  6. Oracle执行计划 explain plan

    Rowid的概念:rowid是一个伪列,既然是伪列,那么这个列就不是用户定义,而是系统自己给加上的. 对每个表都有一个rowid的伪列,但是表中并不物理存储ROWID列的值.不过你可以像使用其它列那样 ...

  7. JavaScript 中禁止用户右键菜单,复制,选取,Ctrl,Alt,Shift. 获取宽高,清除浮动

    //禁用右键菜单 document.oncontextmenu = function(){ event.returnValue = false; } //禁用选取内容 document.onselec ...

  8. js 简易时钟

    html部分 <div id="clock"> </div> css部分 #clock{ width:600px ; text-align: center; ...

  9. AJAX异步请求,局部刷新

    AJAX异步请求,局部刷新 window.onload=function(){ //dom事件,页面加载完成执行如下函数 doGetObjects(); } function doGetObjects ...

  10. linux 安装sqlite3

    python2个版本导致的问题. 网上找了好多方法都不行. 最后自己莫名其妙弄好了, 回想了一下大概是 安装sqlite3 重新安装python 最后 yum update 更新 就好了.