結果

問題 No.2710 How many more?
ユーザー MagentorMagentor
提出日時 2024-03-31 14:21:18
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 515 ms / 2,000 ms
コード長 2,506 bytes
コンパイル時間 5,534 ms
コンパイル使用メモリ 323,668 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-03-31 14:21:30
合計ジャッジ時間 11,766 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 412 ms
8,576 KB
testcase_03 AC 228 ms
8,832 KB
testcase_04 AC 179 ms
11,520 KB
testcase_05 AC 123 ms
7,552 KB
testcase_06 AC 151 ms
10,368 KB
testcase_07 AC 136 ms
6,548 KB
testcase_08 AC 112 ms
6,548 KB
testcase_09 AC 335 ms
9,984 KB
testcase_10 AC 178 ms
7,040 KB
testcase_11 AC 291 ms
6,548 KB
testcase_12 AC 452 ms
11,264 KB
testcase_13 AC 482 ms
12,032 KB
testcase_14 AC 480 ms
12,032 KB
testcase_15 AC 515 ms
12,032 KB
testcase_16 AC 479 ms
12,032 KB
testcase_17 AC 485 ms
12,032 KB
testcase_18 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, m ,n) for (int i = (m); i < (long long)(n); i++)
#define REP(i, n) for (long long i = 1; i < (long long)(n); i++)
typedef long long ll;
#define updiv(N,X) (N + X - 1) / X
#define l(n) n.begin(),n.end()
#define YesNo(Q) Q==1?cout<<"Yes":cout<<"No"
using P = pair<int, int>;
using mint = modint;
const int MOD = 998244353LL;
const ll INF = 999999999999LL;
vector<long long> fact, fact_inv, inv;
/*  init_nCk :二項係数のための前処理
    計算量:O(n)
*/
template <typename T>
void input(vector<T> &v){
 rep(i,v.size()){cin>>v[i];}
  return;
}
void init_nCk(int SIZE) {
    fact.resize(SIZE + 5);
    fact_inv.resize(SIZE + 5);
    inv.resize(SIZE + 5);
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < SIZE + 5; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
    }
}
/*  nCk :MODでの二項係数を求める(前処理 int_nCk が必要)
    計算量:O(1)
*/
long long nCk(int n, int k) {
    assert(!(n < k));
    assert(!(n < 0 || k < 0));
    return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll POW(ll a,ll n){
  long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}
int main() {
 int n,q;cin>>n>>q;
 vector<pair<ll,ll>> v(n);
 rep(i,n){cin>>v[i].first;v[i].second = i;}
 sort(l(v));
 vector<ll> w(n);map<ll,ll> idx;
 rep(i,n){
 	idx[v[i].second] = v[i].first;
 	w[i] = v[i].first;
 }
 //sort(l(w));
 //rep(i,w.size()){cout<<w[i]<<" ";}cout<<endl;
 rep(i,q){
 	int x,y;cin>>x>>y;x--;y--;
 	
 	int t = (int)(lower_bound(l(w),idx[x])-upper_bound(l(w),idx[y]));
 //	cout << idx[x] << " " << idx[y]<<endl;
 	if(idx[x]==idx[y]){cout<<0<<endl;continue;}
 	else if(idx[x]<idx[y]){cout<<0<<endl;continue;}
 	//cout << t << endl;
 	cout << max(t,0) << endl;
 }
}
0