結果

問題 No.2592 おでぶなおばけさん 2
ユーザー 👑 NachiaNachia
提出日時 2023-12-20 01:09:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,500 ms
コード長 1,681 bytes
コンパイル時間 1,161 ms
コンパイル使用メモリ 116,600 KB
実行使用メモリ 9,472 KB
最終ジャッジ日時 2023-12-20 11:16:24
合計ジャッジ時間 11,313 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 16 ms
6,676 KB
testcase_02 AC 24 ms
6,676 KB
testcase_03 AC 11 ms
6,676 KB
testcase_04 AC 12 ms
6,676 KB
testcase_05 AC 39 ms
7,296 KB
testcase_06 AC 27 ms
6,676 KB
testcase_07 AC 34 ms
6,676 KB
testcase_08 AC 31 ms
6,676 KB
testcase_09 AC 12 ms
6,676 KB
testcase_10 AC 16 ms
6,676 KB
testcase_11 AC 32 ms
6,676 KB
testcase_12 AC 8 ms
6,676 KB
testcase_13 AC 55 ms
7,936 KB
testcase_14 AC 54 ms
7,936 KB
testcase_15 AC 44 ms
6,912 KB
testcase_16 AC 54 ms
7,936 KB
testcase_17 AC 57 ms
8,448 KB
testcase_18 AC 44 ms
7,040 KB
testcase_19 AC 38 ms
6,676 KB
testcase_20 AC 49 ms
7,424 KB
testcase_21 AC 43 ms
6,676 KB
testcase_22 AC 55 ms
8,576 KB
testcase_23 AC 57 ms
8,448 KB
testcase_24 AC 47 ms
7,424 KB
testcase_25 AC 35 ms
6,676 KB
testcase_26 AC 35 ms
6,676 KB
testcase_27 AC 67 ms
9,472 KB
testcase_28 AC 66 ms
9,472 KB
testcase_29 AC 67 ms
9,472 KB
testcase_30 AC 69 ms
9,472 KB
testcase_31 AC 69 ms
9,472 KB
testcase_32 AC 68 ms
9,472 KB
testcase_33 AC 69 ms
9,472 KB
testcase_34 AC 70 ms
9,472 KB
testcase_35 AC 69 ms
9,472 KB
testcase_36 AC 70 ms
9,472 KB
testcase_37 AC 69 ms
9,472 KB
testcase_38 AC 70 ms
9,472 KB
testcase_39 AC 68 ms
9,472 KB
testcase_40 AC 67 ms
9,472 KB
testcase_41 AC 68 ms
9,472 KB
testcase_42 AC 69 ms
9,472 KB
testcase_43 AC 67 ms
9,472 KB
testcase_44 AC 68 ms
9,472 KB
testcase_45 AC 68 ms
9,472 KB
testcase_46 AC 67 ms
9,472 KB
testcase_47 AC 60 ms
9,472 KB
testcase_48 AC 60 ms
9,472 KB
testcase_49 AC 61 ms
9,472 KB
testcase_50 AC 60 ms
9,472 KB
testcase_51 AC 59 ms
9,472 KB
testcase_52 AC 66 ms
8,960 KB
testcase_53 AC 67 ms
8,960 KB
testcase_54 AC 67 ms
8,960 KB
testcase_55 AC 67 ms
8,960 KB
testcase_56 AC 67 ms
8,960 KB
testcase_57 AC 28 ms
6,676 KB
testcase_58 AC 73 ms
9,472 KB
testcase_59 AC 73 ms
9,472 KB
testcase_60 AC 75 ms
9,472 KB
testcase_61 AC 75 ms
9,472 KB
testcase_62 AC 73 ms
9,472 KB
testcase_63 AC 73 ms
9,472 KB
testcase_64 AC 75 ms
9,472 KB
testcase_65 AC 64 ms
8,576 KB
testcase_66 AC 64 ms
8,576 KB
testcase_67 AC 64 ms
8,576 KB
testcase_68 AC 63 ms
8,576 KB
testcase_69 AC 62 ms
8,576 KB
testcase_70 AC 63 ms
8,576 KB
testcase_71 AC 63 ms
8,576 KB
testcase_72 AC 63 ms
8,576 KB
testcase_73 AC 64 ms
8,576 KB
testcase_74 AC 2 ms
6,676 KB
testcase_75 AC 67 ms
9,472 KB
testcase_76 AC 69 ms
9,472 KB
testcase_77 AC 67 ms
9,472 KB
testcase_78 AC 69 ms
9,472 KB
testcase_79 AC 68 ms
9,472 KB
testcase_80 AC 69 ms
9,472 KB
testcase_81 AC 68 ms
9,472 KB
testcase_82 AC 68 ms
9,472 KB
testcase_83 AC 68 ms
9,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*


左端 l を固定して右に伸ばしてゆくとき、「一番右の要素に何を足せば重み和が 0 になるか」を管理するのは簡単。
K で割って A を引けばよい。

0 を入れたら 0 になる、のときクエリの答えは No 。

クエリを先読みし、右端 r で分類する。

* a[x] = (x を入れたら結果が 0 になるような l のリスト)

という連想配列を作って r=1 から r=N まで走査する。
連想配列の要素数は log_K max|A| 程度で抑えられる。


*/


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <array>
#include <cmath>
using namespace std;
using i64 = long long;
#define rep(i,n) for(i64 i=0; i<(i64)(n); i++)
const char* yn(bool x){ return x ? "Yes" : "No"; }
#include <map>


int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    i64 N,Q,K; cin >> N >> Q >> K;
    vector<i64> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    vector<int> L(Q), R(Q);
    rep(i,Q){ cin >> L[i] >> R[i]; L[i]--; }
    vector<vector<int>> queries(N+1);
    rep(i,Q) queries[R[i]].push_back(i);
    map<i64, vector<int>> bezero;
    vector<int> ans(Q);
    rep(i,N){
        bezero[0].push_back(i);
        map<i64, vector<int>> nxbezero;
        for(auto& [u,v] : bezero) if(u % K == 0){
            nxbezero[u/K - A[i]] = move(v);
        }
        swap(bezero, nxbezero);
        auto& tosearch = bezero[0];
        for(auto qi : queries[i+1]){
            ans[qi] = binary_search(tosearch.begin(), tosearch.end(), L[qi]) ? 0 : 1;
        }
    }
    rep(i,Q) cout << yn(ans[i]) << '\n';
    return 0;
}
0