結果

問題 No.2710 How many more?
ユーザー hanage
提出日時 2024-03-31 14:10:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 340 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 1,748 ms
コンパイル使用メモリ 203,704 KB
最終ジャッジ日時 2025-02-20 17:00:26
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#include <atcoder/fenwicktree>
using namespace atcoder;

int main() {
  int N, Q;
  cin >> N >> Q;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  map<int, int> cc;
  for (int i = 0; i < N; i++) {
    cc[A[i]];
  }
  int cnt = 0;
  for (auto x : cc) {
    cc[x.first] = cnt;
    cnt++;
  }
  fenwick_tree<ll> ft(200039);
  for (int i = 0; i < N; i++) {
    ft.add(cc[A[i]], 1);
  }
  while (Q--) {
    int x, y;
    cin >> x >> y;
    int xx = cc[A[x - 1]];
    int yy = cc[A[y - 1]];
    if (xx <= yy) {
      cout << 0 << endl;
    } else {
      cout << ft.sum(yy + 1, xx) << endl;
    }
  }
  return 0;
}
0