結果

問題 No.2710 How many more?
ユーザー hanagehanage
提出日時 2024-03-31 14:10:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 429 ms / 2,000 ms
コード長 703 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 212,896 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-03-31 14:10:35
合計ジャッジ時間 7,660 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,548 KB
testcase_01 AC 3 ms
6,548 KB
testcase_02 AC 337 ms
7,936 KB
testcase_03 AC 190 ms
8,064 KB
testcase_04 AC 170 ms
9,600 KB
testcase_05 AC 110 ms
7,296 KB
testcase_06 AC 144 ms
8,960 KB
testcase_07 AC 111 ms
6,548 KB
testcase_08 AC 94 ms
6,548 KB
testcase_09 AC 291 ms
8,832 KB
testcase_10 AC 148 ms
7,040 KB
testcase_11 AC 226 ms
6,656 KB
testcase_12 AC 364 ms
9,472 KB
testcase_13 AC 421 ms
9,984 KB
testcase_14 AC 397 ms
9,984 KB
testcase_15 AC 404 ms
9,984 KB
testcase_16 AC 429 ms
9,984 KB
testcase_17 AC 391 ms
9,984 KB
testcase_18 AC 3 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

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