結果

問題 No.5010 Better Mo's Algorithm is Needed!! (Unweighted)
ユーザー t98slidert98slider
提出日時 2022-12-17 03:00:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 104 ms / 5,000 ms
コード長 2,029 bytes
コンパイル時間 2,922 ms
実行使用メモリ 7,100 KB
スコア 10,093,845,997
最終ジャッジ日時 2022-12-17 03:01:56
合計ジャッジ時間 54,589 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
7,028 KB
testcase_01 AC 95 ms
6,888 KB
testcase_02 AC 95 ms
7,016 KB
testcase_03 AC 96 ms
7,024 KB
testcase_04 AC 104 ms
6,888 KB
testcase_05 AC 95 ms
6,964 KB
testcase_06 AC 96 ms
7,024 KB
testcase_07 AC 95 ms
6,944 KB
testcase_08 AC 100 ms
6,996 KB
testcase_09 AC 97 ms
6,988 KB
testcase_10 AC 96 ms
7,024 KB
testcase_11 AC 96 ms
6,996 KB
testcase_12 AC 97 ms
6,992 KB
testcase_13 AC 96 ms
6,892 KB
testcase_14 AC 96 ms
6,892 KB
testcase_15 AC 97 ms
6,988 KB
testcase_16 AC 98 ms
6,964 KB
testcase_17 AC 96 ms
7,100 KB
testcase_18 AC 95 ms
6,968 KB
testcase_19 AC 96 ms
6,992 KB
testcase_20 AC 96 ms
6,900 KB
testcase_21 AC 96 ms
6,944 KB
testcase_22 AC 95 ms
6,968 KB
testcase_23 AC 95 ms
6,984 KB
testcase_24 AC 96 ms
6,944 KB
testcase_25 AC 95 ms
6,996 KB
testcase_26 AC 97 ms
6,940 KB
testcase_27 AC 95 ms
7,012 KB
testcase_28 AC 93 ms
6,892 KB
testcase_29 AC 97 ms
6,900 KB
testcase_30 AC 96 ms
6,964 KB
testcase_31 AC 95 ms
7,020 KB
testcase_32 AC 96 ms
6,900 KB
testcase_33 AC 96 ms
6,944 KB
testcase_34 AC 96 ms
7,004 KB
testcase_35 AC 96 ms
6,996 KB
testcase_36 AC 97 ms
7,028 KB
testcase_37 AC 96 ms
6,944 KB
testcase_38 AC 95 ms
6,972 KB
testcase_39 AC 96 ms
6,996 KB
testcase_40 AC 96 ms
7,000 KB
testcase_41 AC 97 ms
6,888 KB
testcase_42 AC 96 ms
7,100 KB
testcase_43 AC 97 ms
7,016 KB
testcase_44 AC 95 ms
6,944 KB
testcase_45 AC 97 ms
6,964 KB
testcase_46 AC 95 ms
6,896 KB
testcase_47 AC 99 ms
7,004 KB
testcase_48 AC 96 ms
6,968 KB
testcase_49 AC 95 ms
6,896 KB
testcase_50 AC 95 ms
6,992 KB
testcase_51 AC 96 ms
7,024 KB
testcase_52 AC 97 ms
7,032 KB
testcase_53 AC 96 ms
6,900 KB
testcase_54 AC 96 ms
6,896 KB
testcase_55 AC 95 ms
6,984 KB
testcase_56 AC 96 ms
7,000 KB
testcase_57 AC 96 ms
6,968 KB
testcase_58 AC 95 ms
7,004 KB
testcase_59 AC 96 ms
6,992 KB
testcase_60 AC 96 ms
6,944 KB
testcase_61 AC 95 ms
6,964 KB
testcase_62 AC 97 ms
6,972 KB
testcase_63 AC 97 ms
6,996 KB
testcase_64 AC 94 ms
7,000 KB
testcase_65 AC 97 ms
6,896 KB
testcase_66 AC 97 ms
6,968 KB
testcase_67 AC 96 ms
7,100 KB
testcase_68 AC 96 ms
6,892 KB
testcase_69 AC 95 ms
6,896 KB
testcase_70 AC 99 ms
6,900 KB
testcase_71 AC 96 ms
6,892 KB
testcase_72 AC 95 ms
6,996 KB
testcase_73 AC 95 ms
6,968 KB
testcase_74 AC 98 ms
6,900 KB
testcase_75 AC 95 ms
6,972 KB
testcase_76 AC 96 ms
6,964 KB
testcase_77 AC 94 ms
6,892 KB
testcase_78 AC 96 ms
6,996 KB
testcase_79 AC 96 ms
6,964 KB
testcase_80 AC 96 ms
6,988 KB
testcase_81 AC 95 ms
6,892 KB
testcase_82 AC 96 ms
7,004 KB
testcase_83 AC 96 ms
7,004 KB
testcase_84 AC 96 ms
6,988 KB
testcase_85 AC 96 ms
6,964 KB
testcase_86 AC 97 ms
6,940 KB
testcase_87 AC 96 ms
6,896 KB
testcase_88 AC 97 ms
6,896 KB
testcase_89 AC 97 ms
6,972 KB
testcase_90 AC 96 ms
6,968 KB
testcase_91 AC 95 ms
6,896 KB
testcase_92 AC 95 ms
6,960 KB
testcase_93 AC 99 ms
6,900 KB
testcase_94 AC 96 ms
7,016 KB
testcase_95 AC 98 ms
6,988 KB
testcase_96 AC 96 ms
7,100 KB
testcase_97 AC 97 ms
7,016 KB
testcase_98 AC 96 ms
7,020 KB
testcase_99 AC 97 ms
6,964 KB
testcase_100 AC 95 ms
6,892 KB
testcase_101 AC 97 ms
7,032 KB
testcase_102 AC 96 ms
7,012 KB
testcase_103 AC 95 ms
7,076 KB
testcase_104 AC 100 ms
6,988 KB
testcase_105 AC 97 ms
7,000 KB
testcase_106 AC 96 ms
7,000 KB
testcase_107 AC 96 ms
6,944 KB
testcase_108 AC 101 ms
7,016 KB
testcase_109 AC 96 ms
7,016 KB
testcase_110 AC 95 ms
7,016 KB
testcase_111 AC 95 ms
7,024 KB
testcase_112 AC 96 ms
6,960 KB
testcase_113 AC 95 ms
6,992 KB
testcase_114 AC 96 ms
6,892 KB
testcase_115 AC 96 ms
6,896 KB
testcase_116 AC 97 ms
7,000 KB
testcase_117 AC 98 ms
7,008 KB
testcase_118 AC 96 ms
6,976 KB
testcase_119 AC 97 ms
6,972 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);
        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];
            if(Div[i] & 1)query[i] > query[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;
    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