結果
| 問題 |
No.694 square1001 and Permutation 3
|
| コンテスト | |
| ユーザー |
どらら
|
| 提出日時 | 2018-06-08 23:27:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,337 bytes |
| コンパイル時間 | 1,875 ms |
| コンパイル使用メモリ | 178,952 KB |
| 実行使用メモリ | 55,252 KB |
| 最終ジャッジ日時 | 2024-06-30 11:07:57 |
| 合計ジャッジ時間 | 10,672 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 2 WA * 5 RE * 6 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;
struct FenwickTree{
static const int SIZE = 1<<17;
int n, tree[SIZE+1];
public:
FenwickTree(int n_){
n = n_;
for(int i=0; i<n+1; i++) tree[i] = 0;
}
void add(int i, int value){
for(; i<n; i|=i+1) tree[i] += value;
}
int sum(int i){
int s = 0;
for(; i>=0; i=(i&i+1)-1) s += tree[i];
return s;
}
};
int main(){
int N;
cin >> N;
vector<int> A;
map<int,int> mm, mp;
rep(i,N){
int a;
cin >> a;
A.push_back(a);
if(mm.count(a) == 0){
mm[a] = 1;
}
}
int cnt = 0;
FOR(it,mm){
mp[it->first] = cnt++;
}
vector<int> B;
rep(i,N){
B.push_back(mp[A[i]]);
}
FenwickTree ft(N+10);
ll sum = N * (ll)(N-1) / 2LL;
ll ret = 0;
rep(j,N){
int tmp = ft.sum(B[j]);
ret -= tmp;
ft.add(B[j], 1);
}
cout << sum + ret << endl;
rep(j,N-1){
ft.add(B[j], -1);
ll tmp1 = ft.sum(B[j]);
ll tmp2 = ft.sum(N+5) - ft.sum(B[j]);
ret += tmp2 - tmp1;
cout << sum + ret << endl;
ft.add(B[j], 1);
}
return 0;
}
どらら