結果

問題 No.2710 How many more?
ユーザー porkleoiporkleoi
提出日時 2024-03-31 14:07:06
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 4,650 bytes
コンパイル時間 3,054 ms
コンパイル使用メモリ 256,444 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-03-31 14:07:14
合計ジャッジ時間 7,461 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 267 ms
6,676 KB
testcase_03 AC 147 ms
6,676 KB
testcase_04 AC 118 ms
7,680 KB
testcase_05 AC 85 ms
6,676 KB
testcase_06 AC 101 ms
7,160 KB
testcase_07 AC 101 ms
6,676 KB
testcase_08 AC 77 ms
6,676 KB
testcase_09 AC 213 ms
6,908 KB
testcase_10 AC 119 ms
6,676 KB
testcase_11 AC 202 ms
6,676 KB
testcase_12 AC 272 ms
7,552 KB
testcase_13 AC 301 ms
8,064 KB
testcase_14 AC 295 ms
8,064 KB
testcase_15 AC 319 ms
8,064 KB
testcase_16 AC 293 ms
8,064 KB
testcase_17 AC 294 ms
8,064 KB
testcase_18 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i <= (ll)(n); i++)
#define rep3(i, s, n, d) for (ll i = s; i <= (ll)(n); i += d)
#define rep4(i, s, n, d) for (ll i = s; i >= (ll)(n); i += d)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<vvc> vvvc;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<vvvll> vvvvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<bool> vb;
typedef vector<vd> vvb;
typedef vector<vvd> vvvb;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<vpi> vvpi;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef tuple<int, int, int> tui3;
typedef tuple<ll, ll, ll> tull3;
typedef priority_queue<int, vector<int>, greater<int>> pqi;
typedef priority_queue<vi, vector<vi>, greater<vi>> pqvi;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqll;
typedef priority_queue<vll, vector<vll>, greater<vll>> pqvll;
typedef priority_queue<pll, vector<pll>, greater<pll>> pqpll;
typedef priority_queue<pll, vector<pll>, less<pll>> rpqpll;
typedef priority_queue<int, vector<int>, less<int>> rpqi;
typedef priority_queue<vi, vector<vi>, less<vi>> rpqvi;
typedef priority_queue<tui3, vector<tui3>, greater<tui3>> pqtui3;
typedef priority_queue<tui3, vector<tui3>, less<tui3>> rpqtui3;
typedef priority_queue<tull3, vector<tull3>, greater<tull3>> pqtull3;
typedef priority_queue<tull3, vector<tull3>, less<tull3>> rpqtull3;
#define yes(ans) if(ans)cout << "yes"<< endl; else cout << "no" << endl
#define Yes(ans) if(ans)cout << "Yes"<< endl; else cout << "No" << endl
#define YES(ans) if(ans)cout << "YES"<< endl ;else cout << "NO" << endl
#define printv(vec) {rep(i, vec.size()) cout << vec[i] << ' '; cout << endl;}
#define printvv(vec) rep(i, vec.size()) {rep(j, vec[i].size()) cout << vec[i][j] << ' '; cout << endl;};
#define printvvv(vec) rep(i, vec.size()) { rep(j, vec[i].size()) { rep(k, vec[i][j].size()) cout << vec[i][j][k] << ' '; cout << "	"; }cout << endl; };
#define all1(x) x.begin(),x.end()
#define all2(x) x.rbegin(), x.rend()
#define so(x) sort(all1(x))
#define re(x) reverse(all1(x))
#define rso(x) sort(all2(x))
#define vco(x, a) count(all1(x), a)
#define per(x) next_permutation(all1(x))
#define iINF 2147483647
#define llINF 9223372036854775807
#define INF 1000000000000000000
#define mod 998244353
#define mod2 1000000007

template <typename X>
struct SegTree {
    using FX = function<X(X, X)>; // X•X -> X となる関数の型
    int n;
    FX fx;
    const X ex;
    vector<X> dat;
    SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) {
        int x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }
    void set(int i, X x) { dat[i + n - 1] = x; }
    void build() {
        for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
    }
    void update(int i, X x) {
        i += n - 1;
        dat[i] += x;
        while (i > 0) {
            i = (i - 1) / 2;  // parent
            dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }
    X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    X query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return ex;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return fx(vl, vr);
        }
    }
};

int main() {
    // アルゴリズム一覧を見る
    // 嘘解法ですか
    ll n, q; cin >> n >> q;
    vll vec(n);
    rep(i, n) cin >> vec[i];
    vll list(n);
    rep(i, n) list[i] = vec[i];
    so(list);
    list.erase(unique(all1(list)), list.end());
    rep(i, n) vec[i] = lower_bound(all1(list), vec[i])-list.begin();
    auto fx = [](ll x1, ll x2) -> ll {return x1+x2;};
    SegTree<ll> seg(n, fx, 0);
    rep(i, n) seg.update(vec[i], 1);
    // printv(vec);
    while(q--){
        ll x, y; cin >> x >> y;
        x--, y--;
        cout << seg.query(vec[y]+1, vec[x]) << endl;
    }
}
0