結果
問題 |
No.1687 What the Heck?
|
ユーザー |
![]() |
提出日時 | 2021-09-24 21:31:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 571 bytes |
コンパイル時間 | 2,347 ms |
コンパイル使用メモリ | 199,436 KB |
最終ジャッジ日時 | 2025-01-24 16:51:36 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 14 WA * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int>P(N); set<int>st; for(int i = 0; i < N; i++) { cin >> P[i]; st.insert(i+1); } long long sum = 0; for(int i = N-1; i >= 0; i--) { if(st.lower_bound(P[i]) == st.end()) { sum -= i+1; } else if(st.upper_bound(P[i]) != st.end()) { sum += i+1; st.erase(st.upper_bound(P[i])); } else { st.erase(st.find(P[i])); } } cout << sum << endl; }