結果
| 問題 |
No.694 square1001 and Permutation 3
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2019-03-18 23:03:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 911 ms / 3,000 ms |
| コード長 | 1,088 bytes |
| コンパイル時間 | 661 ms |
| コンパイル使用メモリ | 84,844 KB |
| 実行使用メモリ | 36,736 KB |
| 最終ジャッジ日時 | 2024-07-19 07:25:44 |
| 合計ジャッジ時間 | 7,656 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 13 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:42:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
42 | scanf("%d", &a1[i]);
| ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int bit[500001], t;
int sum(int i){
int s=0;
while(i>0){
s+=bit[i];
i-=(i&(-i));
}
return s;
}
void add(int i){
while(i<=t){
bit[i]+=1;
i+=(i&(-i));
}
}
int main()
{
int n;
cin>>n;
int a1[500000];
map<int, int> mp;
for(int i=0; i<n; i++){
scanf("%d", &a1[i]);
mp[a1[i]]=0;
}
t=1;
for(auto &p:mp){
p.second=t;
t++;
}
t--;
int a[500000];
for(int i=0; i<n; i++){
a[i]=mp[a1[i]];
}
ll ct[500001]={};
for(int i=0; i<n; i++){
ct[i+1]-=((ll)sum(a[i]-1));
ll s=i-sum(a[i]);
ct[i+1]+=s;
ct[0]+=s;
add(a[i]);
}
fill(bit, bit+t+1, 0);
for(int i=n-1; i>=0; i--){
ct[i+1]-=((ll)sum(a[i]-1));
ct[i+1]+=((ll)(n-1-i-sum(a[i])));
add(a[i]);
}
printf("%lld\n", ct[0]);
for(int i=1; i<n; i++){
ct[i]+=ct[i-1];
printf("%lld\n", ct[i]);
}
return 0;
}
chocorusk