QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#797568#8951. 澡堂hhoppitree0 5ms3816kbC++142.4kb2024-12-03 13:32:532024-12-03 13:32:53

Judging History

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

  • [2024-12-03 13:32:53]
  • 评测
  • 测评结果:0
  • 用时:5ms
  • 内存:3816kb
  • [2024-12-03 13:32:53]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;

struct op {
    vector<long long> p;

    void append(long long x) {
        p.push_back(x);
    }

    void Init() {

    }

    long long query(int l, int r, long long &x, int D = 0) {
        if (l > r) return 0;
        pair<long long, long long> res = {0, x};
        for (int i = l; i <= r; ++i) {
            res.second = min(res.second, p[i] + D);
            res.first += res.second;
        }
        x = res.second;
        return res.first;
    }
} o[5];

int a[N];

signed main() {
    int n, m, q, T; scanf("%d%d%d%d", &n, &m, &q, &T);
    long long S = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        o[i % m].append(1ll * (i / m) * T - a[i]);
        S += 1ll * (i / m) * T - a[i];
    }
    for (int i = 0; i < m; ++i) {
        o[i].Init();
    }
    while (q--) {
        int x, y; scanf("%d%d", &x, &y), --x;
        long long res = S + a[x] - y;
        int t = lower_bound(a, a + n, y) - a;
        if (t <= x) {
            for (int i = 0; i < m; ++i) {
                long long now = 1e18;
                res -= o[i].query(0, (t - i) / m, now);
                if (t % m == i) {
                    now = min(now, 1ll * (t / m) * T - y);
                    res -= now;
                }
                for (int j = t; j < x; ++j) {
                    if ((j + 1) % m == i) res -= o[j % m].query(j / m, j / m, now, (j % m == m - 1 ? T : 0));
                }
                for (int j = x + 1; j < n; ++j) {
                    if (j % m == i) res -= o[i].query(j / m, j / m, now);
                }
            }
        } else {
            for (int i = 0; i < m; ++i) {
                long long now = 1e18;
                for (int j = i; j < x; j += m) {
                    res -= o[i].query(j / m, j / m, now);
                }
                for (int j = x + 1; j < t; ++j) {
                    if ((j - 1) % m == i) res -= o[j % m].query(j / m, j / m, now, (j % m == 0 ? -T : 0));
                }
                if ((t - 1) % m == i) {
                    now = min(now, 1ll * ((t - 1) / m) * T - y);
                    res -= now;
                }
                for (int j = t; j < n; ++j) {
                    if (j % m == i) res -= o[i].query(j / m, j / m, now);
                }
            }
        }
        printf("%lld\n", res);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 3816kb

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:

145473241568
145400375427
145403718605
145445072461
145439062659
145437082692
145405212826
145454361828
145460905154
145458535407
145433451633
145459957191
145401672860
145361079139
145486689482
145452009074
145426177956
145368877047
145384484360
145392373415
145514819755
145437488476
145471581928
1...

result:

wrong answer 1st lines differ - expected: '145473107761', found: '145473241568'

Subtask #2:

score: 0
Time Limit Exceeded

Test #6:

score: 0
Time Limit Exceeded

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:

532526465394387
532526382684731
532526432382252
532526335149396
532526336776485
532526441654568
532526419072101
532526448365987
532526461590968
532526446716190
532526451559697
532526448428499
532526467783886
532526436578868
532526455446530
532526418608859
532526437618311
532526421765546
532526361938...

result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Time Limit Exceeded

Test #36:

score: 0
Time Limit Exceeded

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:

138785143192147
138785158412902
138785225284045
138785104800924
138785118976960
138785112934741
138785059838322
138785084952748
138785129256978
138785072292366
138785090484906
138785174307981
138785204547104
138785189045663
138785131284055
138785130779155
138785104455009
138785163776376
138785127154...

result:


Subtask #6:

score: 0
Skipped

Dependency #3:

0%