結果

問題 No.5011 Better Mo's Algorithm is Needed!! (Weighted)
ユーザー t98slidert98slider
提出日時 2022-12-17 02:57:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 2,067 bytes
コンパイル時間 2,813 ms
実行使用メモリ 13,484 KB
スコア 21,938,858,298
最終ジャッジ日時 2022-12-17 02:58:22
合計ジャッジ時間 58,373 ms
ジャッジサーバーID
(参考情報)
judge15 / judge16
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
12,452 KB
testcase_01 AC 115 ms
12,384 KB
testcase_02 AC 115 ms
12,496 KB
testcase_03 AC 115 ms
12,384 KB
testcase_04 AC 114 ms
12,464 KB
testcase_05 AC 121 ms
12,376 KB
testcase_06 AC 117 ms
12,380 KB
testcase_07 AC 120 ms
12,484 KB
testcase_08 AC 119 ms
12,544 KB
testcase_09 AC 118 ms
12,504 KB
testcase_10 AC 116 ms
12,380 KB
testcase_11 AC 116 ms
12,452 KB
testcase_12 AC 114 ms
12,384 KB
testcase_13 AC 118 ms
12,380 KB
testcase_14 AC 119 ms
12,456 KB
testcase_15 AC 112 ms
12,548 KB
testcase_16 AC 114 ms
12,452 KB
testcase_17 AC 118 ms
12,508 KB
testcase_18 AC 116 ms
12,380 KB
testcase_19 AC 115 ms
12,500 KB
testcase_20 AC 114 ms
12,488 KB
testcase_21 AC 114 ms
12,384 KB
testcase_22 AC 116 ms
12,448 KB
testcase_23 AC 116 ms
12,500 KB
testcase_24 AC 114 ms
12,384 KB
testcase_25 AC 116 ms
12,380 KB
testcase_26 AC 113 ms
12,456 KB
testcase_27 AC 111 ms
12,452 KB
testcase_28 AC 116 ms
12,396 KB
testcase_29 AC 116 ms
12,528 KB
testcase_30 AC 119 ms
12,380 KB
testcase_31 AC 110 ms
12,480 KB
testcase_32 AC 115 ms
12,504 KB
testcase_33 AC 123 ms
12,380 KB
testcase_34 AC 115 ms
12,500 KB
testcase_35 AC 117 ms
12,544 KB
testcase_36 AC 120 ms
12,380 KB
testcase_37 AC 114 ms
12,408 KB
testcase_38 AC 116 ms
12,448 KB
testcase_39 AC 119 ms
12,376 KB
testcase_40 AC 118 ms
12,512 KB
testcase_41 AC 115 ms
12,452 KB
testcase_42 AC 116 ms
12,376 KB
testcase_43 AC 115 ms
12,500 KB
testcase_44 AC 115 ms
12,492 KB
testcase_45 AC 118 ms
12,548 KB
testcase_46 AC 115 ms
12,380 KB
testcase_47 AC 115 ms
12,380 KB
testcase_48 AC 119 ms
12,424 KB
testcase_49 AC 117 ms
12,380 KB
testcase_50 AC 118 ms
12,572 KB
testcase_51 AC 115 ms
12,384 KB
testcase_52 AC 116 ms
12,484 KB
testcase_53 AC 113 ms
12,376 KB
testcase_54 AC 122 ms
12,452 KB
testcase_55 AC 112 ms
12,544 KB
testcase_56 AC 118 ms
12,392 KB
testcase_57 AC 117 ms
12,584 KB
testcase_58 AC 116 ms
12,504 KB
testcase_59 AC 115 ms
12,336 KB
testcase_60 AC 117 ms
12,456 KB
testcase_61 AC 114 ms
12,480 KB
testcase_62 AC 114 ms
12,592 KB
testcase_63 AC 113 ms
12,568 KB
testcase_64 AC 114 ms
12,460 KB
testcase_65 AC 117 ms
12,524 KB
testcase_66 AC 115 ms
12,452 KB
testcase_67 AC 117 ms
12,376 KB
testcase_68 AC 118 ms
12,432 KB
testcase_69 AC 116 ms
12,492 KB
testcase_70 AC 115 ms
12,476 KB
testcase_71 AC 112 ms
12,556 KB
testcase_72 AC 118 ms
12,480 KB
testcase_73 AC 113 ms
12,428 KB
testcase_74 AC 116 ms
12,376 KB
testcase_75 AC 119 ms
12,448 KB
testcase_76 AC 116 ms
12,380 KB
testcase_77 AC 116 ms
12,380 KB
testcase_78 AC 118 ms
12,492 KB
testcase_79 AC 116 ms
12,612 KB
testcase_80 AC 114 ms
12,592 KB
testcase_81 AC 117 ms
12,376 KB
testcase_82 AC 116 ms
12,544 KB
testcase_83 AC 117 ms
13,316 KB
testcase_84 AC 114 ms
12,444 KB
testcase_85 AC 113 ms
12,376 KB
testcase_86 AC 118 ms
12,492 KB
testcase_87 AC 118 ms
12,540 KB
testcase_88 AC 116 ms
12,388 KB
testcase_89 AC 116 ms
12,600 KB
testcase_90 AC 116 ms
12,524 KB
testcase_91 AC 113 ms
12,792 KB
testcase_92 AC 116 ms
12,504 KB
testcase_93 AC 118 ms
12,368 KB
testcase_94 AC 117 ms
12,372 KB
testcase_95 AC 118 ms
12,460 KB
testcase_96 AC 119 ms
12,380 KB
testcase_97 AC 113 ms
12,504 KB
testcase_98 AC 110 ms
12,364 KB
testcase_99 AC 115 ms
12,512 KB
testcase_100 AC 114 ms
12,380 KB
testcase_101 AC 115 ms
12,456 KB
testcase_102 AC 120 ms
12,388 KB
testcase_103 AC 118 ms
12,472 KB
testcase_104 AC 118 ms
12,368 KB
testcase_105 AC 120 ms
12,288 KB
testcase_106 AC 113 ms
12,392 KB
testcase_107 AC 120 ms
12,552 KB
testcase_108 AC 119 ms
12,512 KB
testcase_109 AC 119 ms
12,396 KB
testcase_110 AC 119 ms
12,340 KB
testcase_111 AC 119 ms
12,372 KB
testcase_112 AC 116 ms
12,440 KB
testcase_113 AC 115 ms
12,404 KB
testcase_114 AC 120 ms
13,484 KB
testcase_115 AC 115 ms
13,296 KB
testcase_116 AC 122 ms
12,656 KB
testcase_117 AC 121 ms
12,648 KB
testcase_118 AC 120 ms
12,564 KB
testcase_119 AC 115 ms
12,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

