CodeForces Round #521 (Div.3) C. Good Array

http://codeforces.com/contest/1077/problem/C

Let‘s call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array a=[1,3,3,7]a=[1,3,3,7] is good because there is the element a4=7a4=7 which equals to the sum 1+3+31+3+3.

You are given an array aa consisting of nn integers. Your task is to print all indices jj of this array such that after removing the jj-th element from the array it will be good (let‘s call such indices nice).

For example, if a=[8,3,5,2]a=[8,3,5,2], the nice indices are 11 and 44:

  • if you remove a1a1, the array will look like [3,5,2][3,5,2] and it is good;
  • if you remove a4a4, the array will look like [8,3,5][8,3,5] and it is good.

You have to consider all removals independently, i.?e. remove the element, check if the resulting array is good, and return the element into the array.

Input

The first line of the input contains one integer nn (2≤n≤2?1052≤n≤2?105) — the number of elements in the array aa.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106) — elements of the array aa.

Output

In the first line print one integer kk — the number of indices jj of the array aa such that after removing the jj-th element from the array it will be good (i.e. print the number of the nice indices).

In the second line print kk distinct integers j1,j2,…,jkj1,j2,…,jk in any order — nice indices of the array aa.

If there are no such indices in the array aa, just print 00 in the first line and leave the second line empty or do not print it at all.

Examples

input

Copy

5
2 5 1 2 2

output

Copy

3
4 1 5

input

Copy

4
8 3 5 2

output

Copy

2
1 4

input

Copy

5
2 1 2 4 3

output

Copy

0

代码:

#include <bits/stdc++.h>
using namespace std;

const int maxn = 2e5 + 10;
int n;
long long sum = 0;

struct Node{
    int pos;
    int val;
}node[maxn];

map<long long, int> mp;

int main() {
    scanf("%d", &n);
    mp.clear();
    for(int i = 1; i <= n; i ++) {
        int x;
        scanf("%d", &x);
        sum += x;
        node[i].pos = i;
        node[i].val = x;
        mp[x] ++;
    }

    vector<int> v;
    for(int i = 1; i <= n; i ++) {
        int temp = node[i].pos;
        mp[node[i].val] --;
        sum -= node[i].val;

        if(sum % 2 == 0 && mp[sum / 2])
            v.push_back(temp);

        sum += node[i].val;
        mp[node[i].val] ++;
    }

    printf("%d\n", v.size());
    for(int i = 0; i < v.size(); i ++) {
        printf("%d", v[i]);
        printf("%s", i != v.size() - 1 ? " " : "\n");
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/zlrrrr/p/9991164.html

时间: 2024-11-04 03:54:25

CodeForces Round #521 (Div.3) C. Good Array的相关文章

Codeforces Round #521 (Div. 3) D. Cutting Out 【二分+排序】

任意门:http://codeforces.com/contest/1077/problem/D D. Cutting Out time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array ss consisting of nn integers. You have to find any ar

Codeforces Round #521 (Div. 3)

题目链接:http://codeforces.com/contest/1077 A.Frog Jumping 解题思路: AC代码: 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 LL T,a,b,k;///差值相减即可 5 int main(){ 6 while(cin>>T){ 7 while(T--){ 8 cin>>a>>b>>k; 9

Codeforces Round #521 (Div. 3) D. Cutting Out

D. Cutting Out 题目链接:https://codeforces.com/contest/1077/problem/D 题意: 给你n个数,现在要你选k个数出来,并且能够从这n个数种选取尽量多的这k个数. 题解: 一开始想的贪心+模拟,然后写崩了... 其实这个题二分一下选几组就好了,因为要选几个数是固定了的,所以我们可以用二分来判断可行性(根据二分的x和每个数出现的次数来判断),即是否可以选够k个数,这个很容易办到. 然后最后统计一下每个数出现的个数,最后无脑选输出答案就行了. 代

Codeforces Round #210 (Div. 1)——Levko and Array

题目链接 题意: n.k,表示n个点,每个点有一个值,记c = max(abs(n[i] - n[i + 1])),要求只能将数组中的至多k个元素值改变(变成任意值),求c的最小值 分析: 可以二分一下c的值,求当前数组是否能改变至多k个数切c小于二分值.判断的话可以采用DP,dp[i]表示n[i]不改变时候,满足c <= 二分值时候需要改变的数字个数. 注意: DP的时候,dp[i] -> dp[j]时候,如果可以转移,那么直接dp[j] = min(dp[j], dp[i] + j - i

Codeforces Round #275 Div.1 B Interesting Array --线段树

题意: 构造一个序列,满足m个形如:[l,r,c] 的条件. [l,r,c]表示[l,r]中的元素按位与(&)的和为c. 解法: 线段树维护,sum[rt]表示要满足到现在为止的条件时该子树的按位与和至少为多少. 更新时,如果val的pos位为1,那么整个区间的按位与和pos位也应该为1,否则与出来就不对了.(这是本题解题的核心) 那么此时更新 sum[rt] |= val 即可.然后再check一遍看是否满足所有条件即可. 代码: #include <iostream> #inclu

Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)

题目链接:http://codeforces.com/contest/451/problem/B ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943/ma

Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Array

注意p的边界情况,p为0,或者 p为k 奇数+偶数 = 奇数 奇数+奇数 = 偶数 #include <iostream> #include <vector> #include <set> #include <algorithm> #include <cmath> using namespace std; int main(){ int n,k,p; long a; cin >> n >> k >> p; ve

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un

Codeforces Round #354 (Div. 2) ABCD

Codeforces Round #354 (Div. 2) Problems # Name     A Nicholas and Permutation standard input/output 1 s, 256 MB    x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB    x1462 C Vasya and String standard input/output 1 s, 256 MB    x1393 D T