QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#377301#8112. Pastry shopSolitaryDream#WA 14ms50464kbC++171.6kb2024-04-05 12:02:362024-04-05 12:02:36

Judging History

This is the latest submission verdict.

  • [2024-04-05 12:02:36]
  • Judged
  • Verdict: WA
  • Time: 14ms
  • Memory: 50464kb
  • [2024-04-05 12:02:36]
  • 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) {
        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: 14ms
memory: 50460kb

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: 50464kb

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:

443691
256841
44741
75041
443691
125541
297241
226541
367941
317441
489141
130591
120491
398241
105341
64941
479041
362891
211391
236641
80091
7003
443691
44741
408341
246741
347741
433591
34641
120491
484091
352791
64941
49791
494191
307341
125541
191191
261891
29591
443691
494191
453791
64941
5484...

result:

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