結果
問題 | No.2089 置換の符号 |
ユーザー | Nzt3 |
提出日時 | 2022-09-30 21:44:03 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 470 bytes |
コンパイル時間 | 2,141 ms |
コンパイル使用メモリ | 202,728 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-22 23:04:59 |
合計ジャッジ時間 | 3,085 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 33 |
ソースコード
#include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin>>N; vector<int>A(N); for(int &i:A)cin>>i; int bit[N+1]; fill(bit,bit+N+1,0); auto add=[&](int a){ for(;a<=N;a+=a&-a)++bit[a]; }; auto sum=[&](int a){ int ret=0; for(;a>0;a-=a&-a)ret+=bit[a]; return ret; }; int ans=0; for(int i=N-1;i>=0;i--){ ans+=sum(A[i]); add(A[i]); } cout<<(ans%2?-1:1)<<'\n'; }