Codeforces Round #478 (Div. 2)-C. Valhalla Siege【二分】

本文介绍了一个勇士攻防模拟问题,勇士们依次排列承受连续多轮箭雨攻击,每轮攻击后统计站立勇士数量,若全体倒下则立刻满血复活继续战斗。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

C. Valhalla Siege

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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

Output qq lines, the ii-th of them is the number of standing warriors after the ii-th minute.

Examples

input

Copy

5 5
1 2 1 2 1
3 10 1 1 1

output

Copy

3
5
4
4
3

input

Copy

4 4
1 2 3 4
9 1 10 6

output

Copy

1
4
4
1

Note

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.

题意:有一列n个勇士,他们将会承受q分钟的箭击,第i个人承受值为a[i],第j分钟会有攻击值为k[j]的箭击,当第i个人受到大小为a[i]的箭击后将会倒下,该分钟剩余的攻击将会作用于倒下的人的后面的人身上,当某分钟所有人均倒下时,那么所有人将会在该分钟满血复活,而该分钟剩余的攻击值将会无效,即该分钟后所有人的承受值重新加满,都站着。求对于每分钟攻击后,有多少人存活。

题解:首先求a[i]的前缀和sum[ ],然后对于每分钟都仔细分析:对于当前分钟,根据上一分钟攻击到的位置pos及攻击到的勇士被消耗的值的大小xsu,做这一步的判断,并且更新pos与xsu;具体思路看代码。

 

代码如下:
 

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const ll maxn=200005;
ll a[maxn];
ll sum[maxn];
ll kil[maxn];
int main()
{
	ll n,q;
	scanf("%lld %lld",&n,&q);
	sum[0]=0;
	for(ll i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum[i]=sum[i-1]+a[i];//统计前缀和 
	}
	for(ll i=1;i<=q;i++){
		scanf("%lld",&kil[i]);
	}
	
	ll pos=1; 
	ll xsu=0;
	for(ll i=1;i<=q;i++){
		int f=pos;//上一轮攻击到的那个人的位置;xsu:代表那个人已经被消耗的值是多少 
		pos=lower_bound(sum,sum+n+1,kil[i]+sum[pos-1]+xsu)-sum;//此轮攻击到的位置 
		
		
		//根据此轮攻击到的位置,更新下轮要用到的pos值及xsu值,并输出此轮结果 
		if(pos==n+1){//此时攻击值已经把所有士兵击倒 ,并有剩余的攻击值 
			printf("%lld\n",n);
			xsu=0;
			pos=1;
		}else if(pos==n&&kil[i]+sum[f-1]+xsu==sum[n]){//此时攻击值刚好把所有勇士击倒 
			printf("%lld\n",n);
			xsu=0;
			pos=1;
		}else{
			if(sum[pos]==kil[i]+sum[f-1]+xsu){//此时攻击值刚好把一个勇士的承受值全部消灭 
				printf("%lld\n",n-pos);
				pos=pos+1;
				xsu=0;
			}else{//此时攻击值只减少了某个勇士的一部分承受值 
				printf("%lld\n",n-pos+1);
				xsu=(kil[i]+sum[f-1]+xsu)-sum[pos-1];
			}
		}
		
	}
	
	
	return 0;
 } 

 

资源下载链接为: https://pan.quark.cn/s/140386800631 通用大模型文本分类实践的基本原理是,借助大模型自身较强的理解和推理能力,在使用时需在prompt中明确分类任务目标,并详细解释每个类目概念,尤其要突出类目间的差别。 结合in-context learning思想,有效的prompt应包含分类任务介绍及细节、类目概念解释、每个类目对应的例子和待分类文本。但实际应用中,类目和样本较多易导致prompt过长,影响大模型推理效果,因此可先通过向量检索缩小范围,再由大模型做最终决策。 具体方案为:离线时提前配置好每个类目的概念及对应样本;在线时先对给定query进行向量召回,再将召回结果交给大模型决策。 该方法不更新任何模型参数,直接使用开源模型参数。其架构参考GPT-RE并结合相关实践改写,加入上下文学习以提高准确度,还使用BGE作为向量模型,K-BERT提取文本关键词,拼接召回的相似例子作为上下文输入大模型。 代码实现上,大模型用Qwen2-7B-Instruct,Embedding采用bge-base-zh-v1.5,向量库选择milvus。分类主函数的作用是在向量库中召回相似案例,拼接prompt后输入大模型。 结果方面,使用ICL时accuracy达0.94,比bert文本分类的0.98低0.04,错误类别6个,处理时添加“家居”类别,影响不大;不使用ICL时accuracy为0.88,错误58项,可能与未修改prompt有关。 优点是无需训练即可有较好结果,例子优质、类目界限清晰时效果更佳,适合围绕通用大模型api打造工具;缺点是上限不高,仅针对一个分类任务部署大模型不划算,推理速度慢,icl的token使用多,用收费api会有额外开销。 后续可优化的点是利用key-bert提取的关键词,因为核心词语有时比语意更重要。 参考资料包括
内容概要:本文详细介绍了哈希表及其相关概念和技术细节,包括哈希表的引入、哈希函数的设计、冲突处理机制、字符串哈希的基础、哈希错误率分析以及哈希的改进与应用。哈希表作为一种高效的数据结构,通过键值对存储数据,能够快速定位和检索。文中讨论了整数键值和字符串键值的哈希方法,特别是字符串哈希中的多项式哈希及其优化方法,如双哈希和子串哈希的快速计算。此外,还探讨了常见的冲突处理方法——拉链法和闭散列法,并提供了C++实现示例。最后,文章列举了哈希在字符串匹配、最长回文子串、最长公共子字符串等问题中的具体应用。 适合人群:计算机科学专业的学生、算法竞赛选手以及有一定编程基础并对数据结构和算法感兴趣的开发者。 使用场景及目标:①理解哈希表的工作原理及其在各种编程任务中的应用;②掌握哈希函数的设计原则,包括如何选择合适的模数和基数;③学会处理哈希冲突的方法,如拉链法和闭散列法;④了解并能运用字符串哈希解决实际问题,如字符串匹配、回文检测等。 阅读建议:由于哈希涉及较多数学知识和编程技巧,建议读者先熟悉基本的数据结构和算法理论,再结合代码实例进行深入理解。同时,在实践中不断尝试不同的哈希策略,对比性能差异,从而更好地掌握哈希技术。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值