結果

問題 No.2710 How many more?
ユーザー なーなー
提出日時 2024-03-31 15:27:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,500 bytes
コンパイル時間 1,701 ms
コンパイル使用メモリ 173,160 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-31 15:27:27
合計ジャッジ時間 5,831 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 236 ms
6,676 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 78 ms
6,676 KB
testcase_06 WA -
testcase_07 AC 99 ms
6,676 KB
testcase_08 AC 74 ms
6,676 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 185 ms
6,676 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// #include <atcoder/modint>
// #include <atcoder/lazysegtree>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for(int i = (s); i < (int)(n); i++)
#define printYN(check) cout << ((check)? "Yes" : "No") << endl
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define NUM 998244353
#define IMAX INT_MAX
#define LMAX LONG_MAX
using namespace std;
// using namespace atcoder;
// using mint = modint;
// using mint = modint998244353;
// using mint = modint1000000007;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using tii = tuple<int, int, int>;
using mii = map<int, int>;
// using Graph = vvi;
// Graph graph(n);
// vi dx = {-1, 0, 1, -1, 1, -1,  0, 1};
// vi dy = { 1, 1, 1,  0, 0, -1, -1,-1};

template<typename T> bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }

// snippet -> {UnionFind, dfs_reculsive, dfs_stack, is_prime, mypow, print_array, 
//             bfs_queue, digsum, binary_search, gcd, Dijkstra, bitsearch,
//             next_combination, binomial}
// -------------------------------------------------------------------------

int main() {
    int n, q;
    cin >> n >> q;
    vl a(n);
    rep(i, n) cin >> a[i];

    vl b(n);
    rep(i, n) b[i] = a[i];

    sort(all(a));

    auto isOK = [&](int index, ll key, vl& a) -> bool {
        if (a[index] >= key) return true;
        else return false;
    };
    auto binary_search = [&](ll key, vl& a) -> int {
        int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
        int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
    
        /* ok と ng のどちらが大きいかわからないことを考慮 */
        while (abs(ok - ng) > 1) {
            int mid = (ok + ng) / 2;
    
            if (isOK(mid, key, a)) ok = mid;
            else ng = mid;
        }
        return ok;
    };

    while(q > 0) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        int d = binary_search(b[x], a);
        int e = binary_search(b[y], a);

        cout << max(d-e-1, 0) << endl;
        q--;
    }
    return 0;
}
0