struct Mo_Algorithm{
    ll N, D, Q;//配列の要素数,幅,クエリ数
    std::vector<std::pair<ll, ll> > query;
    Mo_Algorithm(ll n) : N(n){}
    void add_query(ll l, ll r){
        query.emplace_back(l, r);
    }
    template< typename ADD, typename DEL, typename ASK>
    void build(const ADD& add,const DEL& del, const ASK& ask){
        Q = query.size() , D = std::max(1, int(N / sqrt(Q)));
        std::vector<int> order(Q), Div(Q);
        for(int i = 0; i < Q; i++)Div[i] = query[i].second / D;
        std::iota(order.begin(), order.end(), 0);
        std::sort(order.begin(), order.end(), [&](int i,int j){
            if(Div[i] != Div[j])return Div[i] < Div[j];
            return query[i] < query[j];
        });
        int cl = 0, cr = 0, l,r;
        for(auto &&qi : order){
            std::tie(l, r) = query[qi];
            while(cl > l)cl--, add(cl);
            while(cr < r)add(cr), cr++;
            while(cl < l)del(cl), cl++;
            while(cr > r)cr--, del(cr);
            ask(qi);
        }
    }
    vector<ll> build(){
        Q = query.size() , D = std::max(1ll, (ll)(N / (sqrt(Q))));
        std::vector<ll> order(Q), Div(Q);
        for(int i = 0; i < Q; i++)Div[i] = query[i].second / D;
        std::iota(order.begin(), order.end(), 0);
        std::sort(order.begin(), order.end(), [&](ll i, ll j){
            if(Div[i] != Div[j])return Div[i] < Div[j];
            return query[i] < query[j];
        });
        return order;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, Q, WT, ST, L, R;
    cin >> N >> Q >> WT >> ST;
    vector<ll> W(N), sw(N + 1);
    for(int i = 0; i < N; i++){
        cin >> W[i];
        sw[i + 1] = sw[i] + W[i];
    }
    Mo_Algorithm MA(sw.back());
    for(int i = 0; i < Q; i++){
        cin >> L >> R;
        MA.add_query(sw[--L], sw[R]);
    }
    auto ans = MA.build();
    for(int i = 0; i < ans.size(); i++){
        cout << ++ans[i] << (i + 1 == ans.size() ? '\n' : ' ');
    }
}
0