QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#138130#1140. Distributing Candiessomethingnew29 3925ms13468kbC++208.3kb2023-08-11 00:19:332023-08-11 00:19:34

Judging History

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

  • [2023-08-11 00:19:34]
  • 评测
  • 测评结果:29
  • 用时:3925ms
  • 内存:13468kb
  • [2023-08-11 00:19:33]
  • 提交

answer

//  ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
//  ➡ @roadfromroi ⬅
//  ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#define all(x) x.begin(), x.end()
using namespace std;
#include "candies.h"
struct segbeb1 {
    vector<array<int, 3>> ar;
    segbeb1(int n, int tpp = 0) {
        ar.clear();
        ar.push_back({n, 0, tpp});
    }
    vector<array<int, 3>> compress(vector<array<int, 3>> art) {
        vector<array<int, 3>> ar2;
        for (auto i : art) {
            if (!ar2.empty() and ar2.back()[2] == 1 and ar2.back()[1] + ar2.back()[0] == i[1] and i[2] == 1) {
                ar2.back()[0] += i[0];
            } else  if (!ar2.empty() and ar2.back()[2] == 0 and ar2.back()[1] == i[1] and i[2] == 0) {
                ar2.back()[0] += i[0];
            } else {
                ar2.push_back(i);
            }
        }
        return ar2;
    }
    void addx(int x) {
        vector<array<int, 3>> ar2;
        int lv = 0;
        for (auto &[cnt, lfvl, add] : ar) {
            lfvl += x;
            if (x > 0) {
                if (lv < lfvl) {
                    if (add == 1) {
                        lfvl = lv;
                        ar2.push_back({cnt, lfvl, add});
                    } else {
                        array<int, 3> lf, rg;
                        lf = {min(cnt, lfvl - lv), lv, 1};
                        ar2.push_back(lf);
                        if (cnt > lf[0]) {
                            rg = {cnt - lf[0], lfvl, 0};
                            ar2.push_back(rg);
                        }
                    }
                } else {
                    ar2.push_back({cnt, lfvl, add});
                }
            } else {
                if (lfvl < 0) {
                    if (add == 0) {
                        lfvl = 0;
                        ar2.push_back({cnt, lfvl, add});
                    } else {
                        array<int, 3> lf, rg;
                        lf = {min(cnt, -lfvl), 0, 0};
                        ar2.push_back(lf);
                        if (cnt > lf[0]) {
                            rg = {cnt - lf[0], 0, 1};
                            ar2.push_back(rg);
                        }
                    }
                } else {
                    ar2.push_back({cnt, lfvl, add});
                }
            }
            lv += cnt;
        }
        ar = compress(ar2);
        //for (auto i : ar)
        //    cout << i[0] << ' ' << i[1] << ' ' << i[2] << endl;
        //cout << endl;
    }
    int getv(int v) {
        int l = 0;
        for (auto i : ar) {
            if (l + i[0] > v) {
                return i[1] + (v - l) * i[2];
            }
            l += i[0];
        }
        exit(1);
    }
};
struct segbeb2 {
    vector<array<int, 3>> ar;
    int N;
    segbeb2() {
    }
    segbeb2(int n) {
        N = n;
        ar.clear();
        ar.push_back({n + 1, 0, 1});
    }
    vector<array<int, 3>> compress(vector<array<int, 3>> art) {
        vector<array<int, 3>> ar2;
        for (auto i : art) {
            if (!ar2.empty() and ar2.back()[2] == 1 and ar2.back()[1] + ar2.back()[0] == i[1] and i[2] == 1) {
                ar2.back()[0] += i[0];
            } else  if (!ar2.empty() and ar2.back()[2] == 0 and ar2.back()[1] == i[1] and i[2] == 0) {
                ar2.back()[0] += i[0];
            } else {
                ar2.push_back(i);
            }
        }
        return ar2;
    }
    void addx(int x) {
        vector<array<int, 3>> ar2;
        int lv = 0;
        for (auto &[cnt, lfvl, add] : ar) {
            lfvl += x;
            if (x > 0) {
                if (lfvl + cnt * add > N) {
                    if (add == 0) {
                        lfvl = N;
                        ar2.push_back({cnt, lfvl, add});
                    } else {
                        array<int, 3> lf, rg;
                        rg = {min(cnt, lfvl+cnt-N), N, 0};
                        if (cnt > rg[0]) {
                            lf = {cnt - rg[0], N - (cnt-rg[0]), 1};
                            ar2.push_back(lf);
                        }
                        ar2.push_back(rg);
                    }
                } else {
                    ar2.push_back({cnt, lfvl, add});
                }
            } else {
                if (lfvl < 0) {
                    if (add == 0) {
                        lfvl = 0;
                        ar2.push_back({cnt, lfvl, add});
                    } else {
                        array<int, 3> lf, rg;
                        lf = {min(cnt, -lfvl), 0, 0};
                        ar2.push_back(lf);
                        if (cnt > lf[0]) {
                            rg = {cnt - lf[0], 0, 1};
                            ar2.push_back(rg);
                        }
                    }
                } else {
                    ar2.push_back({cnt, lfvl, add});
                }
            }
            lv += cnt;
        }
        ar = compress(ar2);
        //for (auto i : ar)
        //    cout << i[0] << ' ' << i[1] << ' ' << i[2] << endl;
        //cout << endl;
    }
    int getv(int v) {
        int l = 0;
        for (auto i : ar) {
            if (l + i[0] > v) {
                return i[1] + (v - l) * i[2];
            }
            l += i[0];
        }
        while (1);
    }
};
vector<int> solveallon(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    segbeb1 beba(1e9 + 5);
    for (auto i : v) {
        beba.addx(i);
    }
    vector<int> res(c.size());
    for (int i = 0; i < c.size(); ++i) {
        res[i] = beba.getv(c[i]);
    }
    return res;
}
struct sqrtpart {
    segbeb2 beba;
    bool pus = 1;
    int CC;
    vector<int> vals;
    sqrtpart(int n, int c) {
        beba = segbeb2(c);
        vals.assign(n, 0);
        CC = c;
    };
    void trypush() {
        if (pus)
            return;
        pus = 1;
        for (auto &i : vals) {
            i = beba.getv(i);
        }
        beba = segbeb2(CC);
    }
    void givelr(int l, int r, int x) {
        trypush();
        for (int i = l; i < r; ++i) {
            vals[i] += x;
            vals[i] = min(vals[i], CC);
            vals[i] = max(vals[i], 0);
        }
    }
    void giveall(int x) {
        beba.addx(x);
        pus = 0;
    }
    vector<int> getel() {
        trypush();
        return vals;
    }
};
int K = 400;
int nxt(int v) {
    return (v+(K-1))/K*K;
}
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    int n = c.size();
    int be = 1;
    for (int i = 0; i < l.size(); ++i) {
        if (l[i] != 0 or r[i] != n- 1)
            be = 0;
    }
    if (be)
        return solveallon(c,l,r,v);
    vector<sqrtpart> a((n+(K-1)) / K, {K, c[0]});
    for (int i = 0; i < v.size(); ++i) {
        int lv = l[i], rg = r[i] + 1;
        if (lv % K != 0 and nxt(lv) <= rg) {
            a[lv / K].givelr(lv % K, K, v[i]);
            lv = nxt(lv);
        }
        while (lv + K <= rg) {
            a[lv / K].giveall(v[i]);
            lv += K;
        }
        if (lv != rg)
            a[lv / K].givelr(lv % K, rg % K, v[i]);
    }
    vector<int> res;
    for (auto &i : a) {
        for (auto j : i.getel())
            res.push_back(j);
    }
    while (res.size() > n)
        res.pop_back();
    return res;
    /**/
}
#ifdef __APPLE__

