結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー daleksprinterdaleksprinter
提出日時 2018-10-06 14:07:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,008 bytes
コンパイル時間 1,937 ms
コンパイル使用メモリ 166,856 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 18:03:22
合計ジャッジ時間 5,263 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In member function 'long long int fenwick::add(long long int, long long int)':
main.cpp:29:12: warning: control reaches end of non-void function [-Wreturn-type]
   29 |         add(i +(i & -i), x);
      |         ~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define int long long

void print(int n){ cout << n << endl; }
int input() {int t; cin >> t; return t;}
//main------------------------------------------------------------------------------------------

struct fenwick{
    vector<int> bit;
    int s;

    fenwick(int n){
        s = n;
        rep(i,0,n+1) bit.push_back(0);
    }

    int sum(int i){
        if(i < 1) return 0;
        return bit[i] + sum(i - (i & -i));
    }

    int add(int i, int x){
        if(i > s) return 0; 
        bit[i] += x;
        add(i +(i & -i), x);
    }


};

signed main(){
    
    fenwick bit = fenwick(100001);

    int n; cin >> n;
    vector<int> arr; rep(i,0,n) arr.push_back(input());

    int ans = 0;
    rep(i,0,n){
        ans += i - bit.sum(arr[i]);
        bit.add(arr[i], 1);
    }

    print(ans);


    
  
    



}   
0