QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#137698#1140. Distributing Candiespandapythoner#29 62ms15752kbC++203.3kb2023-08-10 16:42:242024-07-04 01:29:57

Judging History

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

  • [2024-07-04 01:29:57]
  • 评测
  • 测评结果:29
  • 用时:62ms
  • 内存:15752kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-10 16:42:24]
  • 提交

answer

#include <bits/stdc++.h>

#include "candies.h"

using namespace std;

#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

mt19937 rnd(24);
const ll inf = 1.5e9;

int n;
vector<ll> c;
int q;
vector<int> ql, qr;
vector<ll> qv;
vector<int> rs;

void solve_l0_rn() {
    rs.resize(n);
    vector<pair<ll, ll>> stck;
    stck.push_back(make_pair(0, inf));
    stck.reserve(q);
    for (int i = 0; i < q; i += 1) {
        ll v = qv[i];
        ll x = abs(v);
        if (v == 0) {
            continue;
        }
        if (v >= 0) {
            while (x > 0) {
                auto f = stck.back();
                stck.pop_back();
                if (f.second > x) {
                    f.second -= x;
                    f.first += x;
                    x = 0;
                    stck.push_back(f);
                    break;
                } else if (stck.empty()) {
                    f.first += f.second;
                    f.second = 0;
                    x = 0;
                    stck.push_back(f);
                    break;
                } else {
                    x -= f.second;
                    stck.back().first += f.first + f.second;
                }
            }
        } else {
            ll sm = 0;
            while (x > 0) {
                auto f = stck.back();
                stck.pop_back();
                if (f.first > x) {
                    f.first -= x;
                    stck.push_back(f);
                    sm += x;
                    x = 0;
                    break;
                } else if (stck.empty()) {
                    f.second += f.first;
                    f.first = 0;
                    x = 0;
                    stck.push_back(f);
                    break;
                } else {
                    x -= f.first;
                    sm += f.first + f.second;
                }
            }
            if (sm > 0) {
                stck.push_back(make_pair(0, sm));
            }
        }
    }
    vector<pair<ll, ll>> bbr;
    bbr.reserve((int)stck.size() * 2 + 1);
    ll sm = 0;
    ll pos = 0;
    bbr.push_back(make_pair(pos, sm));
    while (!stck.empty()) {
        auto f = stck.back();
        stck.pop_back();
        pos += f.first;
        sm += f.first;
        if (bbr.back().first != pos) {
            bbr.push_back(make_pair(pos, sm));
        }
        pos += f.second;
        if (bbr.back().first != pos) {
            bbr.push_back(make_pair(pos, sm));
        }
    }
    for (int i = 0; i < n; i += 1) {
        ll ps = c[i];
        int j = upper_bound(all(bbr), make_pair(ps, inf * 5)) - bbr.begin();
        auto [ps0, sm0] = bbr[j - 1];
        auto [ps1, sm1] = bbr[j];
        ll val = ((ps1 - ps) * sm0 + (ps - ps0) * sm1) / (ps1 - ps0);
        rs[i] = val;
    }
}

