Codeforces D. Array Division】的更多相关文章

题目链接:http://codeforces.com/contest/808/problem/D 题意: 这一题给你一个数组,你可以调换某一个数的位置,使得这个数组可以分成2半,前半段的和等于后半段(严格的前半段和后半段).问你能不能构成. 题解: 一开始读题的时候,被吓坏了,没有看到是移动一个,因为题目在output那里才有写是移动一个. 那么如果这个和是奇数的话,就无法分成2个相等的部分.则是NO. 如果这个数列里有一个数是sum/2的话也是YES. 如果是移动一个数,那么这个数一定在某一个…
题目大意 给定你一个长为\(n\)的序列,问能否在最多一次取出某一元素然后插入到某一点后可以将整个序列分成两段使得其两段的元素之和相同. \(n \leq 10^5\) 题解 发现插入操作实际上是让某一个元素与端点周围的元素交换. 维护一个支持插入和查找元素是否存在的ds即可. #include <set> #include <cstdio> #include <cstring> #include <algorithm> using namespace st…
D. Array Division time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecuti…
D. Array Division time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecuti…
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the seco…
题目链接:http://codeforces.com/contest/808/problem/D 题意:有一串长度为n的数组,要求选择一个数字交换它的位置使得这串数能够分成两串连续的和一样的数组. 这个数还可以和自己交换位置. 题解:很显然求一下前缀二分每个数看一下能否插入,再求一下后缀二分每个数看一下能否插入. #include <iostream> #include <cstring> #include <cstdio> #include <algorithm…
传送门 题意 将n个数划分为两块,最多改变一个数的位置, 问能否使两块和相等 分析 因为我们最多只能移动一个数x,那么要么将该数往前移动,要么往后移动,一开始处理不需要移动的情况 那么遍历sum[i] 如果往前移动,sum[k]+(sum[i]-sum[i-1])=sum[n]/2,k∈[1,i-1] 如果往后移动,sum[k]-(sum[i]-sum[i-1])=sum[n]/2,k∈[i+1,n] 一开始我没有考虑往后移动 时间复杂度\(O(nlog(n))\) trick 代码 #incl…
E. Array Queries 题目链接:http://codeforces.com/problemset/problem/797/E time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output a is an array of n positive integers, all of which are not greater than…
Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between easy and hard versions is a number of elements in the array. You are given an array \(a\) consisting of \(n\) integers. The value of the \(i\)-th element…
You are given an array a1,a2,…,ana1,a2,…,an and an integer kk. You are asked to divide this array into kk non-empty consecutive subarrays. Every element in the array should be included in exactly one subarray. Let f(i)f(i) be the index of subarray th…