CF 988C Equal Sums 思维 第九题 map
2 seconds
256 megabytes
standard input
standard output
You are given kk sequences of integers. The length of the ii-th sequence equals to nini.
You have to choose exactly two sequences ii and jj (i≠ji≠j) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence ii (its length will be equal to ni−1ni−1) equals to the sum of the changed sequence jj (its length will be equal to nj−1nj−1).
Note that it's required to remove exactly one element in each of the two chosen sequences.
Assume that the sum of the empty (of the length equals 00) sequence is 00.
The first line contains an integer kk (2≤k≤2⋅1052≤k≤2⋅105) — the number of sequences.
Then kk pairs of lines follow, each pair containing a sequence.
The first line in the ii-th pair contains one integer nini (1≤ni<2⋅1051≤ni<2⋅105) — the length of the ii-th sequence. The second line of the ii-th pair contains a sequence of nini integers ai,1,ai,2,…,ai,niai,1,ai,2,…,ai,ni.
The elements of sequences are integer numbers from −104−104 to 104104.
The sum of lengths of all given sequences don't exceed 2⋅1052⋅105, i.e. n1+n2+⋯+nk≤2⋅105n1+n2+⋯+nk≤2⋅105.
If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers ii, xx (1≤i≤k,1≤x≤ni1≤i≤k,1≤x≤ni), in the third line — two integers jj, yy (1≤j≤k,1≤y≤nj1≤j≤k,1≤y≤nj). It means that the sum of the elements of the ii-th sequence without the element with index xx equals to the sum of the elements of the jj-th sequence without the element with index yy.
Two chosen sequences must be distinct, i.e. i≠ji≠j. You can print them in any order.
If there are multiple possible answers, print any of them.
2
5
2 3 1 3 2
6
1 1 2 2 2 1
YES
2 6
1 2
3
1
5
5
1 1 1 1 1
2
2 3
NO
4
6
2 2 2 2 2 2
5
2 2 2 2 2
3
2 2 2
5
2 2 2 2 2
YES
2 2
4 1
In the first example there are two sequences [2,3,1,3,2][2,3,1,3,2] and [1,1,2,2,2,1][1,1,2,2,2,1]. You can remove the second element from the first sequence to get [2,1,3,2][2,1,3,2]
and you can remove the sixth element from the second sequence to get [1,1,2,2,2][1,1,2,2,2].The sums of the both resulting sequences equal to 88, i.e. the sums are equal.
题意: 给你k个数列(2<=k<=2*10^5),每个数列长度是n(n<=2*10^5),所有序列的总长度小于等于2*10^5,问是否有两个序列去掉序列其中一个值后两个序列序列和相等
用一个map存下每个序列去掉其中一个值后的剩余值及其的位置
然后遍历每个序列,看有没有一个序列去掉一个值后的剩余值被map记录,若有则输出这个值的位置及遍历到的值的位置,没有输出NO
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 1e6 + ;
const int mod = 1e9 + ;
typedef long long ll;
ll a[maxn];
int main(){
std::ios::sync_with_stdio(false);
ll T;
while( cin >> T ) {
ll flag = false;
map< ll, pair< ll, ll > > mm;
for( ll i = ; i <= T; i ++ ) {
ll n, sum = , t;
cin >> n;
for( ll j = ; j <= n; j ++ ) {
cin >> a[j];
sum += a[j];
}
for( ll j = ; j <= n; j ++ ) {
t = sum - a[j];
if( mm.count(t) && !flag && mm[t].first != i ) {
cout << "YES" << endl;
cout << i << " " << j << endl;
cout << mm[t].first << " " << mm[t].second << endl;
flag = true;
}
mm[t] = make_pair( i, j );
}
}
if( !flag ) {
cout << "NO" << endl;
}
}
return ;
}
CF 988C Equal Sums 思维 第九题 map的更多相关文章
- Equal Sums (map的基本应用) 多学骚操作
C. Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #486 (Div. 3)-C. Equal Sums
C. Equal Sums time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- 清橙A1206.小Z的袜子 && CF 86D(莫队两题)
清橙A1206.小Z的袜子 && CF 86D(莫队两题) 在网上看了一些别人写的关于莫队算法的介绍,我认为,莫队与其说是一种算法,不如说是一种思想,他通过先分块再排序来优化离线查询问 ...
- B君的第九题
B君的第九题 对于一个排列\(a_1, a_2,\dots,a_n\),如果对于一个i满足\(a_{i-1}<a_i>a_i+1\)则称i是一个极大值.我们认为\(a_0=a_{n+1}= ...
- [Gym101982M][思维好题][凸壳]Mobilization
[gym101982M][思维好题][凸壳]Mobilization 题目链接 20182019-acmicpc-pacific-northwest-regional-contest-div-1-en ...
- CF上的3道小题(2)
CF上的3道小题(2) T1:CF630K Indivisibility 题意:给出一个数n,求1到n的数中不能被2到9中任意一个数整除的数. 分析:容斥一下,没了. 代码: #include < ...
- CF上的3道小题(1)
CF上的3道小题 终于调完了啊.... T1:CF702E Analysis of Pathes in Functional Graph 题意:你获得了一个n个点有向图,每个点只有一条出边.第i个点的 ...
- 土题大战Vol.0 A. 笨小猴 思维好题
土题大战Vol.0 A. 笨小猴 思维好题 题目描述 驴蛋蛋有 \(2n + 1\) 张 \(4\) 星武器卡片,每张卡片上都有两个数字,第 \(i\) 张卡片上的两个数字分别是 \(A_i\) 与 ...
- CF思维联系– Codeforces-988C Equal Sums (哈希)
ACM思维题训练集合 You are given k sequences of integers. The length of the i-th sequence equals to ni. You ...
随机推荐
- MySQL 之 Explain 输出分析
MySQL 之 Explain 输出分析 背景 前面的文章写过 MySQL 的事务和锁,这篇文章我们来聊聊 MySQL 的 Explain,估计大家在工作或者面试中多多少少都会接触过这个.可能工作中 ...
- java支付宝app支付-代码实现
1.我们需要在支付宝商户平台配置好,取到四个参数如下(这是支付宝官方配置地址):https://www.cnblogs.com/fuzongle/p/10217144.html 合作身份者ID:123 ...
- python3学习-logging模块
1.logging模块的使用非常简单,引入模块就可以使用. import logging logging.debug('This is debug message') logging.info('Th ...
- ccf 201903-5 317号子任务(60分)
看到这题,第一印象,用dijkstra算法求n次单源最短路,时间复杂度O(n^3),超时30分妥妥的. 于是用优先队列优化,O(n*mlogm),快很多,但依然30. 那么不妨换一种思路,题目要求的是 ...
- Thread、ThreadPool、Task、Parallel、Async和Await基本用法、区别以及弊端
多线程的操作在程序中也是比较常见的,比如开启一个线程执行一些比较耗时的操作(IO操作),而主线程继续执行当前操作,不会造成主线程阻塞.线程又分为前台线程和后台线程,区别是:整个程序必须要运行完前台线程 ...
- Flink 源码解析 —— 深度解析 Flink 是如何管理好内存的?
前言 如今,许多用于分析大型数据集的开源系统都是用 Java 或者是基于 JVM 的编程语言实现的.最着名的例子是 Apache Hadoop,还有较新的框架,如 Apache Spark.Apach ...
- Windows下的bat原来可以为我们做很多
用了windows系统这么多年了,对bat也不是很了解.最近研究了一下bat的用法.这里就大概列举一下自己的用法 参考网址 基本命令 echo echo我们可以理解成程序中的输出,和我们Java的Sy ...
- git:将代码提交到远程仓库(码云)
初始化 进入一个任意的文件夹(如D:\aqin_test1\) git init # 初始化,让git将这个文件夹管理起来 git add . # 收集此文件夹下的所有文件 git config -- ...
- 网编(小白心得osi七层协议)
目录 1 C/S B/S架构 2网络通信原理 3osi七层协议 数据链路层 网络层 传输层 应用层 1 C/S B/S架构 C:client端(客户端) B:browse 浏览器 S: s ...
- Spring源码剖析5:JDK和cglib动态代理原理详解
AOP的基础是Java动态代理,了解和使用两种动态代理能让我们更好地理解 AOP,在讲解AOP之前,让我们先来看看Java动态代理的使用方式以及底层实现原理. 转自https://www.jiansh ...