int main() {
    int n;
    assert(1 == scanf("%d", &n));
    std::vector<int> c(n);
    for(int i = 0; i < n; ++i) {
        assert(scanf("%d", &c[i]) == 1);
    }

    int q;
    assert(1 == scanf("%d", &q));
    std::vector<int> l(q), r(q), v(q);
    for(int i = 0; i < q; ++i) {
        assert(scanf("%d %d %d", &l[i], &r[i], &v[i]) == 3);
    }

    std::vector<int> ans = distribute_candies(c, l, r, v);

    for(int i = 0; i < (int)ans.size(); ++i) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", ans[i]);
    }
    printf("\n");
    fclose(stdout);
    return 0;
}
#endif
/*
5
5 5 5 5 5
3
2 4 1
1 5 2
3 3 3
 */

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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: 1ms
memory: 3768kb

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 0 0 0 0 0 0 0 0

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 3925ms
memory: 11332kb

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
87153 87153 243257 250497 325876 406667 525479 655951 766665 971468 1073487 1084603 1144515 1257294 1514842 1536484 1739854 1833903 1950484 1950484 2050477 2096517 2213442 2241808 2453123 2551636 2688712 2735237 2969818 2969818 3043755 3043755 3113712 3297...

result:

wrong answer 3rd lines differ - expected: '87153 87153 37843 28 53693 406...46468 9 1756 429030 247071 1629', found: '87153 87153 243257 250497 3258...1546 474919 429030 247071 16020'

Subtask #3:

score: 0
Time Limit Exceeded

Test #9:

score: 27
Accepted
time: 1ms
memory: 3796kb

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
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 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 ...

result:

ok 3 lines

Test #10:

score: 0
Accepted
time: 157ms
memory: 7884kb

input:

lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg
2000
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1...

output:

4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq
OK
1049802 936230 884511 204101 406074 550834 961642 2076245 1975297 2101513 2254310 1990108 1398298 1917785 2864344 2475931 2270774 401698970 402327667 402506418 401068637 399388438 398687119 398672863 397137012 397262070 396255448 395961553 394643443 394646...

result:

ok 3 lines

Test #11:

score: 0
Accepted
time: 68ms
memory: 6652kb

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
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 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 ...

result:

ok 3 lines

Test #12:

score: -27
Time Limit Exceeded

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:

Unauthorized output

result:


Subtask #4:

score: 29
Accepted

Test #16:

score: 29
Accepted
time: 1ms
memory: 3708kb

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: 1ms
memory: 3788kb

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: 60ms
memory: 10348kb

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: 25ms
memory: 6388kb

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: 90ms
memory: 13348kb

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: 93ms
memory: 13416kb

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: 87ms
memory: 13468kb

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: 88ms
memory: 13404kb

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: 80ms
memory: 13420kb

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%