結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー SugarDragon5SugarDragon5
提出日時 2018-10-05 21:57:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,500 ms
コード長 1,411 bytes
コンパイル時間 1,696 ms
コンパイル使用メモリ 164,796 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 17:58:29
合計ジャッジ時間 2,093 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 11 ms
5,376 KB
testcase_12 AC 10 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
using Pl=pair<ll,ll>;
using PPl=pair<ll,Pl>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
template<class T>
struct BIT{
    //0-indexed
    vector<T> data;
    BIT(int size){
        data.assign(size+1,0);
    }
    T sum(int k){
        //[0,k]
        T res=0;
        for(++k;k>0;k-=k&-k){
            res+=data[k];
        }
        return res;
    }
    T sum(int l,int r){
        //[l,r]
        return sum(r)-sum(l-1);
    }
    void add(int k,T x){
        for(++k;k<data.size();k+=k&-k){
            data[k]+=x;
        }
    }
};
int main(){
    int n;
    cin>>n;
    vi vec(n);
    REP(i,n){
        cin>>vec[i];
    }
    BIT<int> tr(n+1);
    int ans=0;
    REPR(i,n-1){
        ans+=tr.sum(vec[i]);
        tr.add(vec[i],1);
    }
    cout<<ans<<endl;
    return 0;
}
0