codeforce 962A Equator

本文介绍了一个编程竞赛训练计划,该计划包含了解决特定数量题目来庆祝训练进度过半的算法实现。通过输入训练天数及每天解决问题的数量,算法确定了庆祝过半点的具体日期。

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

A. Equator
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp has created his own training plan to prepare for the programming contests. He will train for nn days, all days are numbered from 11to nn, beginning from the first.

On the ii-th day Polycarp will necessarily solve aiai problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.

Determine the index of day when Polycarp will celebrate the equator.

Input

The first line contains a single integer nn (1n2000001≤n≤200000) — the number of days to prepare for the programming contests.

The second line contains a sequence a1,a2,,ana1,a2,…,an (1ai100001≤ai≤10000), where aiai equals to the number of problems, which Polycarp will solve on the ii-th day.

Output

Print the index of the day when Polycarp will celebrate the equator.

Examples
input
Copy
4
1 3 2 1
output
Copy
2
input
Copy
6
2 2 2 2 2 2
output
Copy
3
Note

In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve 44out of 77 scheduled problems on four days of the training.

In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve 66out of 1212 scheduled problems on six days of the training.


注意结果的奇偶即可;

下面附上我的代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL; 
const int MAXN = 2e5 + 5;
int a[MAXN];
LL sum[MAXN];
int main()
{
	int n;
	LL sum1 = 0;
	cin>>n;
	for(int i = 1; i <= n; i++)
	{
		scanf("%d",&a[i]);
		sum[i] = sum[i-1] + a[i];
		sum1 += a[i];
	}
	int u = -1;
	if(sum1 & 1)
		sum1++;
	for(int i = 1; i <= n; i++)
		if(sum[i] >= sum1 / 2)
		{
			u = i;
			break;	
		}
	printf("%d\n",u);
	return 0;
}


03-30
### Swish-Gated Linear Unit (SwiGLU) 的定义 Swish-Gated Linear Unit (SwiGLU) 是一种结合了门控机制和激活函数的神经网络组件,广泛应用于自然语言处理和其他深度学习领域。它通过引入非线性和自适应加权的方式增强了模型表达能力[^4]。 具体来说,SwiGLU 可以被看作是一种特殊的门控单元形式,其中输入经过两个分支路径:一条路径应用 Swish 激活函数作为门控信号,另一条保持原始输入不变。最终输出由这两个分支的结果相乘得到: \[ \text{SwiGLU}(x) = (\sigma(W_s \cdot x + b_s) \odot W_g \cdot x + b_g) \] 在这里: - \(W_s\) 和 \(b_s\) 表示用于计算门控信号的权重矩阵和偏置项; - \(W_g\) 和 \(b_g\) 则表示用于缩放输入的权重矩阵和偏置项; - \(\sigma(x)\) 表示标准 Sigmoid 函数或其变种(如 Swish); - \(\odot\) 表示逐元素乘法操作。 这种设计允许模型动态调整不同特征的重要性,从而提升复杂模式的学习效率[^5]。 --- ### 实现细节 以下是基于 PyTorch 的 SwiGLU 实现代码片段: ```python import torch import torch.nn as nn class SwiGLU(nn.Module): def __init__(self, input_dim, output_dim): super(SwiGLU, self).__init__() self.linear_gate = nn.Linear(input_dim, output_dim) self.linear_main = nn.Linear(input_dim, output_dim) def forward(self, x): gate = torch.sigmoid(self.linear_gate(x)) # Gate signal using sigmoid/Swish main = self.linear_main(x) # Main transformation path return gate * main # Element-wise multiplication ``` 上述实现中,`linear_gate` 负责生成门控信号,而 `linear_main` 处理主要的数据流转换部分。两者的输出随后通过逐元素乘法组合在一起形成最终结果[^6]。 需要注意的是,在实际部署过程中可以根据需求替换掉默认的 Sigmoid 函数为其他更高效的替代品比如 SiLU 或 GELU 来进一步优化性能表现[^7]。 --- ### 使用场景 由于具备较强的灵活性以及良好的梯度传播特性,SwiGLU 特别适合于以下几种情况下的建模工作: 1. **序列建模**: 如 Transformer 架构中的前馈网络模块可以采用 SwiGLU 替代传统 ReLU/GeLU 层次结构来增强局部依赖关系捕捉能力。 2. **低资源环境**: 类似于预训练嵌入未能显著改善整体效果的小型数据集情境下,适当加入此类复杂的非线性变换有助于挖掘潜在规律[^8]。 3. **多任务联合训练框架内**, 当存在多个子任务共享底层表征空间时,利用 SwiGLU 提供额外自由度可以帮助平衡各目标间冲突并促进知识迁移过程顺利开展. ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值