QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#731484#8951. 澡堂forgotmyhandle0 709ms422332kbC++145.3kb2024-11-10 04:51:452024-11-10 04:51:45

Judging History

This is the latest submission verdict.

  • [2024-11-10 04:51:45]
  • Judged
  • Verdict: 0
  • Time: 709ms
  • Memory: 422332kb
  • [2024-11-10 04:51:45]
  • Submitted

answer

#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;
const int inf = 0x7ffffffffffffff;
ostream& operator<<(ostream& out, __int128 x) {
    if (x == 0) {
        out << "0";
        return out;
    }
    bool neg = (x < 0);
    x = (x < 0) ? -x : x;
    string str;
    while (x) str += (char)('0' + x % 10), x /= 10;
    reverse(str.begin(), str.end());
    if (neg) 
        str = '-' + str;
    out << str;
    return out;
}
int n, m, q, T;
int a[1000005], stk[1000005], sz;
struct Data_Structure {
    int r, n;
    __int128 ans;
    vector<signed> tor[20];
    vector<__int128> a, val[20];
    void ini(int x) {
        r = x, n = a.size();
        a.emplace_back(inf);
        for (__int128 i = 0, c = inf; i < n; i++) a[i] = i * T - a[i], c = min(c, a[i]), ans += c;
        for (int i = 0; i < 20; i++) val[i].resize(n + 1), tor[i].resize(n + 1);
        tor[0][n] = stk[sz = 0] = n;
        for (int i = n - 1; ~i; i--) {
            while (sz && a[stk[sz]] > a[i]) --sz;
            val[0][i] = a[i] * (stk[sz] - i), tor[0][i] = stk[sz];
            stk[++sz] = i;
        }
        for (int i = 1; i < 20; i++) {
            for (int j = 0; j <= n; j++) {
                tor[i][j] = tor[i - 1][tor[i - 1][j]];
                val[i][j] = val[i - 1][j] + val[i - 1][tor[i - 1][j]];
            }
        }
    }
    pair<__int128, __int128> f(int L, int R, __int128 x, int v = 0) {
        L = L / m + (L % m > r);
        R = R / m - (R % m < r);
        if (L > R) 
            return make_pair(x, (R - L + 1) * v * T);
        // cout << r << " " << L << " " << R << " " << x << "\n";
        int q = L, p = R + 1;
        if (a[L] <= x) 
            p = L;
        else {
            for (int i = 19; ~i; i--) {
                if (tor[i][q] > R) 
                    continue;
                if (a[tor[i][q]] <= x) 
                    p = tor[i][q];
                else 
                    q = tor[i][q];
            }
        }
        // cout << p << "\n";
        __int128 ret;
        ret = (p - L) * x;
        for (int i = 19; ~i; i--) {
            if (tor[i][p] <= R) 
                ret += val[i][p], p = tor[i][p];
        }
        // cout << p << " p\n";
        ret += (R - p + 1) * a[p];
        ret += (R - L + 1) * v * T;
        // cout << x << " " << a[p] << "\n";
        // cout << min(x, p <= r ? a[p] : inf) << " " << ret << "\n";
        return make_pair(min(x, p <= r ? a[p] : inf), ret);
    }
} ds[5];
__int128 bans;
int V[5];
void fv(__int128& s, __int128& p, __int128 v) { (p <= v) ? (s += p) : (p = v, s += v); }
signed main() {
    // freopen("dp.in", "r", stdin);
    // freopen("dp.out", "w", stdout);
    cin >> n >> m >> q >> T;
    for (int i = 0; i < n; i++) cin >> a[i], ds[i % m].a.emplace_back(a[i]), bans += (i / m) * T - a[i];
    for (int i = 0; i < m; i++) ds[i].ini(i);
    while (q--) {
        int x, v;
        __int128 tmp = bans, c;
        __int128 ans = 0;
        cin >> x >> v, --x;
        bans += a[x], bans -= v;
        int y = lower_bound(a, a + n, v) - a;
        y -= (y > x);
        // cout << x << " " << y << " x y\n";
        if (x == y) {
            for (int i = 0; i < m; i++) x % m != i ? (ans += ds[i].ans) : 0;
            pair<__int128, __int128> p = ds[x % m].f(0, x - 1, inf);
            c = p.first, ans += p.second;
            fv(ans, c, (x / m) * T - v);
            p = ds[x % m].f(x + 1, n - 1, c);
            ans += p.second;
        } else if (x < y) {
            for (int i = 0; i < m - 1; i++) {
                pair<__int128, __int128> p = ds[i].f(0, x - 1, inf); ans += p.second;
                p = ds[i + 1].f(x + 1, y, p.first); c = p.first; ans += p.second;
                if (y % m == i) 
                    fv(ans, c, (y / m) * T - v);
                p = ds[i].f(y + 1, n - 1, c); ans += p.second;
            }
            // cout << "----------------------------\n";
            pair<__int128, __int128> p = ds[m - 1].f(0, x - 1, inf); ans += p.second;
            p = ds[0].f(x + 1, y, p.first + T); c = p.first; ans += p.second;
            if (y % m == m - 1) 
                fv(ans, c, (y / m + 1) * T - v);
            p = ds[m - 1].f(y + 1, n - 1, c - T); ans += p.second;
            ans -= T * ((y + 1) / m - x / m);
        } else {
            for (int i = 1; i < m; i++) {
                pair<__int128, __int128> p = ds[i].f(0, y - 1, inf); c = p.first, ans += p.second;
                if (y % m == i) 
                    fv(ans, c, (y / m) * T - v);
                p = ds[i - 1].f(y, x - 1, c); ans += p.second;
                p = ds[i].f(x + 1, n - 1, p.first); ans += p.second;
            }
            pair<__int128, __int128> p = ds[0].f(0, y - 1, inf); c = p.first, ans += p.second;
            if (y % m == 0) 
                fv(ans, c, (y / m) * T - v);
            p = ds[m - 1].f(y, x - 1, c - T, 1); ans += p.second;
            p = ds[0].f(x + 1, n - 1, p.first + T); ans += p.second;
            // ans += T * ((x - 1) / m - (y / m - (y % m < m - 1)) + 1);
        }
        // cout << bans << " " << ans << "\n";
        cout << bans - ans << "\n";
        // cout << bans - ans << " asdfasdfasdf\n";
        bans = tmp;
    }
    return 0;
}
/*
10 3 1 11
1 1 2 4 6 9 9 11 14 25 
5 20
*/

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 6252kb

