結果

問題 No.742 にゃんにゃんにゃん 猫の挨拶
ユーザー satou_a_mansatou_a_man
提出日時 2018-11-04 15:30:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 2,500 ms
コード長 690 bytes
コンパイル時間 2,682 ms
コンパイル使用メモリ 146,952 KB
実行使用メモリ 11,248 KB
最終ジャッジ日時 2023-08-13 03:20:52
合計ジャッジ時間 2,263 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,720 KB
testcase_01 AC 5 ms
10,536 KB
testcase_02 AC 4 ms
10,588 KB
testcase_03 AC 5 ms
10,624 KB
testcase_04 AC 5 ms
10,844 KB
testcase_05 AC 5 ms
10,576 KB
testcase_06 AC 5 ms
10,652 KB
testcase_07 AC 5 ms
10,764 KB
testcase_08 AC 5 ms
10,824 KB
testcase_09 AC 4 ms
10,824 KB
testcase_10 AC 5 ms
10,656 KB
testcase_11 AC 9 ms
11,248 KB
testcase_12 AC 10 ms
11,128 KB
testcase_13 AC 5 ms
10,784 KB
testcase_14 AC 5 ms
10,768 KB
testcase_15 AC 5 ms
10,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

const int SZ = 1000000;
vector<ll> BIT(SZ+1);
ll sum(int a) {
  ll ans=0;
  while(a) {
    ans+=BIT[a];
    a-=a&-a;
  }
  return ans;
}
ll sum(int a,int b) {
  return sum(b)-sum(a-1);
}

void add(int a,int x) {
  while(a<=SZ) {
    BIT[a]+=x;
    a+=a&-a;
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  cin>>n;
  vector<int> m(n);
  rep(i,n)cin>>m[i];
  ll ans=0;
  rep(i,n) {
    ans+=sum(m[i],n);
    add(m[i],1);
  }
  cout << ans << endl;
  return 0;
}
0