結果
問題 | No.694 square1001 and Permutation 3 |
ユーザー | chocorusk |
提出日時 | 2019-03-18 23:03:55 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 905 ms / 3,000 ms |
コード長 | 1,088 bytes |
コンパイル時間 | 1,523 ms |
コンパイル使用メモリ | 81,360 KB |
実行使用メモリ | 36,780 KB |
最終ジャッジ日時 | 2023-09-26 13:01:27 |
合計ジャッジ時間 | 8,025 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
9,516 KB |
testcase_01 | AC | 4 ms
9,776 KB |
testcase_02 | AC | 3 ms
9,756 KB |
testcase_03 | AC | 4 ms
9,520 KB |
testcase_04 | AC | 3 ms
9,824 KB |
testcase_05 | AC | 4 ms
9,764 KB |
testcase_06 | AC | 4 ms
9,632 KB |
testcase_07 | AC | 125 ms
11,324 KB |
testcase_08 | AC | 425 ms
16,396 KB |
testcase_09 | AC | 846 ms
36,696 KB |
testcase_10 | AC | 97 ms
11,340 KB |
testcase_11 | AC | 881 ms
36,780 KB |
testcase_12 | AC | 905 ms
36,704 KB |
testcase_13 | AC | 3 ms
10,252 KB |
ソースコード
#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; }