题目描述

We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb.
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的更多相关文章

  1. 【AtCoder】ARC082 F - Sandglass

    [链接]F - Sandglass [题意]给定沙漏A和B,分别装着a和X-a的沙子,开始时A在上B在下,每秒漏1,漏完不再漏.给定n,有n个时刻ai沙漏倒转.给定m个询问,每次询问给定初值a和时刻t ...

  2. 2017国家集训队作业[arc082d]Sandglass

    2017国家集训队作业[arc082d]Sandglass 题意: ​ 有一个沙漏,初始时\(A\)瓶在上方,两个瓶子的最大容量都为\(X\)克,沙子流动的速度为\(1g\)每单位时间.给出\(K\) ...

  3. 【ARC082D】Sandglass

    Description ​ 题目链接 Description ​ 好题.题意是维护一个初始值,交替加减一段时间,有上界\(m\)和下界0(不能超过这两条界限),问对于某一种初始值,在某一个时刻时该值为 ...

  4. [arc082F]Sandglass

    Description 传送门 Solution 这题是真的666啊... 以下是本题最关键最关键的结论:如果ai<=aj,则在某个时间t,前者的A中沙子克数(记为t(ai))一定大于等于t(a ...

  5. [arc082f]Sandglass 递推

    Description 有一个沙漏由两个上下相通玻璃球A和B构成,这两个玻璃球都含有一定量的沙子,我们暂且假定AB中位于上方的玻璃球的为U,下方的玻璃球为L,则除非U中没有沙子,否则每秒钟都会有1克沙 ...

  6. 【推导】【模拟】AtCoder Regular Contest 082 F - Sandglass

    题意:有个沙漏,一开始bulb A在上,bulb B在下,A内有a数量的沙子,每一秒会向下掉落1.然后在K个时间点ri,会将沙漏倒置.然后又有m个询问,每次给a一个赋值ai,然后询问你在ti时刻,bu ...

  7. Arc082_F Sandglass

    Description有一个沙漏由两个上下相通玻璃球$A$和$B$构成,这两个玻璃球都含有一定量的沙子,我们暂且假定$A,B$中位于上方的玻璃球的为$U$,下方的玻璃球为$L$,则除非$U$中没有沙子 ...

  8. [ARC082F] Sandglass(线段树)

    Description 有一个沙漏由两个上下相通玻璃球 \(A\) 和 \(B\) 构成,这两个玻璃球都含有一定量的沙子,我们暂且假定 \(AB\) 中位于上方的玻璃球的为 \(U\),下方的玻璃球为 ...

  9. 【AtCoder Regular Contest 082 F】Sandglass

    [链接]点击打开链接 [题意] 你有一个沙漏. 沙漏里面总共有X单位的沙子. 沙漏分A,B上下两个部分. 沙漏从上半部分漏沙子到下半部分. 每个时间单位漏1单位的沙子. 一开始A部分在上面.然后在r1 ...

随机推荐

  1. HDU 4300 Clairewd’s message (next函数的应用)

    题意:给你一个明文对密文的字母表,在给你一段截获信息,截获信息前半段是密文,后半段是明文,但不清楚它们的分界点在哪里,密文一定是完整的,明文可能是残缺的,求完整的信息串(即完整的密文+明文串). 题解 ...

  2. 软工2017第六周团队协作——个人PSP

    10.20 --10.26本周例行报告 1.PSP(personal software process )个人软件过程. 类型 任务 开始时间                结束时间 中断时间 实际用 ...

  3. YaoLingJump开发者日志(一)

      写完PokeCats之后意犹未尽,还想做一个更加有趣的游戏,比如说像超级玛丽那样.   游戏的主角就选"瑶玲"了,这是我小时候最喜欢的动画片<瑶玲啊瑶玲>的女主角. ...

  4. PAT 甲级 1038 Recover the Smallest Number

    https://pintia.cn/problem-sets/994805342720868352/problems/994805449625288704 Given a collection of ...

  5. cacti监控多个mysql端口

    1. 在Console -> Data Templates 找到mysql-cacti-templates的mysql模板,编辑: 在这里面把Port的Use Per-Data Source V ...

  6. Delphi DBGridEH中,选中行、列、单元格

    // 新增行后,默认首列 procedure TForm1.ADOQuery1AfterInsert(DataSet: TDataSet);begin  with DBGridEh1 do  begi ...

  7. BZOJ4870:[SHOI2017]组合数问题——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=4870 https://www.luogu.org/problemnew/show/P3746 看网上 ...

  8. CF633C:Spy Syndrome 2——题解

    https://vjudge.net/problem/CodeForces-633C http://codeforces.com/problemset/problem/633/C 点击这里看巨佬题解 ...

  9. 第13届 广东工业大学ACM程序设计大赛 C题 平分游戏

    第13届 广东工业大学ACM程序设计大赛 C题 平分游戏 题目描述 转眼间又过了一年,又有一届的师兄师姐要毕业了. ​ 有些师兄师姐就去了景驰科技实习. 在景驰,员工是他们最宝贵的财富.只有把每一个人 ...

  10. HDOJ.1010 Tempter of the Bone (DFS)

    Tempter of the Bone [从零开始DFS(1)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tem ...