結果
問題 | No.742 にゃんにゃんにゃん 猫の挨拶 |
ユーザー |
|
提出日時 | 2018-11-04 15:30:14 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 9 ms / 2,500 ms |
コード長 | 690 bytes |
コンパイル時間 | 1,636 ms |
コンパイル使用メモリ | 161,520 KB |
実行使用メモリ | 11,040 KB |
最終ジャッジ日時 | 2024-11-20 19:57:20 |
合計ジャッジ時間 | 2,253 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 16 |
ソースコード
#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;}