結果

問題 No.694 square1001 and Permutation 3
ユーザー dnishdnish
提出日時 2018-06-08 23:35:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 963 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 92,128 KB
実行使用メモリ 44,140 KB
最終ジャッジ日時 2023-09-13 00:24:37
合計ジャッジ時間 7,014 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/iostream:39,
         次から読み込み:  main.cpp:6:
メンバ関数 ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]’ 内,
    inlined from ‘int main()’ at main.cpp:47:5:
/usr/local/gcc7/include/c++/12.2.0/ostream:202:25: 警告: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:32:8: 備考: ‘ans’ はここで定義されています
   32 |     ll ans;
      |        ^~~

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define p(s) cout<<(s)<<endl
#define REP(i,n,N) for(ll i=n;i<N;i++)
#define RREP(i,n,N) for(ll i=N-1;i>=n;i--)
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const ll inf=1e9+7;

ll n;
ll A[500010];
map<ll, ll> m;
set<ll> s;

int main(){
    cin>>n;
    ll ans;
    REP(i,0,n){
        cin>>A[i];
        if(A[i]==n){
           s.insert(i);
            ans = n-i-1;
        }
        m[A[i]]=i;
    }
    RREP(i,1,n){
        ll tmp = distance(s.lower_bound(m[i]), s.end());
        s.insert(m[i]);
        //p(tmp);
        ans += n - (m[i]+1) - tmp;
    }
    p(ans);
    REP(i,0,n-1){
        ans += n - A[i] - (A[i]-1);
        p(ans);
    }

    return 0;
}
0