結果

問題 No.2077 Get Minimum Algorithm
ユーザー kuronikuroni
提出日時 2022-09-16 22:51:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 3,000 ms
コード長 1,253 bytes
コンパイル時間 2,951 ms
コンパイル使用メモリ 172,032 KB
実行使用メモリ 10,720 KB
最終ジャッジ日時 2023-08-23 16:23:00
合計ジャッジ時間 9,000 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 4 ms
4,376 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 95 ms
9,876 KB
testcase_13 AC 95 ms
9,920 KB
testcase_14 AC 96 ms
9,812 KB
testcase_15 AC 96 ms
9,888 KB
testcase_16 AC 100 ms
9,912 KB
testcase_17 AC 99 ms
9,812 KB
testcase_18 AC 99 ms
9,888 KB
testcase_19 AC 93 ms
9,944 KB
testcase_20 AC 97 ms
10,112 KB
testcase_21 AC 111 ms
10,048 KB
testcase_22 AC 111 ms
10,064 KB
testcase_23 AC 100 ms
10,000 KB
testcase_24 AC 101 ms
10,176 KB
testcase_25 AC 106 ms
10,076 KB
testcase_26 AC 100 ms
10,064 KB
testcase_27 AC 93 ms
10,720 KB
testcase_28 AC 79 ms
8,040 KB
testcase_29 AC 59 ms
7,160 KB
testcase_30 AC 89 ms
10,328 KB
testcase_31 AC 77 ms
8,020 KB
testcase_32 AC 58 ms
7,244 KB
testcase_33 AC 96 ms
10,104 KB
testcase_34 AC 81 ms
9,120 KB
testcase_35 AC 58 ms
7,252 KB
testcase_36 AC 96 ms
10,116 KB
testcase_37 AC 96 ms
10,156 KB
testcase_38 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:49:19: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   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