結果
問題 |
No.1687 What the Heck?
|
ユーザー |
![]() |
提出日時 | 2021-09-24 21:23:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 666 bytes |
コンパイル時間 | 4,859 ms |
コンパイル使用メモリ | 255,712 KB |
最終ジャッジ日時 | 2025-01-24 16:44:25 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 14 WA * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:20:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 20 | scanf("%d",&p[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#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; }