input:

1000 5 1000 1969617
59993 133807 154199 240894 438118 483699 540258 892751 922552 1049554 1092961 1153394 1287745 1315664 1372758 1550447 1634967 1817853 1825455 2023239 2064188 2117896 2250036 2453036 2492474 2794776 2917935 3047993 3153958 3163156 3237767 3443614 3664074 3716235 3801008 3822067 40...

output:

145473107761
145400375427
145403718605
145444938654
145438908460
145436948885
145405212826
145454120934
145460664260
145458475414
145433391640
145459823384
145401672860
145361079139
145486629489
145451768180
145426177956
145368877047
145384484360
145392373415
145514759762
145437334277
145471143810
1...

result:

wrong answer 76th lines differ - expected: '145406660854', found: '132009672358'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 20
Accepted
time: 475ms
memory: 418320kb

input:

1000000 1 100000 1165
83 197 266 277 299 529 538 601 629 760 792 1081 1208 1211 1387 1726 1873 1932 2198 2437 2448 2584 2715 2813 3113 3169 3207 3386 3934 4013 4032 4057 4137 4213 4396 4666 4754 4786 4856 4917 4966 5054 5124 5151 5196 5505 5548 5583 5730 5763 6031 6161 6169 6372 6446 6517 6712 6744 ...

output:

532526465394304
532526382684731
532526432382169
532526335149396
532526336776485
532526441654485
532526419072018
532526448365904
532526461590885
532526446716107
532526451559614
532526448428416
532526467783803
532526436578785
532526455446447
532526418608776
532526437618228
532526421765463
532526361938...

result:

ok 100000 lines

Test #7:

score: 20
Accepted
time: 478ms
memory: 419312kb

input:

1000000 1 100000 320
81 176 196 266 277 418 437 447 561 667 671 686 708 916 945 987 1077 1147 1343 1447 1459 1622 1739 1821 1907 2052 2211 2334 2483 2502 2553 2681 2879 2899 2996 3003 3075 3089 3141 3197 3312 3411 3450 3488 3525 3711 3870 4033 4066 4103 4216 4290 4341 4406 4500 4578 4600 4655 4697 4...

output:

110078125101649
110078095701794
110078065549730
110078084700891
110078055599406
110078147872941
110078125921229
110078050034681
110078131570282
110078020684010
110078081392840
110078123741061
110078124999461
110078092777746
110078093138994
110078104230505
110078088736720
110078130160314
110078088020...

result:

ok 100000 lines

Test #8:

score: 0
Wrong Answer
time: 517ms
memory: 421184kb

input:

1000000 1 100000 6
1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97 103 109 115 121 127 133 139 145 151 157 163 169 175 181 187 193 199 205 211 217 223 229 235 241 247 253 259 265 271 277 283 289 295 301 307 313 319 325 331 337 343 349 355 361 367 373 379 385 391 397 403 409 415 421 427 433 439 445 ...

output:

3920278
5120931
5195628
3935678
3984270
4914996
4387142
4869807
4500847
4365952
4714573
4054733
5130939
5651949
4377906
4131668
4175877
4754648
3828974
4813374
4254207
4764654
3583594
4423015
5103684
3833784
4496266
3035308
4258485
3647444
3834702
4660842
5211607
5301240
4468265
4818677
5247084
4613...

result:

wrong answer 1st lines differ - expected: '5553833', found: '3920278'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 709ms
memory: 422332kb

input:

1000000 5 100000 1887
112 168 223 393 535 558 577 631 631 678 682 1043 1099 1268 1337 1396 1437 1472 1510 1587 1804 1984 2013 2290 2294 2392 2474 2547 2694 2717 2742 2841 2880 2906 2985 3030 3047 3064 3108 3275 3375 3440 3451 3488 3950 3957 3963 4047 4086 4335 4378 4448 4490 4544 4622 4864 4875 4897...

output:

138785143191754
138785158412509
138785225283652
138785104800924
138785118976960
138785112934741
138785059838322
138785084952748
138785129256978
138785072292366
138785090484906
138785174307446
138785204546881
138785189045551
138785131284055
138785130779155
138785104455009
138785163776264
138785127154...

result:

wrong answer 29026th lines differ - expected: '138785157028503', found: '125342497426581'

Subtask #6:

score: 0
Skipped

Dependency #3:

0%