Codeforces Round #478 C. Valhalla Siege
2 seconds
256 megabytes
standard input
standard output
Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle.
Ivar has nn warriors, he places them on a straight line in front of the main gate, in a way that the ii-th warrior stands right after(i−1)(i−1)-th warrior. The first warrior leads the attack.
Each attacker can take up to aiai arrows before he falls to the ground, where aiai is the ii-th warrior's strength.
Lagertha orders her warriors to shoot kiki arrows during the ii-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute tt, they will all be standing to fight at the end of minute tt.
The battle will last for qq minutes, after each minute you should tell Ivar what is the number of his standing warriors.
The first line contains two integers nn and qq (1≤n,q≤2000001≤n,q≤200000) — the number of warriors and the number of minutes in the battle.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) that represent the warriors' strengths.
The third line contains qq integers k1,k2,…,kqk1,k2,…,kq (1≤ki≤10141≤ki≤1014), the ii-th of them represents Lagertha's order at the ii-th minute: kiki arrows will attack the warriors.
Output qq lines, the ii-th of them is the number of standing warriors after the ii-th minute.
5 5
1 2 1 2 1
3 10 1 1 1
3
5
4
4
3
4 4
1 2 3 4
9 1 10 6
1
4
4
1
In the first example:
- after the 1-st minute, the 1-st and 2-nd warriors die.
- after the 2-nd minute all warriors die (and all arrows left over are wasted), then they will be revived thus answer is 5 — all warriors are alive.
- after the 3-rd minute, the 1-st warrior dies.
- after the 4-th minute, the 2-nd warrior takes a hit and his strength decreases by 1.
- after the 5-th minute, the 2-nd warrior dies.
这题其实就是一个前缀和二分查找。
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
const int maxn = 2e5 + ;
long long a[maxn], b[maxn], sum[maxn], sum1[maxn];
int main() {
long long n, q;
while(scanf("%lld%lld", &n, &q) != EOF) {
sum[] = ;
for (long long i = ; i <= n ; i++) {
scanf("%lld", &a[i]);
sum[i] = sum[i - ] + a[i];
}
for (long long i = ; i <= q ; i++) {
scanf("%lld", &b[i]);
}
long long temp = , cnt, ret = ;
for (long long i = ; i <= q ; i++) {
cnt = upper_bound(sum + , sum + n + , sum[temp] + b[i] + ret) - sum - ;
ret = a[cnt + ] - (sum[cnt + ] - sum[temp] - b[i] - ret);
if (ret == a[cnt + ]) ret = ;
temp = cnt;
if (temp == n ) {
temp = ;
ret = ;
}
printf("%lld\n", n - temp);
}
}
return ;
}
Codeforces Round #478 C. Valhalla Siege的更多相关文章
- Codeforces Round #478 (Div. 2)
题目链接:http://codeforces.com/contest/975 A. Aramic script time limit per test:1 second memory limit pe ...
- Codeforces Round #478 (Div. 2) ABCDE
A. Aramic script time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #478 Div2 975A 975B 975C 975D
A. Aramic script 题目大意: 对于每个单词,定义一种集合,这个集合包含且仅包含单词中出现的字母.给你一堆单词,问有多少种这种集合. 题解: 状压,插入set,取size #in ...
- 【map离散&容斥】Ghosts @Codeforces Round #478 (Div. 2) D
传送门 题意:给你一条直线的斜率a和截距b,和某一时刻n个在直线上的点的横坐标,以及沿坐标轴方向的速度.问你这些点在(-∞,+∞)的时间内的碰撞次数. solution 设两个点在t时刻相碰,有: x ...
- 【推导】Codeforces Round #478 (Div. 2) D. Ghosts
题意:给你一条直线以及初始时刻这条直线上的一些人的坐标,以及他们的速度矢量.让你对每个人计算他在过去无限远到将来无限远的时间内会与多少人处于同一个点,然后对每个人的这个值求和. 列方程组:两个人i,j ...
- B. Mancala (Codeforces Round #478 (Div. 2))
#include <bits/stdc++.h> using namespace std; ; typedef long long ll; ll a[maxn]; ll b[maxn]; ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- C++ 指针初始化要注意的地方
1. 声明多个指针的时候: int* P1,P2; 如上所示,声明的是创建一个指针P1和一个int型的变量P2.而不是声明的两个指针. 对每个指针变量名,都需要使用一个*. 在C++中,int* 是一 ...
- Centos7下lamp环境搭建的小笔记
刚刚把校赛弄完,赛前在环境搭建上花了蛮多时间,也正好记一下笔记 0.首先更新源 清华大学开源镜像站的源 https://mirrors.tuna.tsinghua.edu.cn/help/centos ...
- Delphi中客户端获取数据库更新信息(更新条数)
1.SQL语句 from tb where xxx='XXX') //不存在,则插入数据 begin insert into tb(xxx) values('XXX') //这里自己定义,插入或更新都 ...
- sshd 防止暴力破解
- 签名的html
<b><a href="http://www.feiyuanxing.com" style="color:red">未来星开发团队--狒 ...
- 转MySQL详解--索引
写在前面:索引对查询的速度有着至关重要的影响,理解索引也是进行数据库性能调优的起点.考虑如下情况,假设数据库中一个表有10^6条记录,DBMS的页面大小为4K,并存储100条记录.如果没有索引,查询将 ...
- Windows扩展屏开发总结
本文来自网易云社区 作者:梁敏 一.多屏设置 在设置-系统-可以点击显示器1和2,可以进行单独设置: "使之成为我的主显示器"可以设置当前显示器是主屏:主屏的选择会决定整个虚拟屏幕 ...
- win10子系统Ubuntu18.04下安装图形界面
前提:windows 10 已经安装WSL(windows subsystem for linux),并能正确运行Bash. 要想使用Linux的图形用户界面通常有两种方法,一种是使用X-Window ...
- 游戏测试中遇到的奇葩bug(不断整理中...)
1:跨服组织战中,不同服务器相同组织ID的敌对玩家不能造成伤害. 2:节日活动24点开启,角色不下线自然过渡到活动开启,界面显示异常 3:前端请求数据之后,不管是否接收到后端返回的数据,只要玩家点击仙 ...
- 第四篇 Python循环
While 循环 For 循环