結果

問題 No.2223 Merged Med
ユーザー kuronikuroni
提出日時 2023-02-17 23:43:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 724 ms / 7,000 ms
コード長 2,158 bytes
コンパイル時間 1,743 ms
コンパイル使用メモリ 178,588 KB
実行使用メモリ 13,668 KB
最終ジャッジ日時 2023-09-26 21:04:57
合計ジャッジ時間 15,617 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 193 ms
6,444 KB
testcase_14 AC 68 ms
4,380 KB
testcase_15 AC 501 ms
11,928 KB
testcase_16 AC 611 ms
12,716 KB
testcase_17 AC 292 ms
8,320 KB
testcase_18 AC 62 ms
4,380 KB
testcase_19 AC 161 ms
6,052 KB
testcase_20 AC 724 ms
13,304 KB
testcase_21 AC 706 ms
13,056 KB
testcase_22 AC 694 ms
13,328 KB
testcase_23 AC 704 ms
12,976 KB
testcase_24 AC 699 ms
13,076 KB
testcase_25 AC 711 ms
13,668 KB
testcase_26 AC 702 ms
13,212 KB
testcase_27 AC 703 ms
13,316 KB
testcase_28 AC 711 ms
12,976 KB
testcase_29 AC 714 ms
13,636 KB
testcase_30 AC 509 ms
13,360 KB
testcase_31 AC 508 ms
11,936 KB
testcase_32 AC 10 ms
4,376 KB
testcase_33 AC 695 ms
13,076 KB
testcase_34 AC 612 ms
13,424 KB
testcase_35 AC 616 ms
11,972 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:74:22: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   74 |                 auto [l, r] = que[ind];
      |                      ^
main.cpp:76:22: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   76 |                 auto [rl, rr] = rng[ind];
      |                      ^

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;

struct node {
    int l, r, val, sum;
    bool ok = false;

    node(int s = 0) {
        l = 0; r = s;
        val = 0;
        sum = s;
        ok = s;
    }
};

node e() {
    return node();
}

node op(node a, node b) {
    node ans;
    ans.l = min(a.l, a.sum + b.l);
    ans.r = max(a.r, a.sum + b.r);
    ans.sum = a.sum + b.sum;
    ans.val = min({a.val + b.sum, b.val + a.sum, ans.sum - (b.r + a.sum) + a.l});
    return ans;
}

ostream& operator<<(ostream &out, node x) {
    return out << "(" << x.l << ", " << x.r << ", " << x.sum << ", " << x.val << ")";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q; cin >> n >> q;
    vector<int> a(n);
    vector<vector<int>> pos(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        pos[a[i]].push_back(i);
    }
    vector<pair<int, int>> que(q), rng(q);
    vector<vector<int>> xd(n + 1);
    auto set_range = [&](int i, int l, int r) {
        rng[i] = {l, r};
        if (l + 1 < r) {
            xd[(l + r) / 2].push_back(i);
        }
    };
    for (int i = 0; i < q; i++) {
        int l, r; cin >> l >> r; l--;
        if (l + 1 == r) {
            set_range(i, a[l], a[l]);
        } else {
            que[i] = {l, r}; set_range(i, 0, n + 1);
        }
    }
    while (true) {
        vector<vector<int>> cur(n + 1); swap(cur, xd);
        bool ok = false;
        segtree<node, op, e> seg(n);
        for (int i = 0; i < n; i++) {
            seg.set(i, node(1));
        }
        for (int m = 0; m <= n; m++) {
            for (int v : pos[m]) {
                seg.set(v, node(-1));
            }
            for (int ind : cur[m]) {
                ok = true;
                auto [l, r] = que[ind];
                node cc = seg.prod(l, r);
                auto [rl, rr] = rng[ind];
                (cc.val + 1 >= 0 ? rl : rr) = m;
                set_range(ind, rl, rr);
            }
        }
        if (!ok) {
            break;
        }
    }
    for (int i = 0; i < q; i++) {
        cout << rng[i].second << '\n';
    }
}
0