题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229509

时间限制:2s

空间限制:512MB

题目大意:

在一个车站中有若干人在队列中等待车辆,求所有人等待时间的期望值

首先给定n和q,随后是n行操作:

"+ t k":在t时刻有k个人加入队列等待车辆

"- t k":在t时刻有k个人乘车离开队列

然后是q个数字代表在初始时刻车站中有多少个车在等待

求出每个询问对应的所有人的等待时间,如果有人始终等不到车则输出"INFINITY"

样例:



代码:

#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pi acos(-1.0)
#define mem0(a) memset(a,0,sizeof(a))
#define memf(b) memset(b,false,sizeof(b))
#define ll long long
#define eps 1e-10
#define inf 1e17
#define maxn 101010
int n, q;
int a[maxn], t[maxn];
int s[maxn];
int b[maxn], cnt;
long long ans[maxn];
struct node{
int x, id;
bool operator < (const node &rhs) const{
return x < rhs.x;
}
}c[maxn];
bool cmp(int i, int j){
return s[i] > s[j];
} int main()
{
freopen("expect.in", "r", stdin);
freopen("expect.out", "w", stdout);
scanf("%d%d", &n, &q);
for(int i = 1; i <= n; i++){
char op[5];
scanf("%s%d%d", op, &t[i], &a[i]);
if(op[0] == '-') a[i] = -a[i];
}
for(int i = 1; i <= n; i++){
s[i] = s[i-1] + a[i];
if(i < n) t[i] = t[i+1] - t[i];
}
// for(int i = 1; i <= n; i++){
// printf("s[%d] = %d, t[%d] = %d\n", i, s[i], i, t[i]);
// }
long long sum1 = 0, sum2 = 0;
for(int i = 1; i <= n; i++){
if(s[i] < 0){
b[++cnt] = i;
sum1 += 1LL*(-s[i])*t[i];
sum2 += t[i];
}
}
sort(b + 1, b + cnt + 1, cmp);
int j = 1;
long long k = 0;
for(int i = 1; i <= q; i++){
scanf("%d", &c[i].x);
c[i].id = i;
}
sort(c + 1, c + q + 1);
for(int i = 1; i <= q; i++){
int x = c[i].x;
while(j <= cnt && (-s[b[j]]) <= x){
sum1 -= 1LL*(-s[b[j]]) * t[b[j]];
sum2 -= t[b[j]];
++j;
}
if(s[n] + x < 0){
ans[c[i].id] = -1;
}
else{
ans[c[i].id] = sum1 - x * sum2;
}
}
for(int i = 1; i <= q; i++){
if(ans[i] == -1) printf("INFINITY\n");
else printf("%lld\n", ans[i]);
}
return 0;
}

2016-2017 ACM-ICPC Northeastern European Regional Contest Problem E. Expect to Wait的更多相关文章

  1. ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbilisi, November 24, 2010

    ACM ICPC 2010–2011, Northeastern European Regional Contest St Petersburg – Barnaul – Tashkent – Tbil ...

  2. ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków

    ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...

  3. 2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17)

    2017-2018 ACM-ICPC Northern Eurasia (Northeastern European Regional) Contest (NEERC 17) A 题意:有 n 个时刻 ...

  4. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)G GCD Guessing Game

    G: 要你去才Paul的年龄,Paul的年龄在1~n之间,你每猜一个Paul会告诉你,你猜的这个数和他年龄的gcd,问在最坏情况下最少要猜多少次. 题解: 什么是最坏情况,我们直到如果他的年龄是1的话 ...

  5. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)E Eve

    E: 模拟题,一开始有n个人(有男有女),对于子女来说线粒体DNA是继承母亲的.然后有m个操作(按时间顺序),一种就是给了父亲,母亲的ID,生了一个孩子(编号从n+1开始往下):还有一个就是 -x , ...

  6. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)K Kingdom Roadmap

    K: 给你n个点以及n-1的条边, 问你最少要加多少条边,使得每两个点割去一条联通的边,还可以使的这两个点连通. 有个一个结论,最少添加的边数为(叶子节点数+1)/ 2. 我们可以只考虑叶子节点数应该 ...

  7. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)B Binary Encoding

    B: 现在有一种新的2进制表示法,要你求出0~m-1的每个数的表示. 规则如下:n 是满足 m<=2n 最小数. 而0~m-1的数只能够用n-1个位和n个位来表示. 对于n个位表示的数来说不能有 ...

  8. ACM ICPC 2011-2012 Northeastern European Regional Contest(NEERC)A ASCII Area

    A: 给你一个矩阵求'/' 和 '\' 围成的图形,简单签到题,有一些细节要考虑. 题解:一行一行的跑,遇到'/'和'\' 就加0.5, 在面积里面的'.' 就加1.用一个flag来判断是否在围住的图 ...

  9. Gym 2009-2010 ACM ICPC Southwestern European Regional Programming Contest (SWERC 2009) A. Trick or Treat (三分)

    题意:在二维坐标轴上给你一堆点,在x轴上找一个点,使得该点到其他点的最大距离最小. 题解:随便找几个点画个图,不难发现,答案具有凹凸性,有极小值,所以我们直接三分来找即可. 代码: int n; lo ...

随机推荐

  1. es6 入坑笔记(五)

    Symbol 主要用做key或私有变量,Symbol是唯一的不可重复的,也是一个单独的数据类型 定义形式: let demo=Symbol("aaaa"); 1.Symbol不能使 ...

  2. vue数组赋值

    在使用vue开发移动端项目过程中,统一数组在对多个变量赋值时:希望一个数组的改变不影响另外一个数组,此时可以使用如下方式实现: let arr = [] let a1 = JSON.parse(JSO ...

  3. 浅谈es5和es6中的继承

    首先给大家介绍下在es5中构造函数的继承 function A(){ 2 //构造函数A 3 this.name="我是A函数"; 4 } 5 6 A.prototype={ 7 ...

  4. Redis API的理解与使用

    目录 一.通用命令 二.数据结构与内部编码 三.单线程架构 一.通用命令 Redis有五种数据结构,它们是键值对中的值,对于键来说有一些通用的命令.Redis的全局通用命令有:keys,dbsize, ...

  5. C语言链栈

    链栈与链表结构相似 typedef int elemtype; typedef struct linkedStackNode{ elemtype e; struct linkedStackNode * ...

  6. Debian使用dpkg安装MySQL

    说明 本文写于2017-10-03,使用MySQL 5.7,操作系统为64位 Debian GNU/Linux 8.6 (jessie). 安装 因apt仓库将mysql相关的包移除,需要自己去官网下 ...

  7. uni-app 下拉至指定高度固定view

    uni.createSelectorQuery().select(‘#salyt’).boundingClientRect(function(rects){ console.log(rects) va ...

  8. 1130: [POI2008]POD Subdivision of Kingdom

    1130: [POI2008]POD Subdivision of Kingdom https://lydsy.com/JudgeOnline/problem.php?id=1130 分析: 有效状态 ...

  9. 变态的iis10

    IIS10发布网站不能使用.NET4.0需要重新注册在之前版本的系统中使用如下命令可以直接重新注册: 但是windowsServer2016(iis 10) 使用该命令 提示 版本不支持 C:\WIN ...

  10. Drupal8 使用模块的配置文件

    D8中移除了variable表及相关方法 (variable_get(),variable_set()等) .用config表取代了. 新的方法该如何使用? 以D8的Youtube模块为例 配置文件要 ...