結果
問題 |
No.1687 What the Heck?
|
ユーザー |
![]() |
提出日時 | 2021-09-24 21:28:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 509 bytes |
コンパイル時間 | 2,292 ms |
コンパイル使用メモリ | 198,072 KB |
最終ジャッジ日時 | 2025-01-24 16:48:21 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 3 WA * 15 |
ソースコード
#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])); } } cout << sum << endl; }