結果

問題 No.2710 How many more?
ユーザー hatsuka_iwa
提出日時 2024-04-01 15:47:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 720 bytes
コンパイル時間 1,933 ms
コンパイル使用メモリ 176,440 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-30 21:51:24
合計ジャッジ時間 6,264 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int N, Q; cin >> N >> Q;
  vector<int> A(N), B(N);
  vector<long long> S(1);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    B.at(i) = A.at(i);
  }

  sort(B.begin(), B.end());
  B.erase(unique(B.begin(), B.end()), B.end());
  vector<int> C(B.size()), M(B.size());

  for (int i = 0; i < N; i++) {
    A.at(i) = lower_bound(B.begin(), B.end(), A.at(i)) - B.begin();
    M[A.at(i)]++;
    C.at(A.at(i))++;
  }

  for (int i = 0; i < (int)C.size(); i++)
    S.push_back(S.at(i) + C.at(i));

  for (int i = 0; i < Q; i++) {
    int x, y; cin >> x >> y;
    cout << max(0LL, S.at(A.at(x - 1) + 1) - S.at(A.at(y - 1) + 1) - M[A.at(x - 1)]) << endl;
  }
}
0