結果

問題 No.1526 Sum of Mex 2
ユーザー square1001square1001
提出日時 2021-05-31 20:20:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,158 ms / 3,000 ms
コード長 989 bytes
コンパイル時間 802 ms
コンパイル使用メモリ 80,516 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-04-26 08:16:20
合計ジャッジ時間 15,061 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 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 2 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 24 ms
5,376 KB
testcase_14 AC 29 ms
5,376 KB
testcase_15 AC 46 ms
5,376 KB
testcase_16 AC 796 ms
8,152 KB
testcase_17 AC 399 ms
6,784 KB
testcase_18 AC 8 ms
5,376 KB
testcase_19 AC 6 ms
5,376 KB
testcase_20 AC 172 ms
5,504 KB
testcase_21 AC 729 ms
7,808 KB
testcase_22 AC 273 ms
6,144 KB
testcase_23 AC 768 ms
7,936 KB
testcase_24 AC 853 ms
8,192 KB
testcase_25 AC 753 ms
7,936 KB
testcase_26 AC 802 ms
7,936 KB
testcase_27 AC 843 ms
8,320 KB
testcase_28 AC 869 ms
8,320 KB
testcase_29 AC 833 ms
8,064 KB
testcase_30 AC 879 ms
8,448 KB
testcase_31 AC 879 ms
8,320 KB
testcase_32 AC 781 ms
8,064 KB
testcase_33 AC 2,158 ms
7,596 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;
			}
		}
		ans += 1LL * N * N - cursum;
	}
	cout << ans << endl;
	return 0;
}
0