結果

問題 No.2710 How many more?
コンテスト
ユーザー kekenx
提出日時 2024-05-26 21:35:59
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 571 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 550 ms
コンパイル使用メモリ 105,448 KB
実行使用メモリ 12,020 KB
最終ジャッジ日時 2026-07-04 19:18:53
合計ジャッジ時間 4,386 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 6 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int N, Q; cin >> N >> Q;

  vector<pair<int, int>> A(N);
  for (int i = 0; i < N; i++) {
    int a; cin >> a;
    A[i] = make_pair(a, i);
  }

  vector<int> b(N);
  sort(A.rbegin(), A.rend());
  for (int i = 0; i < N; i++) {
    b[A[i].second] = i;
  }

  while (Q--) {
    int x, y; cin >> x >> y;
    x--; y--;
    int frm = b[x], to = b[y];
    if (frm >= to)
      cout << 0 << endl;
    else
      cout << to - frm - 1 << endl;
  }
  return 0;
}
  

0