結果
問題 |
No.694 square1001 and Permutation 3
|
ユーザー |
![]() |
提出日時 | 2019-03-23 15:17:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,776 bytes |
コンパイル時間 | 2,024 ms |
コンパイル使用メモリ | 206,572 KB |
最終ジャッジ日時 | 2025-01-07 00:18:05 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 7 WA * 6 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} struct FastIO{ FastIO(){ cin.tie(0); ios::sync_with_stdio(0); } }fastio_beet; template<typename T> vector<T> compress(vector<T> v){ sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); return v; } template<typename T> map<T, int> dict(const vector<T> &v){ map<T, int> res; for(int i=0;i<(int)v.size();i++) res[v[i]]=i; return res; } template<typename T> struct BIT{ int n; vector<T> bit; //1-indexed BIT():n(-1){} BIT(int n_,T d):n(n_),bit(n_+1,d){} T sum(int i){ T s=bit[0]; for(int x=i;x>0;x-=(x&-x)) s+=bit[x]; return s; } void add(int i,T a){ if(i==0) return; for(int x=i;x<=n;x+=(x&-x)) bit[x]+=a; } int lower_bound(int w){ if(w<=0) return 0; int x=0,r=1; while(r<n) r<<=1; for(int k=r;k>0;k>>=1){ if(x+k<=n&&bit[x+k]<w){ w-=bit[x+k]; x+=k; } } return x+1; } T sum0(int i){ return sum(i+1); } void add0(int i,T a){ add(i+1,a); } T query(int l,int r){ return sum(r-1)-sum(l-1); } T query0(int l,int r){ return sum(r)-sum(l); } }; //INSERT ABOVE HERE signed main(){ int n; cin>>n; vector<int> a(n); for(int i=0;i<n;i++) cin>>a[i]; auto c=compress(a); auto d=dict(c); for(int &x:a) x=d[x]; BIT<int> bit(n,0); int cnt=0; for(int i=0;i<n;i++){ cnt+=i-bit.sum0(a[i]); bit.add0(a[i],1); } for(int i=0;i<n;i++){ cout<<cnt<<"\n"; cnt-=bit.sum0(a[i]-1); cnt+=n-bit.sum0(a[i]); } cout<<flush; return 0; }