結果
問題 | No.1687 What the Heck? |
ユーザー |
![]() |
提出日時 | 2024-06-11 13:13:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 835 bytes |
コンパイル時間 | 2,232 ms |
コンパイル使用メモリ | 200,368 KB |
最終ジャッジ日時 | 2025-02-21 21:05:04 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 14 WA * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n; cin >> n; vector<int> p(n); for (int i = 0; i < n; i++) { cin >> p[i]; } set<int> unused; for (int i = 1; i <= n; i++) { unused.insert(i); } long long ans = 0; for (int i = n - 1; i >= 0; i--) { auto it = unused.lower_bound(p[i] + 1); if (it == unused.end()) { auto it_prev = prev(it); if (*it_prev == p[i]) { unused.erase(it_prev); } else { unused.erase(unused.begin()); ans -= i + 1; } } else { ans += i + 1; unused.erase(it); } } cout << ans << endl; }