vector<int> distribute_candies(vector<int> _c, vector<int> _l, vector<int> _r, vector<int> _v) {
    n = _c.size();
    q = _l.size();
    c.resize(n);
    for (int i = 0; i < n; i += 1) {
        c[i] = _c[i];
    }
    ql.resize(q);
    qr.resize(q);
    qv.resize(q);
    for (int i = 0; i < q; i += 1) {
        ql[i] = _l[i];
        qr[i] = _r[i];
        qv[i] = _v[i];
    }
    solve_l0_rn();
    return rs;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 3
Accepted
time: 0ms
memory: 3808kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
8
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
8
0 7 1
0 7 1
0 7 300000000
0 7 994967293
0 7 1
0 7 1000000000
0 7 1000000000
0 7 1000000000

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

result:

ok 3 lines

Test #2:

score: -3
Wrong Answer
time: 0ms
memory: 4072kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
10
283 43634 101056 10340 6009 5133 30 2 3677888 210
10
1 8 26416
2 7 -51219
2 4 17793
3 7 75426
3 7 22307
1 1 60258
3 7 -29824
0 8 24839
2 8 -60304
0 1 -26411

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
0 0 9356 0 0 0 0 0 84084 0

result:

wrong answer 3rd lines differ - expected: '0 17223 0 0 0 0 0 0 0 0', found: '0 0 9356 0 0 0 0 0 84084 0'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 62ms
memory: 15612kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
200000
11408901 370732653 37843 28 53693 15782410 103 297546 1112427 170319071 26 1 6172 11614171 431 884673599 1 3 50085 154 57 28200 145886 898969 74758 72 845768 6 69787 11 31012465 55362 253 2363145 47186217 1103 19622 594 7867 1 4299 28130 48 4689582 12 ...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
11408901 370732653 37843 28 53693 15782410 103 297546 1112427 170319071 26 1 6172 11614171 431 884673599 1 3 50085 154 57 28200 145886 898969 74758 72 845768 6 69787 11 31012465 55362 253 2363145 47186217 1103 19622 594 7867 1 4299 28130 48 4689582 12 431 ...

result:

wrong answer 3rd lines differ - expected: '87153 87153 37843 28 53693 406...46468 9 1756 429030 247071 1629', found: '11408901 370732653 37843 28 53...3 9 1756 167542621 6854551 1629'

Subtask #3:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 0ms
memory: 3888kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
1000
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1...

result:

wrong answer 3rd lines differ - expected: '0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '1000 1000 1000 1000 1000 1000 ...0 1000 1000 1000 1000 1000 1000'

Subtask #4:

score: 29
Accepted

Test #16:

score: 29
Accepted
time: 0ms
memory: 4072kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
10
11 440 51 41 11 1 3 108 148 14
10
0 9 60
0 9 -9
0 9 -30
0 9 41
0 9 82
0 9 69
0 9 -79
0 9 -39
0 9 72
0 9 41

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
11 208 51 41 11 1 3 108 143 14

result:

ok 3 lines

Test #17:

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

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
1000
6 129 1 3 18 414 46 7 33 2 29 3 395 143 120 62 343 102 568 40 49 1 37 7 31 66 12 1 330 4 3 10 3 216 2 375 15 786 1 156 243 411 519 14 13 13 667 2 382 294 1 556 53 2 368 1 32 5 201 13 376 369 91 11 14 5 584 65 3 443 1 989 889 22 8 177 140 7 481 6 371 142 ...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 68 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

result:

ok 3 lines

Test #18:

score: 0
Accepted
time: 31ms
memory: 11160kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
2000
4207825 17466917 11 20 10489 1278831 48720 43780703 37223309 28500011 76204785 631 321 1650 263304936 1382 1900 1 225756109 43424483 21143 218062355 851196097 633450 141629084 11494 1 19 12133 5908567 7 26138 1131 152662321 18 787906 312 11463 393 109417...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
780706 1955314 11 20 10489 659178 48720 1955314 1955314 1955314 1955314 631 321 1650 1955314 1382 1900 1 1955314 1955314 21143 1955314 1955314 633450 1955314 11494 1 19 12133 1691591 7 26138 1131 1955314 18 659178 312 11463 393 659178 659178 1180 1955314 5...

result:

ok 3 lines

Test #19:

score: 0
Accepted
time: 21ms
memory: 7984kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
200000
401 38224076 293 9 2873526 11 356842329 318925257 728 169 749704686 13312846 8 6106116 4 379784 2 678669 1104 1268657 4579072 4620407 111763 117481111 81224 415449128 69269056 62353747 592 998 1135181 7443857 5706444 6 2 11 87555 3780941 72 8 407 11455...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
0 2136442 0 0 1590745 0 2136442 2136442 0 0 2136442 2136442 0 2136442 0 120361 0 120361 0 120361 2136442 2136442 24468 2136442 0 2136442 2136442 2136442 0 0 120361 2136442 2136442 0 0 0 260 2136442 0 0 0 0 2136442 0 0 0 1210287 2136442 2136442 0 2136442 0 ...

result:

ok 3 lines

Test #20:

score: 0
Accepted
time: 56ms
memory: 15640kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
200000
2 607917 87 7743038 272 19678 1 98 439 30 7898 262 2631381 23073 1026097 3698 6614 40 442324 168 3 43717 2370 1627514 8316081 398 1882901 1 42496 1 20135 29167 4032 6305 3894321 170 598 492 9418417 74322 2401853 52 42 31 145771 1720 63583 100 270 4249 ...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
2 56203 87 56203 148 12145 1 98 179 30 1408 148 56203 15540 56203 179 1408 40 56203 148 3 17751 179 56203 56203 179 56203 1 17751 1 12602 17751 179 1408 56203 148 179 179 56203 44280 56203 52 42 31 56203 179 33541 100 148 179 179 22 56203 56203 31 16 4 140...

result:

ok 3 lines

Test #21:

score: 0
Accepted
time: 57ms
memory: 15528kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
200000
11408901 370732653 37843 28 53693 15782410 103 297546 1112427 170319071 26 1 6172 11614171 431 884673599 1 3 50085 154 57 28200 145886 898969 74758 72 845768 6 69787 11 31012465 55362 253 2363145 47186217 1103 19622 594 7867 1 4299 28130 48 4689582 12 ...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
6103361 10904843 17 17 17 6103361 17 17 17 10904843 17 1 17 6103361 17 10904843 1 3 17 17 17 17 17 17 17 17 17 6 17 11 10904843 17 17 515937 10904843 17 17 17 17 1 17 17 17 515937 12 17 17 10904843 17 17 17 1 1 10904843 10904843 17 17 2 17 17 17 1 515937 1...

result:

ok 3 lines

Test #22:

score: 0
Accepted
time: 55ms
memory: 15752kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
200000
305263 281 10690 235 990069 52806771 124403 6 22 4901 18 4667 1944046 163079 358062945 167 258980 119407 434894470 51581578 40072504 9499993 3863 1269 1659 3 4 954 67916 18536 57095396 7 19561069 6 51690 595643338 5 902269 249 15 4526 1326847 3474 4157...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
305263 281 10690 235 990069 52806771 124403 6 22 4901 18 4667 1944046 163079 157437912 167 258980 119407 157437912 51581578 40072504 9499993 3863 1269 1659 3 4 954 67916 18536 57095396 7 19561069 6 51690 202403916 5 902269 249 15 4526 1326847 3474 41576 3 ...

result:

ok 3 lines

Test #23:

score: 0
Accepted
time: 57ms
memory: 15592kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
200000
36 596 2 302 1 22 7381829 295 411 221 267845 2822 635 22 45033 2 3 24 15 1 585 2832326 80 499271 110 192 6185 1752 302907 52967 3 3423576 5373 63 2196 35 113 1209 303 12 89 4572 4 13274 5867 10158 33467 3128 776575 59189 23 11698 637 3 330 1 1 18 3534 ...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
36 125 2 125 1 22 28253 125 125 70 28253 418 125 22 28253 2 3 24 15 1 125 28253 67 28253 67 67 1796 418 28253 28253 3 28253 1796 63 418 35 67 418 125 12 67 1655 4 5768 1796 3551 25961 418 28253 28253 23 4244 125 3 125 1 1 18 617 418 28253 28253 418 28253 1...

result:

ok 3 lines

Test #24:

score: 0
Accepted
time: 54ms
memory: 15608kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
200000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100...

result:

ok 3 lines

Subtask #5:

score: 0
Skipped

Dependency #1:

0%