結果

問題 No.2077 Get Minimum Algorithm
ユーザー SSRSSSRS
提出日時 2022-09-16 22:24:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 518 ms / 3,000 ms
コード長 1,340 bytes
コンパイル時間 1,612 ms
コンパイル使用メモリ 172,948 KB
実行使用メモリ 11,564 KB
最終ジャッジ日時 2023-08-23 16:03:08
合計ジャッジ時間 18,523 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 12 ms
4,376 KB
testcase_04 AC 30 ms
4,376 KB
testcase_05 AC 15 ms
4,376 KB
testcase_06 AC 16 ms
4,376 KB
testcase_07 AC 12 ms
4,380 KB
testcase_08 AC 31 ms
4,380 KB
testcase_09 AC 37 ms
4,380 KB
testcase_10 AC 17 ms
4,380 KB
testcase_11 AC 34 ms
4,380 KB
testcase_12 AC 514 ms
11,268 KB
testcase_13 AC 508 ms
11,176 KB
testcase_14 AC 506 ms
11,348 KB
testcase_15 AC 503 ms
11,228 KB
testcase_16 AC 509 ms
11,176 KB
testcase_17 AC 514 ms
11,232 KB
testcase_18 AC 510 ms
11,328 KB
testcase_19 AC 512 ms
11,348 KB
testcase_20 AC 518 ms
11,304 KB
testcase_21 AC 511 ms
11,148 KB
testcase_22 AC 489 ms
11,268 KB
testcase_23 AC 489 ms
11,240 KB
testcase_24 AC 490 ms
11,352 KB
testcase_25 AC 494 ms
11,204 KB
testcase_26 AC 488 ms
11,508 KB
testcase_27 AC 486 ms
11,564 KB
testcase_28 AC 455 ms
8,840 KB
testcase_29 AC 410 ms
7,264 KB
testcase_30 AC 500 ms
11,064 KB
testcase_31 AC 459 ms
8,772 KB
testcase_32 AC 424 ms
7,320 KB
testcase_33 AC 496 ms
10,888 KB
testcase_34 AC 437 ms
9,304 KB
testcase_35 AC 419 ms
7,312 KB
testcase_36 AC 513 ms
11,264 KB
testcase_37 AC 513 ms
11,176 KB
testcase_38 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct binary_indexed_tree{
  int N;
  vector<T> BIT;
  function<T(T, T)> f;
  T E;
  binary_indexed_tree(int N, function<T(T, T)> f, T E): N(N), BIT(N + 1, E), f(f), E(E){
  }
  void add(int i, T x){
    i++;
    while (i <= N){
      BIT[i] = f(BIT[i], x);
      i += i & -i;
    }
  }
  T sum(int i){
    T ans = E;
    while (i > 0){
      ans = f(ans, BIT[i]);
      i -= i & -i;
    }
    return ans;
  }
};
int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i = 0; i < N; i++){
    cin >> P[i];
    P[i]--;
  }
  int Q;
  cin >> Q;
  vector<int> x(Q), y(Q);
  for (int i = 0; i < Q; i++){
    cin >> x[i] >> y[i];
    y[i]--;
  }
  vector<vector<int>> A(N);
  for (int i = 0; i < Q; i++){
    A[y[i]].push_back(i);
  }
  vector<int> PP(N);
  for (int i = 0; i < N; i++){
    PP[P[i]] = i;
  }
  vector<int> ans(Q);
  binary_indexed_tree<int> BIT(N, plus<int>(), 0);
  for (int i = 0; i < N; i++){
    for (int j : A[i]){
      int tv = N, fv = 0;
      while (tv - fv > 1){
        int mid = (tv + fv) / 2;
        if (BIT.sum(mid) >= x[j]){
          tv = mid;
        } else {
          fv = mid;
        }
      }
      ans[j] = max(PP[y[j]] + 1, tv);
    }
    BIT.add(PP[i], 1);
  }
  for (int i = 0; i < Q; i++){
    cout << ans[i] << endl;
  }
}
0