結果
問題 | No.5011 Better Mo's Algorithm is Needed!! (Weighted) |
ユーザー | t98slider |
提出日時 | 2022-12-17 03:05:12 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 128 ms / 5,000 ms |
コード長 | 2,104 bytes |
コンパイル時間 | 2,484 ms |
実行使用メモリ | 13,244 KB |
スコア | 34,956,868,287 |
最終ジャッジ日時 | 2022-12-17 03:06:13 |
合計ジャッジ時間 | 58,732 ms |
ジャッジサーバーID (参考情報) |
judge16 / judge15 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 119 ms
12,596 KB |
testcase_01 | AC | 120 ms
12,512 KB |
testcase_02 | AC | 114 ms
12,456 KB |
testcase_03 | AC | 121 ms
12,508 KB |
testcase_04 | AC | 118 ms
12,368 KB |
testcase_05 | AC | 121 ms
12,376 KB |
testcase_06 | AC | 114 ms
12,508 KB |
testcase_07 | AC | 118 ms
12,544 KB |
testcase_08 | AC | 119 ms
12,580 KB |
testcase_09 | AC | 120 ms
12,388 KB |
testcase_10 | AC | 117 ms
12,508 KB |
testcase_11 | AC | 112 ms
12,380 KB |
testcase_12 | AC | 118 ms
12,540 KB |
testcase_13 | AC | 114 ms
12,548 KB |
testcase_14 | AC | 111 ms
12,544 KB |
testcase_15 | AC | 118 ms
12,384 KB |
testcase_16 | AC | 120 ms
12,376 KB |
testcase_17 | AC | 118 ms
12,600 KB |
testcase_18 | AC | 117 ms
12,384 KB |
testcase_19 | AC | 113 ms
12,412 KB |
testcase_20 | AC | 115 ms
12,384 KB |
testcase_21 | AC | 118 ms
12,524 KB |
testcase_22 | AC | 117 ms
12,380 KB |
testcase_23 | AC | 122 ms
12,596 KB |
testcase_24 | AC | 128 ms
12,540 KB |
testcase_25 | AC | 116 ms
12,376 KB |
testcase_26 | AC | 116 ms
13,196 KB |
testcase_27 | AC | 118 ms
12,456 KB |
testcase_28 | AC | 116 ms
12,592 KB |
testcase_29 | AC | 115 ms
12,444 KB |
testcase_30 | AC | 113 ms
12,564 KB |
testcase_31 | AC | 115 ms
12,548 KB |
testcase_32 | AC | 118 ms
12,436 KB |
testcase_33 | AC | 116 ms
12,640 KB |
testcase_34 | AC | 117 ms
12,308 KB |
testcase_35 | AC | 115 ms
12,628 KB |
testcase_36 | AC | 117 ms
12,564 KB |
testcase_37 | AC | 115 ms
12,484 KB |
testcase_38 | AC | 120 ms
12,436 KB |
testcase_39 | AC | 116 ms
13,196 KB |
testcase_40 | AC | 116 ms
12,384 KB |
testcase_41 | AC | 117 ms
12,572 KB |
testcase_42 | AC | 118 ms
12,648 KB |
testcase_43 | AC | 113 ms
12,432 KB |
testcase_44 | AC | 116 ms
12,592 KB |
testcase_45 | AC | 118 ms
12,724 KB |
testcase_46 | AC | 118 ms
12,444 KB |
testcase_47 | AC | 114 ms
13,068 KB |
testcase_48 | AC | 117 ms
12,428 KB |
testcase_49 | AC | 117 ms
12,348 KB |
testcase_50 | AC | 115 ms
12,504 KB |
testcase_51 | AC | 117 ms
12,732 KB |
testcase_52 | AC | 117 ms
12,384 KB |
testcase_53 | AC | 123 ms
12,584 KB |
testcase_54 | AC | 117 ms
12,608 KB |
testcase_55 | AC | 113 ms
12,412 KB |
testcase_56 | AC | 120 ms
12,864 KB |
testcase_57 | AC | 118 ms
12,432 KB |
testcase_58 | AC | 114 ms
12,680 KB |
testcase_59 | AC | 114 ms
12,572 KB |
testcase_60 | AC | 117 ms
12,456 KB |
testcase_61 | AC | 114 ms
12,568 KB |
testcase_62 | AC | 118 ms
12,524 KB |
testcase_63 | AC | 115 ms
12,652 KB |
testcase_64 | AC | 115 ms
12,456 KB |
testcase_65 | AC | 115 ms
12,940 KB |
testcase_66 | AC | 115 ms
13,112 KB |
testcase_67 | AC | 112 ms
12,548 KB |
testcase_68 | AC | 115 ms
12,784 KB |
testcase_69 | AC | 117 ms
12,516 KB |
testcase_70 | AC | 116 ms
12,472 KB |
testcase_71 | AC | 117 ms
12,744 KB |
testcase_72 | AC | 114 ms
12,616 KB |
testcase_73 | AC | 112 ms
12,352 KB |
testcase_74 | AC | 119 ms
12,672 KB |
testcase_75 | AC | 117 ms
12,580 KB |
testcase_76 | AC | 118 ms
12,488 KB |
testcase_77 | AC | 114 ms
12,412 KB |
testcase_78 | AC | 122 ms
12,480 KB |
testcase_79 | AC | 117 ms
12,380 KB |
testcase_80 | AC | 118 ms
12,408 KB |
testcase_81 | AC | 118 ms
12,644 KB |
testcase_82 | AC | 117 ms
12,500 KB |
testcase_83 | AC | 113 ms
12,536 KB |
testcase_84 | AC | 119 ms
12,536 KB |
testcase_85 | AC | 113 ms
12,380 KB |
testcase_86 | AC | 115 ms
12,392 KB |
testcase_87 | AC | 122 ms
12,412 KB |
testcase_88 | AC | 118 ms
12,684 KB |
testcase_89 | AC | 118 ms
12,624 KB |
testcase_90 | AC | 115 ms
12,576 KB |
testcase_91 | AC | 112 ms
12,472 KB |
testcase_92 | AC | 116 ms
12,404 KB |
testcase_93 | AC | 119 ms
12,632 KB |
testcase_94 | AC | 115 ms
12,468 KB |
testcase_95 | AC | 117 ms
12,496 KB |
testcase_96 | AC | 123 ms
12,636 KB |
testcase_97 | AC | 116 ms
12,500 KB |
testcase_98 | AC | 121 ms
12,508 KB |
testcase_99 | AC | 122 ms
12,532 KB |
testcase_100 | AC | 115 ms
12,460 KB |
testcase_101 | AC | 110 ms
12,596 KB |
testcase_102 | AC | 112 ms
12,496 KB |
testcase_103 | AC | 112 ms
12,460 KB |
testcase_104 | AC | 117 ms
12,412 KB |
testcase_105 | AC | 119 ms
12,476 KB |
testcase_106 | AC | 116 ms
12,520 KB |
testcase_107 | AC | 115 ms
12,832 KB |
testcase_108 | AC | 117 ms
12,380 KB |
testcase_109 | AC | 111 ms
12,436 KB |
testcase_110 | AC | 115 ms
12,388 KB |
testcase_111 | AC | 117 ms
12,384 KB |
testcase_112 | AC | 113 ms
13,244 KB |
testcase_113 | AC | 119 ms
13,112 KB |
testcase_114 | AC | 117 ms
12,632 KB |
testcase_115 | AC | 114 ms
12,592 KB |
testcase_116 | AC | 119 ms
12,444 KB |
testcase_117 | AC | 119 ms
12,676 KB |
testcase_118 | AC | 114 ms
12,460 KB |
testcase_119 | AC | 111 ms
12,388 KB |
ソースコード
#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 (Div[i] & 1 ? 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; 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' : ' '); } }