제출 #1172286

#제출 시각아이디문제언어결과실행 시간메모리
1172286lopkusIndex (COCI21_index)C++20
20 / 110
2595 ms832 KiB
#include <bits/stdc++.h>

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, q;
  std::cin >> n >> q;
  std::vector<int> a(n + 1);
  for(int i = 1; i <= n; i++) {
    std::cin >> a[i];
  }
  while(q--) {
    int l, r;
    std::cin >> l >> r;
    std::vector<int> b = a;
    sort(b.begin() + l, b.begin() + r + 1);
    int L = l, R = r, ans = - 1;
    while(L <= R) {
      int mid = (L + R) / 2;
      if(b[mid] > r - mid) {
        ans = r - mid + 1;
        R = mid - 1;
      }
      else {
        L = mid + 1;
      }
    }
    std::cout << ans << "\n";
  }
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...