結果

問題 No.2250 Split Permutation
ユーザー bayashikobayashiko
提出日時 2023-05-31 22:09:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,098 bytes
コンパイル時間 5,458 ms
コンパイル使用メモリ 280,820 KB
実行使用メモリ 16,224 KB
最終ジャッジ日時 2023-08-28 01:39:02
合計ジャッジ時間 9,827 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
12,796 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 11 ms
12,976 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 11 ms
12,928 KB
testcase_16 AC 10 ms
13,016 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
//#include<unistd.h>
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
//#define INF (1<<30)
#define LINF (lint)(1LL<<62)
#define MINF (lint)(2e18)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
//#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
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;}
//vector<int> bucket[MAX_N/1000];
//constexpr int MOD=1000000007;
constexpr int MOD=998244353;
#include<atcoder/all>
using namespace atcoder;
typedef __int128_t llint;

lint op(lint a,lint b){
    return a+b;
}
lint e(){
    return 0;
}
lint calc(int N,vector<lint> A){
    segtree<lint,op,e> seg_dist(200001),seg_cnt(200001);
    lint ret=0;
    rep(i,N){
        lint plus_coef=seg_dist.prod(0,A[i])-seg_cnt.prod(0,A[i])*(N-1-i);
        ret+=plus_coef*A[i];
        lint minus_coef=seg_dist.prod(A[i]+1,200001)-seg_cnt.prod(A[i]+1,200001)*(N-1-i);
        ret-=minus_coef*A[i];
        seg_dist.set(A[i],seg_dist.get(A[i])+(N-1-i));
        seg_cnt.set(A[i],seg_cnt.get(A[i])+1);
    }
    return ret;
}
int main(void){
    int N;
    cin >> N;
    vector<lint> A(N);
    rep(i,N) cin >> A[i];
    lint ans=0;
    ans+=calc(N,A);
    reverse(all(A));
    ans+=calc(N,A);
    cout << ans << endl;
}
0