結果
問題 | No.1300 Sum of Inversions |
ユーザー | recososo |
提出日時 | 2020-11-27 22:16:40 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,954 bytes |
コンパイル時間 | 1,819 ms |
コンパイル使用メモリ | 178,404 KB |
実行使用メモリ | 31,308 KB |
最終ジャッジ日時 | 2023-10-01 06:26:33 |
合計ジャッジ時間 | 10,853 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 234 ms
24,780 KB |
testcase_04 | AC | 230 ms
24,144 KB |
testcase_05 | AC | 178 ms
20,348 KB |
testcase_06 | AC | 270 ms
27,340 KB |
testcase_07 | AC | 253 ms
26,432 KB |
testcase_08 | AC | 299 ms
28,580 KB |
testcase_09 | AC | 312 ms
28,528 KB |
testcase_10 | AC | 154 ms
17,552 KB |
testcase_11 | AC | 152 ms
17,844 KB |
testcase_12 | AC | 245 ms
24,052 KB |
testcase_13 | AC | 235 ms
23,628 KB |
testcase_14 | AC | 347 ms
30,692 KB |
testcase_15 | AC | 287 ms
28,400 KB |
testcase_16 | AC | 243 ms
25,120 KB |
testcase_17 | AC | 134 ms
16,924 KB |
testcase_18 | AC | 154 ms
19,160 KB |
testcase_19 | AC | 193 ms
21,784 KB |
testcase_20 | AC | 211 ms
22,320 KB |
testcase_21 | AC | 206 ms
22,304 KB |
testcase_22 | AC | 168 ms
20,428 KB |
testcase_23 | AC | 255 ms
27,320 KB |
testcase_24 | AC | 181 ms
21,004 KB |
testcase_25 | AC | 157 ms
18,608 KB |
testcase_26 | AC | 150 ms
18,240 KB |
testcase_27 | AC | 170 ms
20,272 KB |
testcase_28 | AC | 302 ms
29,136 KB |
testcase_29 | AC | 192 ms
22,060 KB |
testcase_30 | AC | 283 ms
28,276 KB |
testcase_31 | AC | 187 ms
20,720 KB |
testcase_32 | AC | 189 ms
21,188 KB |
testcase_33 | AC | 43 ms
17,120 KB |
testcase_34 | AC | 58 ms
17,292 KB |
testcase_35 | AC | 144 ms
31,220 KB |
testcase_36 | WA | - |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll INF=1LL<<60; const int inf=(1<<30)-1; const int mod=998244353; int dx[8]={1,0,-1,0,-1,-1,1,1}; int dy[8]={0,1,0,-1,-1,1,-1,1}; template< typename T > struct BIT { int N; int max_2beki; vector< T > data; // 初期化 1-indexedでデータを管理する 0で初期化 BIT(int size){ N = ++size; data.assign(N, 0); max_2beki = 1; while(max_2beki * 2 <= N) max_2beki *= 2; } // [0,k](閉区間)の総和 閉区間に注意! T sum(int k) { if(k < 0) return 0; // k<0のとき0を返す T ret = 0; for(++k; k > 0; k -= k & -k) ret += data[k]; return (ret); } // [l,r](閉区間)の総和 inline T sum(int l,int r){ return sum(r) - sum(l-1); } // 一点取得 更新はできないことに注意 inline T operator[](int k){ return sum(k) - sum(k-1); } // data[k] += x; void add(int k, T x) { for(++k; k < N; k += k & -k) data[k] += x; } // imos法 [l,r]にxを加算 void imos(int l,int r,T x){ add(l , x); add(r + 1 , -x); } // lower_bound sum(i)がval以上となる最小のi int lower_bound(T w){ if(w <= 0) return 0; int x = 0; for(int k = max_2beki; k > 0; k /= 2){ if(x+k <= N - 1 && data[x + k] < w){ w -= data[x + k]; x += k; } } return x; } // upper_bound sum(i)がvalより大きくなる最小のi int upper_bound(T w){ if(w < 0) return 0; int x = 0; for(int k = max_2beki; k > 0; k /= 2){ if(x+k <= N - 1 && data[x + k] <= w){ w -= data[x + k]; x += k; } } return x; } }; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n;cin >> n; vector<ll> a(n),sm(n+1); map<ll,vector<ll>> mp; REP(i,n){ cin >> a[i]; mp[a[i]].push_back(i); sm[i+1]=sm[i]+a[i]; } BIT<ll> c(n),d(n); ll ans=0; for(auto x:mp){ vector<ll> tmp=x.second; int ts=tmp.size(); vector<ll> rc(ts),rd(ts); REP(i,ts){ rc[i]=c.sum(tmp[i],n-1); rd[i]=d.sum(tmp[i],n-1)%mod; } REP(i,ts){ c.add(tmp[i],1); d.add(tmp[i],x.first); } REP(i,ts){ ll cc=tmp[i]-c.sum(tmp[i]-1); ll dd=(sm[tmp[i]]-d.sum(tmp[i]-1))%mod; (ans+=cc*rc[i]*x.first%mod)%=mod; (ans+=(cc*rd[i]%mod+rc[i]*dd%mod)%mod)%=mod; } } cout << ans << endl; }