首页 > 其他分享 >[ABC166E] This Message Will Self-Destruct in 5s

[ABC166E] This Message Will Self-Destruct in 5s

时间:2023-06-09 10:11:35浏览次数:48  
标签:le int ABC166E Self long 5s include

This Message Will Self-Destruct in 5s の 传送门

Solution

首先看到

\(j-i=A_i+A_j\)

转换一下,\(i+a_i=j-a_j\)。

接下来,对于每一个 \(i\)(\(1\le i\le n\)),用一个 map 存 \(i - a_i\) 的数量。

最后枚举 \(i\)(\(1\le i\le n\)),每次将 \(ans\) 加上 \(i+a_i\) 在 map 里的数量。

Code

//#include "pch.h"
#include <iostream>
#include <map>
using namespace std;
#define int long long//int -> long long
const int N = 2e5 + 5;
int n, ans, a[N];
map<int, int> mp;
signed main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		++mp[i - a[i]];
	}
	for (int i = 1; i <= n; ++i) { ans += mp[i + a[i]]; }
	cout << ans;
	return 0;
}
//i+ai=j-aj

标签:le,int,ABC166E,Self,long,5s,include
From: https://www.cnblogs.com/StrayerTen/p/ABC166E.html

相关文章

  • 01.Self—attention
    self—attention自注意力机制一、输入在学习自注意力机制之前,我们学到的神经网络的输入都是一个向量,输出可能是一个数值或者是一个类别。1.举个例子。假设输入的向量是一排向量,而且输入的向量的数目是会改变的,最简单的输入长度会改变的向量就是文字处理,假设我们的输入是一个......
  • qt 一直提示找不到 libQt5Sql.so.5 库
    报错提示: 背景:1.在ubuntu下,编译了一套开源库,用的是qt5.92.但是qt5.9特别不好用,我换成了qt5.14.2,但是担心会不会报错,因为编译开源库用到的是qt5.9的库 编译工程1.一直报上面那个错2.其他错误倒没有 解决:1.参考原文链接2.我的修改:添加变量LD_LIBRARY_PATH......
  • ABB IGCT 5SHY3545L0020 可控硅 5SHY系列可控硅都有货
    ABBIGCT5SHY3545L0020可控硅5SHY系列可控硅都有货ABBIGCT5SHY3545L0020可控硅5SHY系列可控硅都有货 任何复杂SCADA系统设计的很大一部分都涉及匹配连接设备之间的协议和通信参数。大约有200个这样的实时用户层和应用程序协议。其中包括专有和非专有协议,其中一些协......
  • Self-Supervised Hypergraph Convolutional Networks for Session-based Recommendati
    目录概符号说明HypergraphLinegraphDHCNHypergraphChannelLineGraphChannelContrastiveLearning优化代码XiaX.,YinH.,YuJ.,WangQ.,CuiLandZhangX.Self-supervisedhypergraphconvolutionalnetworksforsession-basedrecommendation.AAAI,2021.概自监......
  • 使用WPF、OwinSelfHost和Swagger创建自托管的Web API
    在本篇博客中,我将介绍如何在WPF应用程序中使用OwinSelfHost和Swagger来创建自托管的WebAPI。我们将使用WPF作为我们的应用程序界面,OwinSelfHost来自托管我们的WebAPI,并使用Swagger来为我们的API生成文档。首先,确保你的计算机上已安装了以下组件:VisualStudio2017.NETFramew......
  • Self-Supervised Graph Co-Training for Session-based Recommendation
    目录概符号说明COTREC图的构建ItemViewEncodingSessionViewEncodingCo-TrainingContrastiveLearningDivergenceConstraint优化代码XiaX.,YinH.,YuJ.,ShaoY.andCuiL.Self-supervisedgraphco-trainingforsession-basedrecommendation.CIKM,2021.概自监......
  • QA|外部调用类方法总报错missing 1 required positional argument:'self'|UI自动化
    外部调用类方法总报错missing1requiredpositionalargument:'self' 原因:实例化这个类实例化错了,少了括号()解决:改成如下就可以了 参考学习:调用类方法时报错:missing1requiredpositionalargument:'self'-hehehe_wy7-博客园(cnblogs.com) ......
  • 论文阅读 | Learn from Others and Be Yourself in Heterogeneous Federated Learning
    在异构联邦学习中博采众长做自己代码:https://paperswithcode.com/paper/learn-from-others-and-be-yourself-in摘要联邦学习中有异质性问题和灾难性遗忘。首先,由于非I.I.D(相同独立分布)数据和异构体系结构,模型在其他领域的性能下降,并且与参与者模型之间存在通信障碍。其次,在局......
  • leetcode 728. Self Dividing Numbers
    Aself-dividingnumberisanumberthatisdivisiblebyeverydigititcontains.Forexample,128isaself-dividingnumberbecause128%1==0,128%2==0,and128%8==0.Also,aself-dividingnumberisnotallowedtocontainthedigitzero.Givenal......
  • Self-consistency Improves Chain of Thought Reasoning in Language Models 论文阅读
    ICLR2023原文地址1.MotivationChain-of-Thought(CoT)使LargeLanguageModels(LLMs)在复杂的推理任务中取得了令人鼓舞的结果。本文提出了一种新的解码策略——self-consistency,以取代贪婪解码。self-consistency利用了一种直觉,即一个复杂的推理问题通常允许多种不同的思维......