結果

問題 No.1299 Random Array Score
ユーザー 👑Zack Ni👑Zack Ni
提出日時 2020-11-30 14:02:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,246 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 88,552 KB
実行使用メモリ 12,812 KB
最終ジャッジ日時 2023-10-11 02:50:06
合計ジャッジ時間 3,959 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
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 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
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 AC 42 ms
12,620 KB
testcase_35 WA -
testcase_36 AC 68 ms
12,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int lsb(int x){
    return x & (-x);
}
typedef long long ll;
#define MODX 998244353

class FenwickTree{
public:
    ll * B; 
    int n;
    FenwickTree(int n){
        this->n = n;
        this->B = new ll[n+3];
        for(int i = 0; i <= n+1; ++i)
            this->B[i] = 0;
    }
    ll getsum(int index){
        ll sum = 0;
        index = index + 1;
        while(index > 0){
            sum = (this->B[index] + sum) % MODX;
            index -= lsb(index);
        }
        return sum;
    }
    void update(int index, ll val){
        index = index + 1;
        while(index <= n){
            this->B[index] =  (this->B[index] + val ) %MODX;
            index += lsb(index);
        }
    }

};
ll add(ll x, ll y){
    return (x+y)%MODX;
}

ll mul(ll x, ll y){
    return (x*y)%MODX;
}

void CoordinateCompress(vector<int> u, vector<int> & v){
    sort(u.begin(),u.end()); 
    map<int,int> mpitoind;
    int n = u.size();
    for(int i = 0; i< n; ++i)
        mpitoind[u[i]] = i;
    for(int i = 0; i < n; ++i)
        v[i] = mpitoind[v[i]];
}

int main()
{
   
    int n; 
    cin >> n;
    vector<int> a; vector<int> b;
    for(int i = 0; i< n; ++i){
        int x; cin >> x; a.push_back(x);
        b.push_back(x);
    }
    CoordinateCompress(a,a);
    FenwickTree * presum = new FenwickTree(n+2);
    FenwickTree * f = new FenwickTree(n+2);
    FenwickTree * g = new FenwickTree(n+2);
    FenwickTree * c = new FenwickTree(n+2);
    FenwickTree * gp = new FenwickTree(n+2);
    for(int i = n-1; i >= 0; --i){
        ll nf = 1, ng = 0, nc = 0, ngp = 0;
        if(a[i] - 1 >= 0){
            ll frequency = f->getsum(a[i]-1);
            ll pres = presum->getsum(a[i]-1);
            ng = add( mul(frequency, b[i]) , pres);
            nc = frequency;
            ll frequency2 = c->getsum(a[i]-1);
            ll pres2 = g->getsum(a[i]-1);
            ngp = add( mul(frequency2, b[i]) , pres2);
        }
        presum->update(a[i], b[i]);
        f->update(a[i], nf);
        g->update(a[i], ng);
        c->update(a[i], nc);
        gp->update(a[i], ngp);        
    }
    cout << gp->getsum(n);
    return 0;
}
0