結果

問題 No.2223 Merged Med
ユーザー kuronikuroni
提出日時 2023-02-17 23:34:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,317 bytes
コンパイル時間 1,759 ms
コンパイル使用メモリ 177,552 KB
実行使用メモリ 12,764 KB
最終ジャッジ日時 2023-09-26 20:56:25
合計ジャッジ時間 11,613 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 152 ms
6,360 KB
testcase_14 AC 67 ms
4,376 KB
testcase_15 AC 284 ms
11,128 KB
testcase_16 AC 410 ms
12,136 KB
testcase_17 AC 165 ms
8,112 KB
testcase_18 AC 61 ms
4,376 KB
testcase_19 AC 129 ms
5,820 KB
testcase_20 AC 475 ms
12,752 KB
testcase_21 AC 472 ms
12,716 KB
testcase_22 AC 485 ms
12,364 KB
testcase_23 AC 474 ms
12,312 KB
testcase_24 AC 499 ms
12,548 KB
testcase_25 AC 483 ms
12,632 KB
testcase_26 AC 482 ms
12,736 KB
testcase_27 AC 496 ms
12,764 KB
testcase_28 AC 491 ms
12,548 KB
testcase_29 AC 494 ms
12,656 KB
testcase_30 AC 254 ms
12,616 KB
testcase_31 AC 267 ms
11,304 KB
testcase_32 AC 10 ms
4,380 KB
testcase_33 AC 423 ms
12,240 KB
testcase_34 AC 359 ms
12,684 KB
testcase_35 AC 357 ms
11,312 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:72:22: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   72 |                 auto [l, r] = que[ind];
      |                      ^
main.cpp:74:22: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   74 |                 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;

    node(int s = 0) {
        l = 0; r = s;
        val = 0;
        sum = 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, 0, n);
        }
    }
    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];
                // for (int i = 0; i < n; i++) {
                //     cerr << seg.get(i) << '\n';
                // }
                // 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