Sandglass
题目描述
The sand drops from the upper bulb to the lower bulb at a rate of 1 gram per second. When the upper bulb no longer contains any sand, nothing happens.
Initially at time 0, bulb A is the upper bulb and contains a grams of sand; bulb B contains X−a grams of sand (for a total of X grams).
We will turn over the sandglass at time r1,r2,..,rK. Assume that this is an instantaneous action and takes no time. Here, time t refer to the time t seconds after time 0.
You are given Q queries. Each query is in the form of (ti,ai). For each query, assume that a=ai and find the amount of sand that would be contained in bulb A at time ti.
Constraints
1≤X≤109
1≤K≤105
1≤r1<r2<..<rK≤109
1≤Q≤105
0≤t1<t2<..<tQ≤109
0≤ai≤X(1≤i≤Q)
All input values are integers.
样例输入
180
3
60 120 180
3
30 90
61 1
180 180
样例输出
60
1
120 题解移步晨哥博客https://www.cnblogs.com/tian-luo/p/9387640.html然后其实题目数据是按照时间顺序给的,所以我代码中的排序其实是没有用的qwq
#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int N=1e5+;
ll x;
int n,m;
struct orz{
ll t,a;
int id;}c[N];
ll r[N],ans[N];
bool cmp(orz a,orz b)
{
return a.t<b.t;
}
int main()
{
scanf("%lld",&x);
scanf("%d",&n);
for (int i=;i<=n;i++) scanf("%lld",&r[i]);
scanf("%d",&m);
for (int i=;i<=m;i++)
{
scanf("%lld%lld",&c[i].t,&c[i].a);
c[i].id=i;
}
sort(c+,c++m,cmp);
r[n+]=c[m].t+;
ll mx=x,mn=,tmp=,tt=,flag=-; int k=;
for (int i=;i<=m;i++)
{
while (r[k]<=c[i].t&&k<=n)
{
tt=(r[k]-r[k-])*flag;
tmp+=tt;
mx+=tt; mn+=tt;
if (mn>x) mn=x; if (mn<) mn=;
if (mx>x) mx=x; if (mx<) mx=;
k++; flag*=-;
} ll now=c[i].a+tmp; //cout<<'*'<<now<<' '<<tmp<<' ';
if (now>mx) now=mx; else if (now<mn) now=mn; //cout<<now<<endl; if (k%) ans[c[i].id]=max(now-(c[i].t-r[k-]),(ll));
else ans[c[i].id]=min(now+(c[i].t-r[k-]),x);
}
for (int i=;i<=m;i++) printf("%lld\n",ans[i]);
return ;
}
Sandglass的更多相关文章
- 【AtCoder】ARC082 F - Sandglass
[链接]F - Sandglass [题意]给定沙漏A和B,分别装着a和X-a的沙子,开始时A在上B在下,每秒漏1,漏完不再漏.给定n,有n个时刻ai沙漏倒转.给定m个询问,每次询问给定初值a和时刻t ...
- 2017国家集训队作业[arc082d]Sandglass
2017国家集训队作业[arc082d]Sandglass 题意: 有一个沙漏,初始时\(A\)瓶在上方,两个瓶子的最大容量都为\(X\)克,沙子流动的速度为\(1g\)每单位时间.给出\(K\) ...
- 【ARC082D】Sandglass
Description 题目链接 Description 好题.题意是维护一个初始值,交替加减一段时间,有上界\(m\)和下界0(不能超过这两条界限),问对于某一种初始值,在某一个时刻时该值为 ...
- [arc082F]Sandglass
Description 传送门 Solution 这题是真的666啊... 以下是本题最关键最关键的结论:如果ai<=aj,则在某个时间t,前者的A中沙子克数(记为t(ai))一定大于等于t(a ...
- [arc082f]Sandglass 递推
Description 有一个沙漏由两个上下相通玻璃球A和B构成,这两个玻璃球都含有一定量的沙子,我们暂且假定AB中位于上方的玻璃球的为U,下方的玻璃球为L,则除非U中没有沙子,否则每秒钟都会有1克沙 ...
- 【推导】【模拟】AtCoder Regular Contest 082 F - Sandglass
题意:有个沙漏,一开始bulb A在上,bulb B在下,A内有a数量的沙子,每一秒会向下掉落1.然后在K个时间点ri,会将沙漏倒置.然后又有m个询问,每次给a一个赋值ai,然后询问你在ti时刻,bu ...
- Arc082_F Sandglass
Description有一个沙漏由两个上下相通玻璃球$A$和$B$构成,这两个玻璃球都含有一定量的沙子,我们暂且假定$A,B$中位于上方的玻璃球的为$U$,下方的玻璃球为$L$,则除非$U$中没有沙子 ...
- [ARC082F] Sandglass(线段树)
Description 有一个沙漏由两个上下相通玻璃球 \(A\) 和 \(B\) 构成,这两个玻璃球都含有一定量的沙子,我们暂且假定 \(AB\) 中位于上方的玻璃球的为 \(U\),下方的玻璃球为 ...
- 【AtCoder Regular Contest 082 F】Sandglass
[链接]点击打开链接 [题意] 你有一个沙漏. 沙漏里面总共有X单位的沙子. 沙漏分A,B上下两个部分. 沙漏从上半部分漏沙子到下半部分. 每个时间单位漏1单位的沙子. 一开始A部分在上面.然后在r1 ...
随机推荐
- Discover the Web(栈模拟)
Description Standard web browsers contain features to move backward and forward among the pages rece ...
- 软工第三次作业——个人PSP
9.22--9.26本周例行报告 1.PSP(personal software process )个人软件过程. 类型 任务 预计时间 开始时间 结束时间 中断时间 实际用时 准备工作 学习重定向 ...
- JSR303中的来验证数据信息
spring mvc之实现简单的用户管理三 博客分类: spring spring mvc spring mvc dispatcherServlet springspring mvcbean vali ...
- C语言 指针数组 多维数组
. 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/21402047 . 1. 地址算数运算示例 指针算数运算 ...
- python正则表达式函数match()和search()的区别详解
match()和search()都是python中的正则匹配函数,那这两个函数有何区别呢? match()函数只检测RE是不是在string的开始位置匹配, search()会扫描整个string查找 ...
- c#笔记整理 关于继承与多态等
[ 塔 · 第 二 条 约 定 ] c#面向对象基础 整理private.protected.public.abstract等的异同 public 公有访问.不受任何限制. private 私有访问. ...
- ACM 第九天
动态规划1 动态规划问题是面试题中的热门话题,如果要求一个问题的最优解(通常是最大值或者最小值),而且该问题能够分解成若干个子问题,并且小问题之间也存在重叠的子问题,则考虑采用动态规划. 1.LLS ...
- 转 Js 跨域CORS报错 Response for preflight has invalid HTTP status code 405
转自:http://www.cnblogs.com/SilenceTom/p/6697484.html 调用接口遇到Response for preflight has invalid HTTP st ...
- mini2440 Nor Flash工作原理分析
我的mini2440上是只接了一块Nor Flash,型号是S29AL016M90TAI02,这是一块2M Byte,16位宽度的Nor Flash,用于引导扇区的闪存.原理图里面关键的引脚是: 地址 ...
- AndroidStudio3.0 注解报错Annotation processors must be explicitly declared now. The following dependencies on the compile classpath are found to contain annotation processor.
把Androidstudio2.2的项目放到3.0里面去了,然后开始报错了. 体验最新版AndroidStudio3.0 Canary 8的时候,发现之前项目的butter knife报错,用到注解的 ...