結果

問題 No.1526 Sum of Mex 2
ユーザー square1001square1001
提出日時 2021-05-31 20:32:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,040 ms / 3,000 ms
コード長 1,004 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 79,416 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-04-26 09:37:56
合計ジャッジ時間 3,457 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 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 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 6 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 7 ms
5,376 KB
testcase_16 AC 23 ms
8,064 KB
testcase_17 AC 17 ms
6,656 KB
testcase_18 AC 3 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 11 ms
5,376 KB
testcase_21 AC 23 ms
7,936 KB
testcase_22 AC 15 ms
6,144 KB
testcase_23 AC 24 ms
7,936 KB
testcase_24 AC 24 ms
8,192 KB
testcase_25 AC 30 ms
7,936 KB
testcase_26 AC 26 ms
8,192 KB
testcase_27 AC 25 ms
8,320 KB
testcase_28 AC 24 ms
8,064 KB
testcase_29 AC 23 ms
8,320 KB
testcase_30 AC 25 ms
8,448 KB
testcase_31 AC 23 ms
8,404 KB
testcase_32 AC 23 ms
8,192 KB
testcase_33 AC 1,040 ms
7,720 KB
evil_largest RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int inc[102400];
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);
	}
	for(int i = 0; i < N; ++i) {
		inc[i] = i;
	}
	long long ans = 1LL * N * (N + 1) / 2;
	long long cursum = 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) {
				if(inc[k] < t) {
					cursum += t - inc[k];
					inc[k] = t;
				}
				else break;
			}
			ini = t + 1;
		}
		for(int j = ini; j < N; ++j) {
			if(inc[j] < N) {
				cursum += N - inc[j];
				inc[j] = N;
			}
			else break;
		}
		ans += 1LL * N * N - cursum;
	}
	cout << ans << endl;
	return 0;
}
0