結果

問題 No.2223 Merged Med
ユーザー kuronikuroni
提出日時 2023-02-17 23:40:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,235 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 179,856 KB
実行使用メモリ 10,844 KB
最終ジャッジ日時 2023-09-26 21:01:20
合計ジャッジ時間 11,849 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 6 ms
4,384 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
    for (int i = 0; i < n; i++) {
        cin >> a[i]; a[i]--;
        pos[a[i]].push_back(i);
    }
    vector<pair<int, int>> que(q), rng(q);
    vector<vector<int>> xd(n);
    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, -1, n - 1);
        }
    }
    while (true) {
        vector<vector<int>> cur(n); 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];
                cerr << m + 1 << " " << l << " " << r << ": " << cc << endl;
                (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 + 1 << '\n';
    }
}
0