結果

問題 No.2077 Get Minimum Algorithm
ユーザー kuronikuroni
提出日時 2022-09-16 22:51:36
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 101 ms / 3,000 ms
コード長 1,253 bytes
コンパイル時間 1,569 ms
使用メモリ 10,708 KB
最終ジャッジ日時 2023-01-11 08:10:09
合計ジャッジ時間 8,066 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
4,904 KB
testcase_01 AC 1 ms
4,900 KB
testcase_02 AC 2 ms
6,948 KB
testcase_03 AC 3 ms
4,904 KB
testcase_04 AC 6 ms
4,900 KB
testcase_05 AC 3 ms
4,900 KB
testcase_06 AC 3 ms
4,900 KB
testcase_07 AC 2 ms
4,900 KB
testcase_08 AC 5 ms
4,904 KB
testcase_09 AC 6 ms
6,948 KB
testcase_10 AC 3 ms
6,952 KB
testcase_11 AC 6 ms
4,904 KB
testcase_12 AC 90 ms
10,036 KB
testcase_13 AC 93 ms
9,856 KB
testcase_14 AC 94 ms
9,952 KB
testcase_15 AC 94 ms
9,948 KB
testcase_16 AC 92 ms
9,936 KB
testcase_17 AC 93 ms
9,836 KB
testcase_18 AC 94 ms
9,844 KB
testcase_19 AC 89 ms
9,912 KB
testcase_20 AC 101 ms
9,884 KB
testcase_21 AC 92 ms
9,912 KB
testcase_22 AC 92 ms
10,040 KB
testcase_23 AC 93 ms
10,180 KB
testcase_24 AC 91 ms
10,068 KB
testcase_25 AC 96 ms
10,112 KB
testcase_26 AC 92 ms
10,176 KB
testcase_27 AC 91 ms
10,708 KB
testcase_28 AC 76 ms
8,076 KB
testcase_29 AC 57 ms
7,276 KB
testcase_30 AC 88 ms
10,484 KB
testcase_31 AC 75 ms
8,004 KB
testcase_32 AC 57 ms
7,276 KB
testcase_33 AC 90 ms
10,236 KB
testcase_34 AC 79 ms
9,060 KB
testcase_35 AC 58 ms
6,948 KB
testcase_36 AC 95 ms
10,232 KB
testcase_37 AC 92 ms
10,180 KB
testcase_38 AC 2 ms
4,900 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:49:19: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’
   49 |         for (auto [x, ind] : que[i]) {
      |                   ^

ソースコード

diff #

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

struct fenwick_tree {
    int n;
    vector<int> bit;
    
    fenwick_tree(int _n) : n(_n) {
        bit.resize(n + 1);
    }

    void add(int u) {
        for (; u <= n; u += u & -u) {
            bit[u]++;
        }
    }
    
    int search(int ret) {
        int ans = 0, cur = 0;
        for (int i = __lg(n); i >= 0; i--) {
            if (cur + (1 << i) <= n && ans + bit[cur + (1 << i)] < ret) {
                cur += (1 << i);
                ans += bit[cur];
            }
        }
        return cur + 1;
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    fenwick_tree fen(n);
    vector<int> pos(n + 1);
    for (int i = 1; i <= n; i++) {
        int u; cin >> u;
        pos[u] = i;
    }
    int q; cin >> q;
    vector<vector<pair<int, int>>> que(n + 1);
    for (int i = 0; i < q; i++) {
        int x, y; cin >> x >> y;
        que[y].push_back({x + 1, i});
    }
    vector<int> ans(q);
    for (int i = 1; i <= n; i++) {
        fen.add(pos[i]);
        for (auto [x, ind] : que[i]) {
            ans[ind] = max(pos[i], fen.search(x));
        }
    }
    for (int i = 0; i < q; i++) {
        cout << ans[i] << '\n';
    }
}
0