結果

問題 No.121 傾向と対策:門松列(その2)
ユーザー t98slidert98slider
提出日時 2022-05-26 02:24:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 612 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 93,668 KB
最終ジャッジ日時 2024-04-27 04:07:12
合計ジャッジ時間 2,592 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:8:5: error: 'cin' was not declared in this scope
    8 |     cin>>n;
      |     ^~~
main.cpp:2:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
    1 | #include<atcoder/all>
  +++ |+#include <iostream>
    2 | #define all(v) v.begin(),v.end()
main.cpp:26:5: error: 'cout' was not declared in this scope
   26 |     cout<<ans<<'\n';
      |     ^~~~
main.cpp:26:5: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?

ソースコード

diff #

#include<atcoder/all>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;

int main(){
    ll n,ans=0,s=0;
    cin>>n;
    vector<ll> a(n),c,mul(n);
    for(auto &&v:a)cin>>v;
    c=a;
    sort(all(c));
    c.erase(unique(all(c)),c.end());
    atcoder::fenwick_tree<ll> L(n),R(n);
    for(auto &&v:a){
        v=lower_bound(all(c),v)-c.begin();
        R.add(v,1);
    }
    for(auto &&v:a){
        s-=mul[v];
        ans+=L.sum(0,v)*R.sum(0,v)+L.sum(v+1,n)*R.sum(v+1,n)-s; 
        R.add(v,-1);
        L.add(v,1);
        s+=mul[v]=L.sum(v,v+1)*R.sum(v,v+1);
    }
    cout<<ans<<'\n';
}
0