結果

問題 No.5010 Better Mo's Algorithm is Needed!! (Unweighted)
ユーザー t98slidert98slider
提出日時 2022-12-17 03:13:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 5,000 ms
コード長 2,264 bytes
コンパイル時間 2,811 ms
実行使用メモリ 7,112 KB
スコア 8,987,570,417
最終ジャッジ日時 2022-12-17 03:14:02
合計ジャッジ時間 55,280 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
純コード判定しない問題か言語
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
6,952 KB
testcase_01 AC 105 ms
6,892 KB
testcase_02 AC 103 ms
6,988 KB
testcase_03 AC 105 ms
7,020 KB
testcase_04 AC 106 ms
6,888 KB
testcase_05 AC 104 ms
6,888 KB
testcase_06 AC 105 ms
7,000 KB
testcase_07 AC 105 ms
6,888 KB
testcase_08 AC 104 ms
6,952 KB
testcase_09 AC 103 ms
7,000 KB
testcase_10 AC 104 ms
6,972 KB
testcase_11 AC 104 ms
6,900 KB
testcase_12 AC 104 ms
6,952 KB
testcase_13 AC 104 ms
6,892 KB
testcase_14 AC 105 ms
6,968 KB
testcase_15 AC 104 ms
6,952 KB
testcase_16 AC 104 ms
6,888 KB
testcase_17 AC 105 ms
6,948 KB
testcase_18 AC 104 ms
7,000 KB
testcase_19 AC 105 ms
6,892 KB
testcase_20 AC 105 ms
7,108 KB
testcase_21 AC 107 ms
6,968 KB
testcase_22 AC 105 ms
7,028 KB
testcase_23 AC 104 ms
6,884 KB
testcase_24 AC 106 ms
6,904 KB
testcase_25 AC 105 ms
6,884 KB
testcase_26 AC 105 ms
6,896 KB
testcase_27 AC 104 ms
6,892 KB
testcase_28 AC 104 ms
6,996 KB
testcase_29 AC 104 ms
6,996 KB
testcase_30 AC 105 ms
6,968 KB
testcase_31 AC 105 ms
6,988 KB
testcase_32 AC 104 ms
7,004 KB
testcase_33 AC 106 ms
6,900 KB
testcase_34 AC 105 ms
6,996 KB
testcase_35 AC 106 ms
6,956 KB
testcase_36 AC 104 ms
6,984 KB
testcase_37 AC 105 ms
6,940 KB
testcase_38 AC 104 ms
7,012 KB
testcase_39 AC 104 ms
7,004 KB
testcase_40 AC 104 ms
6,916 KB
testcase_41 AC 104 ms
6,936 KB
testcase_42 AC 104 ms
6,992 KB
testcase_43 AC 106 ms
6,996 KB
testcase_44 AC 105 ms
6,952 KB
testcase_45 AC 105 ms
7,036 KB
testcase_46 AC 105 ms
7,004 KB
testcase_47 AC 105 ms
7,108 KB
testcase_48 AC 104 ms
6,968 KB
testcase_49 AC 105 ms
6,976 KB
testcase_50 AC 104 ms
6,888 KB
testcase_51 AC 104 ms
6,884 KB
testcase_52 AC 104 ms
6,940 KB
testcase_53 AC 104 ms
6,944 KB
testcase_54 AC 104 ms
6,884 KB
testcase_55 AC 104 ms
6,936 KB
testcase_56 AC 105 ms
6,888 KB
testcase_57 AC 105 ms
6,968 KB
testcase_58 AC 105 ms
7,008 KB
testcase_59 AC 105 ms
6,900 KB
testcase_60 AC 105 ms
6,996 KB
testcase_61 AC 103 ms
6,952 KB
testcase_62 AC 106 ms
7,000 KB
testcase_63 AC 104 ms
6,884 KB
testcase_64 AC 103 ms
6,944 KB
testcase_65 AC 104 ms
6,984 KB
testcase_66 AC 104 ms
6,968 KB
testcase_67 AC 106 ms
7,008 KB
testcase_68 AC 104 ms
6,992 KB
testcase_69 AC 105 ms
6,996 KB
testcase_70 AC 104 ms
6,996 KB
testcase_71 AC 104 ms
7,100 KB
testcase_72 AC 105 ms
6,928 KB
testcase_73 AC 105 ms
7,008 KB
testcase_74 AC 104 ms
6,896 KB
testcase_75 AC 107 ms
6,996 KB
testcase_76 AC 104 ms
6,956 KB
testcase_77 AC 103 ms
6,904 KB
testcase_78 AC 105 ms
7,044 KB
testcase_79 AC 103 ms
6,944 KB
testcase_80 AC 104 ms
6,896 KB
testcase_81 AC 105 ms
6,900 KB
testcase_82 AC 106 ms
6,984 KB
testcase_83 AC 105 ms
6,956 KB
testcase_84 AC 105 ms
6,996 KB
testcase_85 AC 106 ms
6,904 KB
testcase_86 AC 105 ms
6,932 KB
testcase_87 AC 104 ms
6,888 KB
testcase_88 AC 104 ms
6,964 KB
testcase_89 AC 103 ms
7,032 KB
testcase_90 AC 103 ms
6,904 KB
testcase_91 AC 104 ms
6,884 KB
testcase_92 AC 104 ms
6,992 KB
testcase_93 AC 104 ms
6,900 KB
testcase_94 AC 104 ms
6,888 KB
testcase_95 AC 105 ms
7,020 KB
testcase_96 AC 103 ms
6,892 KB
testcase_97 AC 105 ms
7,008 KB
testcase_98 AC 104 ms
7,020 KB
testcase_99 AC 104 ms
6,992 KB
testcase_100 AC 103 ms
6,968 KB
testcase_101 AC 105 ms
6,896 KB
testcase_102 AC 103 ms
6,884 KB
testcase_103 AC 103 ms
7,112 KB
testcase_104 AC 104 ms
7,012 KB
testcase_105 AC 106 ms
6,976 KB
testcase_106 AC 103 ms
7,028 KB
testcase_107 AC 104 ms
7,036 KB
testcase_108 AC 104 ms
6,888 KB
testcase_109 AC 104 ms
6,888 KB
testcase_110 AC 103 ms
7,000 KB
testcase_111 AC 103 ms
7,000 KB
testcase_112 AC 104 ms
6,884 KB
testcase_113 AC 106 ms
6,904 KB
testcase_114 AC 106 ms
6,892 KB
testcase_115 AC 108 ms
7,008 KB
testcase_116 AC 104 ms
6,992 KB
testcase_117 AC 104 ms
7,032 KB
testcase_118 AC 104 ms
6,960 KB
testcase_119 AC 102 ms
6,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct Mo_Algorithm{
    int N, D, Q;//配列の要素数,幅,クエリ数
    std::vector<std::pair<int, int> > query;
    Mo_Algorithm(int n) : N(n){}
    void add_query(int l,int 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<int> build(){
        Q = query.size() , D = std::max(1, int(N / sqrt(Q)));
        std::vector<int> order(Q), Div(Q), cnt(N / D + 1);
        std::vector<bool> type(N / D + 1);
        for(int i = 0; i < Q; i++){
            Div[i] = query[i].second / D;
            cnt[Div[i]]++;
        }
        bool s = false;
        for(int i = 0; i < cnt.size(); i++){
            type[i] = s;
            if(cnt[i] >= 1)s ^= true;
        }
        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 type[i] ? query[i] > query[j] : 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;
    Mo_Algorithm MA(N);
    vector<int> W(N);
    for(auto &&v:W)cin >> v;
    for(int i = 0; i < Q; i++){
        cin >> L >> R;
        MA.add_query(--L, R);
    }
    auto ans = MA.build();
    for(int i = 0; i < ans.size(); i++){
        cout << ++ans[i] << (i + 1 == ans.size() ? '\n' : ' ');
    }
}
0