結果

問題 No.1687 What the Heck?
ユーザー 沙耶花沙耶花
提出日時 2021-09-24 21:23:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 666 bytes
コンパイル時間 4,455 ms
コンパイル使用メモリ 264,396 KB
実行使用メモリ 13,328 KB
最終ジャッジ日時 2023-09-18 20:34:20
合計ジャッジ時間 6,990 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 50 ms
6,864 KB
testcase_08 AC 77 ms
8,160 KB
testcase_09 WA -
testcase_10 AC 30 ms
5,624 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 213 ms
13,160 KB
testcase_14 AC 208 ms
13,328 KB
testcase_15 AC 207 ms
13,232 KB
testcase_16 AC 200 ms
13,112 KB
testcase_17 AC 8 ms
4,380 KB
testcase_18 AC 213 ms
13,256 KB
testcase_19 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001



int main(){
	
	int n;
	cin>>n;
	
	vector<int> p(n);
	set<int> S;
	rep(i,n){
		scanf("%d",&p[i]);
		S.insert(i+1);
	}
	
	long long ans = 0LL;
	
	for(int i=n-1;i>=0;i--){
		auto it = S.upper_bound(p[i]);
		if(it!=S.end()){
			S.erase(it);
			ans += i+1;
		}
		else{
			it = S.lower_bound(p[i]);
			if(it!=S.end()){
				S.erase(it);
			}
			else{
				it = S.begin();
				S.erase(it);
				ans -= i+1;
			}
		}
	}
	
	cout<<ans<<endl;
		
	
	
	
	return 0;
}
0