結果

問題 No.694 square1001 and Permutation 3
ユーザー konsin_tokagekonsin_tokage
提出日時 2018-06-24 14:52:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,145 ms / 3,000 ms
コード長 713 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 76,732 KB
実行使用メモリ 27,088 KB
最終ジャッジ日時 2023-09-13 13:41:55
合計ジャッジ時間 12,474 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 4 ms
4,376 KB
testcase_07 AC 948 ms
11,276 KB
testcase_08 AC 1,145 ms
12,944 KB
testcase_09 AC 2,144 ms
27,088 KB
testcase_10 AC 925 ms
11,304 KB
testcase_11 AC 2,124 ms
26,900 KB
testcase_12 AC 2,145 ms
26,888 KB
testcase_13 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <unordered_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){
        unordered_map<int,int> c(n);
        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;
}
0