結果

問題 No.2710 How many more?
ユーザー marble72marble72
提出日時 2024-03-31 15:01:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 988 bytes
コンパイル時間 2,160 ms
コンパイル使用メモリ 214,308 KB
実行使用メモリ 8,396 KB
最終ジャッジ日時 2024-03-31 15:02:00
合計ジャッジ時間 7,215 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 302 ms
6,548 KB
testcase_03 AC 177 ms
6,548 KB
testcase_04 AC 136 ms
8,012 KB
testcase_05 AC 97 ms
6,548 KB
testcase_06 AC 116 ms
7,372 KB
testcase_07 AC 116 ms
6,548 KB
testcase_08 AC 92 ms
6,548 KB
testcase_09 AC 257 ms
7,244 KB
testcase_10 AC 140 ms
6,548 KB
testcase_11 AC 227 ms
6,548 KB
testcase_12 AC 341 ms
8,012 KB
testcase_13 AC 365 ms
8,396 KB
testcase_14 AC 365 ms
8,396 KB
testcase_15 AC 365 ms
8,396 KB
testcase_16 AC 364 ms
8,396 KB
testcase_17 AC 365 ms
8,396 KB
testcase_18 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

struct UnionFind
{
  vector< int > data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return(false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return(true);
  }

  int find(int k)
  {
    if(data[k] < 0) return(k);
    return(data[k] = find(data[k]));
  }

  int size(int k)
  {
    return(-data[find(k)]);
  }
};

int main(){
  int N,Q;
  cin >> N >> Q;
  vector<int> A;
  map<int,int> mp;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    A.push_back(a);
    mp[i] = a;
  }
  sort(A.begin(),A.end());
  for(int i=0;i<Q;i++){
    int x,y;
    cin >> x >> y;
    x--;y--;
    if(mp[x]<=mp[y]){
      cout << 0 << endl;
      continue;
    }
    auto first = lower_bound(A.begin(),A.end(),mp[x]);
    auto last = upper_bound(A.begin(),A.end(),mp[y]);
    cout << (first-last) << endl;
  }
}
0