QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377310#8112. Pastry shopSolitaryDream#WA 13ms50496kbC++171.6kb2024-04-05 12:12:382024-04-05 12:12:39

Judging History

This is the latest submission verdict.

  • [2024-04-05 12:12:39]
  • Judged
  • Verdict: WA
  • Time: 13ms
  • Memory: 50496kb
  • [2024-04-05 12:12:38]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int N = 1e6 + 10;
int n, m, t[N];
int fa[N], sm[N], ans[N];
vector<pii> ev[N];
vector<int> que[N];
inline int Updiv(int x, int y) {
    return (x + y - 1) / y;
}
inline int Ask(int x) {
    return fa[x] >= 0 ? fa[x] = Ask(fa[x]) : x;
}

int A, B;  // current ans = A i + b
inline void Append(int x, int qu) {
    int rt = Ask(x);
    int si = -fa[rt];
    A += ((0 + si - 1) * si / 2) * qu;
    B += (si * t[x] - sm[rt]) * qu;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> t[i];
        if (t[i] - t[i - 1] < N) ev[t[i] - t[i - 1]].push_back({i - 1, i});
    }
    t[n + 1] = 1e18;
    for (int i = 1, x; i <= m; ++i) {
        cin >> x;
        que[x].push_back(i);
    }
    for (int i = 0; i <= n + 1; ++i) {
        fa[i] = -1;
        sm[i] = t[i];
    }
    for (int i = 0; i < N; ++i) {
        reverse(ev[i].begin(), ev[i].end());
        for (auto [x, y] : ev[i]) {
            int rx = Ask(x), ry = Ask(y);
            if (rx == ry) continue;
            Append(x, -1);
            Append(y, -1);
            fa[ry] += fa[rx];
            sm[ry] += sm[rx];
            fa[rx] = ry;
            Append(x, 1);
            int si = -fa[ry];
            int nxt = Updiv(t[ry + 1] - t[x], si);
            if (nxt < N) ev[nxt].push_back({x, ry + 1});
        }
        for (auto x : que[i]) {
            ans[x] = A * i + B;
        }
    }
    for (int i = 1; i <= m; ++i) cout << ans[i] << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 13ms
memory: 50496kb

input:

4 3
3 10 11 23
4 2 5

output:

4
1
6

result:

ok 3 number(s): "4 1 6"

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 50448kb

input:

100 100
1 3 5 5 6 10 10 12 13 14 14 14 14 15 16 17 18 19 19 19 20 22 24 26 26 29 29 30 30 30 31 31 32 32 33 36 37 38 40 40 42 43 43 46 47 47 48 49 55 56 59 60 61 61 63 64 64 65 65 66 67 68 72 74 76 76 77 79 80 80 81 81 81 81 82 82 82 84 84 84 85 87 87 88 89 89 89 90 90 91 91 91 92 93 94 95 99 100 10...

output:

443348
256498
44398
74698
443348
125198
296898
226198
367598
317098
488798
130248
120148
397898
104998
64598
478698
362548
211048
236298
79748
14098
443348
44398
407998
246398
347398
433248
34298
120148
483748
352448
64598
49448
493848
306998
125198
190848
261548
29248
443348
493848
453448
64598
544...

result:

wrong answer 1st numbers differ - expected: '439025', found: '443348'