結果

問題 No.2710 How many more?
ユーザー Nafmo2Nafmo2
提出日時 2024-01-22 19:35:30
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 358 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 4,218 ms
コンパイル使用メモリ 272,100 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2024-09-28 06:28:28
合計ジャッジ時間 9,788 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:19:19: warning: range-based 'for' loops with initializer only available with '-std=c++20' or '-std=gnu++20' [-Wc++20-extensions]
   19 |   for (int i = 1; auto x : B) {
      |                   ^~~~

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/all>
using namespace std;
using namespace atcoder;
int main() {
  int ans = 0;
  int N, Q;
  cin >> N >> Q;
  vector<int> A(N, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  auto B = A;
  sort(B.rbegin(), B.rend());
  map<int, int> M;
  vector S(B.size() + 1, 0);
  B.erase(unique(B.begin(), B.end()), B.end());
  for (int i = 1; auto x : B) {
    M[x] = i;
    i++;
  }
  for (auto x : A) {
    S[M[x]]++;
  }
  for (int i = 0; i < S.size() - 1; i++) {
    S[i + 1] += S[i];
  }
  while (Q--) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << max(S[M[A[y]] - 1] - S[M[A[x]]], 0) << endl;
  }
}
0