結果

問題 No.1526 Sum of Mex 2
ユーザー square1001square1001
提出日時 2021-05-31 20:16:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 897 bytes
コンパイル時間 810 ms
コンパイル使用メモリ 81,416 KB
実行使用メモリ 15,136 KB
最終ジャッジ日時 2024-04-26 08:16:03
合計ジャッジ時間 6,256 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,312 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 146 ms
5,376 KB
testcase_14 AC 181 ms
5,376 KB
testcase_15 AC 297 ms
5,376 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
evil_largest -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; ++i) {
		cin >> A[i];
		--A[i];
	}
	vector<vector<int> > G(N);
	for(int i = 0; i < N; ++i) {
		G[A[i]].push_back(i);
	}
	vector<int> inc(N);
	for(int i = 0; i < N; ++i) {
		inc[i] = i;
	}
	long long ans = 1LL * N * (N + 1) / 2;
	for(int i = 0; i < N; ++i) {
		int ini = 0;
		for(int j = 0; j < int(G[i].size()); ++j) {
			int t = G[i][j];
			for(int k = ini; k < t; ++k) {
				inc[k] = max(inc[k], t);
			}
			ini = t + 1;
		}
		for(int j = ini; j < N; ++j) {
			inc[j] = max(inc[j], N);
		}
		ans += 1LL * N * N;
		for(int j = 0; j < N; ++j) {
			ans -= inc[j];
		}
	}
	cout << ans << endl;
	return 0;
}
0