結果

問題 No.2779 Don't make Pair
ユーザー shobonvipshobonvip
提出日時 2024-06-07 21:34:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 469 ms / 2,000 ms
コード長 1,874 bytes
コンパイル時間 4,194 ms
コンパイル使用メモリ 272,468 KB
実行使用メモリ 22,840 KB
最終ジャッジ日時 2024-06-07 21:35:14
合計ジャッジ時間 10,856 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 42 ms
5,376 KB
testcase_11 AC 14 ms
5,376 KB
testcase_12 AC 168 ms
12,288 KB
testcase_13 AC 191 ms
12,928 KB
testcase_14 AC 110 ms
9,472 KB
testcase_15 AC 317 ms
17,920 KB
testcase_16 AC 348 ms
18,944 KB
testcase_17 AC 216 ms
13,824 KB
testcase_18 AC 149 ms
11,424 KB
testcase_19 AC 248 ms
15,672 KB
testcase_20 AC 103 ms
9,344 KB
testcase_21 AC 451 ms
22,400 KB
testcase_22 AC 449 ms
22,528 KB
testcase_23 AC 469 ms
22,840 KB
testcase_24 AC 455 ms
22,528 KB
testcase_25 AC 456 ms
22,528 KB
testcase_26 AC 450 ms
22,528 KB
testcase_27 AC 457 ms
22,400 KB
testcase_28 AC 458 ms
22,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//* ATCODER
#include<atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
//*/

/* BOOST MULTIPRECISION
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
//*/

typedef long long ll;

#define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--)

template <typename T> bool chmin(T &a, const T &b) {
	if (a <= b) return false;
	a = b;
	return true;
}

template <typename T> bool chmax(T &a, const T &b) {
	if (a >= b) return false;
	a = b;
	return true;
}

template <typename T> T max(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]);
	return ret;
}

template <typename T> T min(vector<T> &a){
	assert(!a.empty());
	T ret = a[0];
	for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]);
	return ret;
}

template <typename T> T sum(vector<T> &a){
	T ret = 0;
	for (int i=0; i<(int)a.size(); i++) ret += a[i];
	return ret;
}

int main(){
	int n; cin >> n;
	vector<int> a(n);
	rep(i,0,n){
		cin >> a[i];
	}
	
	map<int,int> mp1;
	map<int,int> mp2;
	multiset<int> st1;
	multiset<int> st2;
	rep(i,0,n){
		if(mp2.find(a[i]) == mp2.end()){
			st2.insert(0);
		}
		st2.erase(st2.find(mp2[a[i]]));
		mp2[a[i]]++;
		st2.insert(mp2[a[i]]);
	}

	vector<int> ans;
	rep(i,0,n-1){
		if(mp1.find(a[i]) == mp1.end()){
			st1.insert(0);
		}
		if(mp2.find(a[i]) == mp2.end()){
			st2.insert(0);
		}
		st1.erase(st1.find(mp1[a[i]]));
		mp1[a[i]]++;
		st1.insert(mp1[a[i]]);
		st2.erase(st2.find(mp2[a[i]]));
		mp2[a[i]]--;
		st2.insert(mp2[a[i]]);

		auto itr1 = st1.end();
		auto itr2 = st2.end();
		itr1--;
		itr2--;
		if (max(*itr1, *itr2) == 1){
			ans.push_back(i+1);
		}
	}
	int m = ans.size();
	cout << m << '\n';
	for (int x: ans){
		cout << x << ' ';
	}
	cout << '\n';
}

0