博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Sandglass
阅读量:5222 次
发布时间:2019-06-14

本文共 1631 字,大约阅读时间需要 5 分钟。

题目描述

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.

样例输入

180360 120 180330 9061 1180 180

样例输出

601120 题解移步晨哥博客然后其实题目数据是按照时间顺序给的,所以我代码中的排序其实是没有用的qwq
#include
#define ll long long#define inf 0x3f3f3f3fusing namespace std;const int N=1e5+50;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
x) mn=x; if (mn<0) mn=0; if (mx>x) mx=x; if (mx<0) mx=0; k++; flag*=-1; } ll now=c[i].a+tmp; //cout<<'*'<
<<' '<
<<' '; if (now>mx) now=mx; else if (now
View Code

 

 

转载于:https://www.cnblogs.com/tetew/p/9419621.html

你可能感兴趣的文章
[LeetCode]662. Maximum Width of Binary Tree判断树的宽度
查看>>
WinForm聊天室
查看>>
【Python学习笔记】1.基础知识
查看>>
梦断代码阅读笔记02
查看>>
selenium学习中遇到的问题
查看>>
大数据学习之一——了解简单概念
查看>>
Linux升级内核教程(CentOS7)
查看>>
Lintcode: Partition Array
查看>>
分享适合个人站长的5类型网站
查看>>
类别的三个作用
查看>>
【SICP练习】85 练习2.57
查看>>
runC爆严重安全漏洞,主机可被攻击!使用容器的快打补丁
查看>>
Maximum Product Subarray
查看>>
solr相关配置翻译
查看>>
通过beego快速创建一个Restful风格API项目及API文档自动化(转)
查看>>
解决DataSnap支持的Tcp长连接数受限的两种方法
查看>>
Synchronous/Asynchronous:任务的同步异步,以及asynchronous callback异步回调
查看>>
ASP.NET MVC5 高级编程-学习日记-第二章 控制器
查看>>
Hibernate中inverse="true"的理解
查看>>
高级滤波
查看>>