题目描述

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.

题目大意:

先输入一个整数t,代表有t组测试样例,对于每组样例先输入两个整数m,n,m代表下面m行操作,n代表数组的长度,对于每一行操作,先输入一个字母,'U'代表修改,‘Q’代表查询,对于U操作,先输入一个字母,'E'代表向右,'W'代表向左,后面跟着四个正整数a,b,c,d,代表从数组里面的第a项开始,往左或往右修改d项,对于第一项将其加上b,第二项加上b+c,第三项加上b+2*c,等等,按照等差的形式修改这d项元素。而Q操作即查询经过修改后的元素是多少。

解题思路:

此题只需将所有的修改操作存在一个结构体中,当进行查询时,通过遍历这些操作,判断所需要查询的元素是否在其修改区间内,在就改变元素的值,否则继续。注意:此题需用scanf,printf输入输出,用cin,cout会超时,并且数据类型最好定义为long long,防止出错。

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
struct node
{char dir;int start;ll fir;ll d;int len;
}arr[500500];
int main()
{#ifndef ONLINE_JUDGEfreopen("in.txt", "r", stdin);#endif//freopen("out.txt", "w", stdout);ios::sync_with_stdio(0),cin.tie(0);int t;scanf("%d",&t);while(t--) {char s1[10];char s[10];int cnt=0;int m,n;scanf("%d %d",&m,&n);while(m--) {scanf("%s",s1);if(s1[0]=='U') {scanf("%s",s);int a,d;ll b,c;scanf("%d %lld %lld %d",&a,&b,&c,&d);cnt++;arr[cnt].dir=s[0];arr[cnt].start=a;arr[cnt].fir=b;arr[cnt].d=c;arr[cnt].len=d;}else {int id;scanf("%d",&id);ll ans=0;for(int i=1;i<=cnt;i++) {if(arr[i].dir=='E') {if(arr[i].start<=id&&arr[i].start+arr[i].len-1>=id) {ans=ans+(arr[i].fir+(id-arr[i].start)*arr[i].d);}}else if(arr[i].dir=='W') {if(arr[i].start>=id&&arr[i].start-arr[i].len+1<=id) {ans=ans+(arr[i].fir+(arr[i].start-id)*arr[i].d);}}}printf("%lld\n",ans);}}}return 0;
}

【模拟】Ground Defense相关推荐

  1. Ground Defense 模拟

    题目描述 You are a denizen of Linetopia, whose n major cities happen to be equally spaced along an east- ...

  2. Interactron | 体现自适应的目标检测器

      欢迎关注我的公众号 [极智视界],获取我的更多笔记分享   大家好,我是极智视界,本文解读一下 体现自适应的目标检测器 Interactron.   多年来,人们提出了各种各样的方法来解决目标检测 ...

  3. 继LSTM之父用世界模型来模拟2D赛车后,谷歌又推出全新世界模型助力导航:360度无死角,就问你怕了没?...

    来源:AI科技评论本文约3400字,建议阅读10分钟 今年2月,Google AI 也用世界模型,在 Atari 游戏中实现了达到人类水平的表现. 近年来,世界模型(World Model)在机器人. ...

  4. 《Ray Tracing in One Weekend》、《Ray Tracing from the Ground Up》读后感以及光线追踪学习推荐...

    <Ray Tracing in One Weekend> 优点: 相对简单易懂 渲染效果相当好 代码简短,只看书上的代码就可以写出完整的程序,而且Github上的代码是将基类与之类写在一起 ...

  5. 【深度学习笔记】关键点检测——标签(Ground Truth)构建

    首先介绍一下关键点回归的Ground Truth的构建问题,主要有两种思路,Coordinate和Heatmap,Coordinate即直接将关键点坐标作为最后网络需要回归的目标,这种情况下可以直接得 ...

  6. 基于AcrGIS平台实现三维场景下的积水效果动态模拟

    文章目录 1.前言 2.环境准备 3.开发过程 3.1 软件安装 3.2 共享(发布)场景服务 3.3 积水区三维可视化 3.4 动态模拟 4. 完整代码 5. 效果图 6. 在线演示 1.前言 现有 ...

  7. 《ACM国际大学生程序设计竞赛题解Ⅰ》——模拟题

    这篇文章来介绍一些模拟题,即一类按照题目要求将现实的操作转换成程序语言. zoj1003: On every June 1st, the Children's Day, there will be a ...

  8. Educational Codeforces Round 10 A. Gabriel and Caterpillar 模拟

    A. Gabriel and Caterpillar 题目连接: http://www.codeforces.com/contest/652/problem/A Description The 9-t ...

  9. 机器学习与流体动力学:谷歌AI利用「ML+TPU」实现流体模拟数量级加速

    作者|魔王 来源|机器之心 谷歌 AI 最近一项研究表明,利用机器学习和硬件加速器能够改进流体模拟,且不损害准确率或泛化性能. 流体数值模拟对于建模多种物理现象而言非常重要,如天气.气候.空气动力学和 ...

最新文章

  1. jbpm binding类深入解析
  2. PokeCats开发者日志(一)
  3. a标签,选中当前菜单后高亮
  4. idea中构造器和toString方法覆写的快捷键
  5. 总结redis中对象的类型与编码
  6. SpringCloudConfig(了解)
  7. java获取当月有几天_腾讯程序员裸辞3个月,转行去送外卖,曝出当月收入网友:又骗我去送外卖...
  8. mingw linux socket,MingW上编译WinSocket程序undefined reference to `WSAStartup@8'报错的解决办法...
  9. [].slice.call
  10. 荣耀赵明:电视开关机广告不符合商业逻辑 用户需享受收益分成
  11. C语言的延时程序怎么改,C语言延时子程序准确设置
  12. 淘宝账号如何快速提升到更高等级
  13. 项目成功部署到idea ,并且成功运行,访问却是404
  14. 软件定义和硬件重构知多少(一)
  15. 细粒度分类之NTS_NET解读
  16. 【论文】使用endnote进行论文引用插入
  17. 河北工业机器人夹爪生产厂家_GIMATIC,GIMATIC电动夹爪,GIMATIC气动夹爪-工业控制领域一站式服务商-华联欧...
  18. 【安全攻防系列】教你如何 ssh暴力破解、捕捉短连接、清理挖矿病毒、盖茨木马和DDOS病毒
  19. 2018年中国电影总票房突破609亿这个惊心动魄的数字
  20. 齐治堡垒机配置文件服务器,登录齐治堡垒机简易使用手册V

热门文章

  1. C语言 void 指针 - C语言零基础入门教程
  2. 企业开发需要的git提交和拉取代码(本地仓库和github演示)
  3. php如何封装数组,PHP数组转对象 对象转数组封装类
  4. 杭州师范大学c语言程序设计机试,2016年杭州师范大学杭州国际服务工程学院程序设计基础考研复试题库...
  5. gin 静态文件服务器拒绝,nginx实现简单的图片服务器(windows)+静态文件服务器-Go语言中文社区...
  6. oracle实验四运动会,实验四oracle的安全性和完整性控制
  7. 方法 手写promise_JS探索-手写Promise
  8. java substring截取字符串_java基础教程之字符串的介绍,比较重要的一个知识点【下】...
  9. 中班机器人歌曲_机器人幼儿园大班音乐教案
  10. python renamer模块_artellapipe-tools-renamer-以简单的方式重命名DCC对象的工具-Tomas Poveda...