QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#250867#7627. PhonyikefumyWA 0ms3824kbC++206.2kb2023-11-13 20:02:362023-11-13 20:02:36

Judging History

你现在查看的是最新测评结果

  • [2023-11-13 20:02:36]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2023-11-13 20:02:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
    if(x > y) {
        x = y;
        return true;
    } else return false;
}
template<class T> bool chmax(T& x, T y){
    if(x < y) {
        x = y;
        return true;
    } else return false;
}

// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )

#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )

#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)

// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)

// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)

// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)    
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = b - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = b - 1; i >= a; i -= c)

// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = b - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = b - 1; i >= (ll)(a); i -= c)

// for_earh
#define fore(e, v) for (auto&& e : v)

// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

template<class T, T(* op)(T, T), T(* e)()>
struct segment_tree {
private:
    int n, tn;
    vector<T> node;

public:
    segment_tree(int _n, vector<T> a = {}) : tn(_n) {
        n = 1;
        while (n < _n) n *= 2;

        node.resize(2 * n, e());
        if (!a.empty()) {
            for (int i = 0; i < (int)a.size(); i++) {
                update(i, a[i]);
            }
        }
    }

    void update(int i, T val) {
        i += n;
        node[i] = val;
        while (i / 2) {
            i /= 2;
            node[i] = op(node[i * 2], node[i * 2 + 1]);
        }
    }

    T get_val(int l, int r) {
        l += n;
        r += n;
        
        T lval = e(), rval = e();
        while (l < r) {
            if (l & 1) lval = op(lval, node[l++]);
            if (r & 1) rval = op(node[--r], rval);
            l /= 2, r /= 2;
        }

        return op(lval, rval);
    }

    template<class F>
    int right_search(int i, F f) {
        int ret = i, len = 1;
        i += n;
        T val = e();
        while (ret < n) {
            if (i & 1) {
                if (!f(op(val, node[i]))) break;
                val = op(val, node[i]);
                ret += len;
                i++;
            }
            len *= 2, i /= 2;
        }

        if (ret == n) return tn;

        while (len > 1) {
            len /= 2, i *= 2;
            if (f(op(val, node[i]))) {
                val = op(val, node[i]);
                ret += len;
                i++;
            }
        }

        return min(ret, tn);
    }

    template<class F>
    int left_search(int i, F f) {
        int ret = i, len = 1;
        i += n;
        T val = e();
        while (ret > 0) {
            if (i & 1) {
                i--;
                if (!f(op(node[i], val))) break;
                val = op(node[i], val);
                ret -= len;
            }
            len *= 2, i /= 2;
        }

        if (ret == 0) return 0;

        while (len > 1) {
            len /= 2, i = i * 2 + 1;
            if (f(op(node[i], val))) {
                val = op(node[i], val);
                ret -= len;
                i--;
            }
        }

        return ret;
    }
};

int op(int a, int b) {
    return a + b;
}

int e() {
    return 0;
}

int n, m;
ll k;
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    cin >> n >> m >> k;
    vector<ll> a(n), b(n), idx(n);
    vector<int128> tm(n);
    rep (i, n) {
        cin >> a[i];
        a[i] += linf;
        b[i] = a[i] % k;
    }

    sort(all(a));
    sort(all(b));
    map<ll, int> cnt;

    segment_tree<int, op, e> st(n);
    int128 qsum = 0;
    rrep (i, n) {
        ll c = a[i];
        int it = lower_bound(all(b), c % k) - b.begin() + cnt[c % k]++;
        tm[i] = qsum - (int128)(c / k) * (n - 1 - i) + st.get_val(upper_bound(all(b), c % k) - b.begin(), n);
        st.update(it, 1);
        idx[i] = it;
        qsum += c / k;
    }

    segment_tree<int, op, e> rem(3 * n);
    int l = n;
    int128 tsum = 0;
    rep (i, m) {
        char c;
        ll t;
        cin >> c >> t;
        if (c == 'C') {
            tsum += t;
            while (l - 1 >= 0) {
                if (tm[l - 1] > tsum) break;
                l--;
                rem.update(idx[l], 1);
                rem.update(idx[l] + n, 1);
                rem.update(idx[l] + 2 * n, 1);
            }
        } else {
            int x = t;
            ll ans = -linf;
            if (x > n - l) {
                ans += a[n - x];
            } else {
                int128 trem = tsum - tm[l];
                int128 dec = trem / (n - l);
                int it = rem.left_search(idx[l] + 2 * n + 1, [&](int val) {
                        return val < trem % (n - l) + x;
                    }) - 1;
                ans += a[l] - a[l] % k + b[it % n] - dec * k;
                if (a[l] % k < b[it % n]) ans -= k;
                if (it <= idx[l] + n) ans -= k;
            }
            cout << ans << '\n';
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3784kb

input:

3 5 5
7 3 9
A 3
C 1
A 2
C 2
A 3

output:

3
4
-1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

5 8 8
294 928 293 392 719
A 4
C 200
A 5
C 10
A 2
C 120
A 1
A 3

output:

294
200
191
0
-2

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3792kb

input:

100 100 233
5101 8001 6561 6329 6305 7745 4321 811 49 1121 3953 8054 8415 9876 6701 4097 6817 6081 495 5521 2389 2042 4721 8119 7441 7840 8001 5756 5561 129 1 5981 4801 7201 8465 7251 6945 5201 5626 3361 5741 3650 7901 2513 8637 3841 5621 9377 101 3661 5105 4241 5137 7501 5561 3581 4901 561 8721 811...

output:

6881
9161
4721
8200
2945
7647
7530
5291
5001
2042
4721
4721
6881
4097
7181
7218
7018
7018
811
6742
2561
6683
6103
6135
3581
5291
1485
5957
5393
2042
5303
5171
5205
4721
5084
4029
4097
4586
4816
4721
4698
2042
4535
4454
4603
4422
3581
4345
115
2042
4274
2042
4273
1485
4326
-17552

result:

wrong answer 7th lines differ - expected: '7531', found: '7530'