結果
問題 |
No.694 square1001 and Permutation 3
|
ユーザー |
![]() |
提出日時 | 2018-06-24 14:38:31 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 690 bytes |
コンパイル時間 | 622 ms |
コンパイル使用メモリ | 72,088 KB |
実行使用メモリ | 36,736 KB |
最終ジャッジ日時 | 2024-06-30 22:30:01 |
合計ジャッジ時間 | 8,397 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 1 |
other | AC * 9 TLE * 1 -- * 3 |
ソースコード
#include <iostream> #include <algorithm> #include <map> using namespace std; int a[500000], b[500000]; int main(){ cin.tie(0), ios_base::sync_with_stdio(false); int n; cin >> n; for(int i=0; i<n; ++i) cin >> a[i]; long long r = 0; for(int i=29; i>=0; --i){ map<int,int> c; for(int j=0; j<n; ++j){ if(!(a[j]>>i&1)) r += c[a[j]>>i+1]; else c[a[j]>>i+1] += 1; } } for(int i=0; i<n; ++i) b[i] = a[i]; sort(b, b+n); for(int i=0; i<n; ++i){ cout << r << endl; int l = lower_bound(b, b+n, a[i]) - b; int u = upper_bound(b, b+n, a[i]) - b; r += (n-u) - l; } return 0; }