UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213173#584. t3KXG408962ms48196kbC++114.8kb2024-11-09 22:12:162024-11-09 23:26:48

answer

#include <cstdio>
using namespace std;
const long long mod = 1e9 + 7;
long long C[15][15];
void init() {
    C[0][0] = 1;
    for (int i = 1; i <= 10; i++) {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++) {
            C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
        }
    }
}
struct segmenttree {
    long long a[100010];
    struct node {
        long long val[12] = {};
        long long lazyadd = 0, lazyset = 0;
        bool lazy = false;
    } nodes[400010];
    void pushaddtag(int p, int l, int r, long long x) {
        if (x == 0) return;
        for (int i = 10; i >= 0; i--) {
            long long now = 1;
            for (int j = 1; j <= i; j++) {
                now = now * x % mod;
                nodes[p].val[i] = (nodes[p].val[i] + C[i][j] * now * nodes[p].val[i - j]) % mod;
            }
        }
        nodes[p].lazyadd = (nodes[p].lazyadd + x) % mod;
    }
    void pushsettag(int p, int l, int r, long long x) {
        long long now = 1;
        for (int i = 0; i <= 10; i++) {
            nodes[p].val[i] = now * (r - l + 1) % mod;
            now = now * x % mod;
        }
        nodes[p].lazyset = x;
        nodes[p].lazy = true;
        nodes[p].lazyadd = 0;
    }
    void pushup(int p) {
        for (int i = 0; i <= 10; i++) {
            nodes[p].val[i] = nodes[p << 1].val[i] + nodes[p << 1 | 1].val[i];
        }
    }
    void pushdown(int p, int l, int r) {
        // printf("pushdown %d [%d, %d] : %lld %lld\n", p, l, r, nodes[p].lazyadd, nodes[p].lazyset);
        int mid = (l + r) >> 1;
        if (nodes[p].lazy) {
            pushsettag(p << 1, l, mid, nodes[p].lazyset);
            pushsettag(p << 1 | 1, mid + 1, r, nodes[p].lazyset);
            nodes[p].lazyset = 0;
            nodes[p].lazy = false;
        }
        if (nodes[p].lazyadd) {
            pushaddtag(p << 1, l, mid, nodes[p].lazyadd);
            pushaddtag(p << 1 | 1, mid + 1, r, nodes[p].lazyadd);
            nodes[p].lazyadd = 0;
        }
    }
    void build(int p, int l, int r) {
        nodes[p].lazyadd = nodes[p].lazyset = 0;
        nodes[p].lazy = false;
        if (l == r) {
            nodes[p].val[0] = 1;
            for (int i = 1; i <= 10; i++) {
                nodes[p].val[i] = nodes[p].val[i - 1] * a[l] % mod;
            }
            return;
        }
        int mid = (l + r) >> 1;
        build(p << 1, l, mid);
        build(p << 1 | 1, mid + 1, r);
        pushup(p);
    }
    void modifyadd(int p, int l, int r, int L, int R, long long x) {
        if (L <= l && r <= R) {
            pushaddtag(p, l, r, x);
            return;
        }
        pushdown(p, l, r);
        int mid = (l + r) >> 1;
        if (L <= mid) {
            modifyadd(p << 1, l, mid, L, R, x);
        }
        if (R > mid) {
            modifyadd(p << 1 | 1, mid + 1, r, L, R, x);
        }
        pushup(p);
    }
    void modifyset(int p, int l, int r, int L, int R, long long x) {
        if (L <= l && r <= R) {
            pushsettag(p, l, r, x);
            return;
        }
        pushdown(p, l, r);
        int mid = (l + r) >> 1;
        if (L <= mid) {
            modifyset(p << 1, l, mid, L, R, x);
        }
        if (R > mid) {
            modifyset(p << 1 | 1, mid + 1, r, L, R, x);
        }
        pushup(p);
    }
    long long query(int p, int l, int r, int L, int R, long long x) {
        if (L <= l && r <= R) {
            return nodes[p].val[x];
        }
        pushdown(p, l, r);
        int mid = (l + r) >> 1;
        long long ans = 0;
        if (L <= mid) {
            ans += query(p << 1, l, mid, L, R, x);
        }
        if (R > mid) {
            ans += query(p << 1 | 1, mid + 1, r, L, R, x);
        }
        return (ans % mod + mod) % mod;
    }
    void print(int p, int l, int r, int option = 10) {
        printf("%d [%d, %d] [%lld, %lld] : ", p, l, r, nodes[p].lazyadd, nodes[p].lazyset);
        for (int i = 0; i <= option; i++) {
            printf("%lld ", nodes[p].val[i]);
        }
        printf("\n");
        if (l == r) return;
        int mid = (l + r) >> 1;
        print(p << 1, l, mid, option);
        print(p << 1 | 1, mid + 1, r, option);
    }
} sgt;
int n, m, opt, l, r;
long long x;
int main() {
    init();
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &sgt.a[i]);
    }
    sgt.build(1, 1, n);
    // sgt.print(1, 1, n);
    // printf("\n");
    for (int i = 1; i <= m; i++) {
        scanf("%d%d%d%lld", &opt, &l, &r, &x);
        if (opt == 1) {
            sgt.modifyadd(1, 1, n, l, r, x);
        } else if (opt == 2) {
            sgt.modifyset(1, 1, n, l, r, x);
        } else {
            printf("%lld\n", sgt.query(1, 1, n, l, r, x));
        }
        // sgt.print(1, 1, n);
        // printf("\n");
    }
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 47424kb

input:

458 823
14431 9895 11970 15308 2575 20181 709 27999 12992 18884 11061 16281 5044 28990 25092 28337 3...

output:

806084096
581212945
581509507
903754571
381316325
789203673
218884232
377354153
741787988
89040104
9...

result:

wrong answer 2nd lines differ - expected: '117884357', found: '581212945'

Test #2:

score: 0
Wrong Answer
time: 11ms
memory: 47420kb

input:

481 526
8409 14498 18636 10027 24362 32458 17986 17730 11956 19192 2193 1034 29317 19284 16210 26242...

output:

867105097
717265913
288311190
320452351
133
433501333
863460013
216488030
788660511
611630662
471106...

result:

wrong answer 6th lines differ - expected: '498037408', found: '433501333'

Test #3:

score: 10
Accepted
time: 1190ms
memory: 48196kb

input:

100000 100000
15247 4194 9619 4532 22058 2667 21549 16652 25327 12018 13395 11426 7243 11714 22904 2...

output:

54433
544457741
352487648
82525935
532381851
235929450
38218
30045720
19138
459644406
33559
30953524...

result:

ok 33327 lines

Test #4:

score: 10
Accepted
time: 1168ms
memory: 48192kb

input:

100000 100000
6264 26207 28424 24165 4852 20798 5803 18679 24588 12238 25786 28622 19900 101 25922 2...

output:

18923
13111195
41716
34447
32091
80654
731180277
9973
523560023
19797
159789457
695071461
3136
95363...

result:

ok 33328 lines

Test #5:

score: 10
Accepted
time: 1604ms
memory: 48196kb

input:

100000 100000
15043 9299 7163 25384 24996 3803 24356 12466 22073 12987 8931 14997 3951 32704 23076 8...

output:

754347097
6296
588341566
325967942
180064833
683
831351544
63953
57030
17635
175222109
5280
57193
32...

result:

ok 33349 lines

Test #6:

score: 10
Accepted
time: 1181ms
memory: 48196kb

input:

100000 100000
14736 16956 19864 23894 29403 5507 12182 6188 17192 14440 18618 3970 15396 15037 23334...

output:

17008
73008
935797904
16519312
15383
25232
236856418
75334
25854
46510
797344028
517157465
595936107...

result:

ok 33304 lines

Test #7:

score: 0
Wrong Answer
time: 593ms
memory: 47812kb

input:

50000 50000
17799 29763 25337 21321 1391 31852 27418 28753 18524 14044 15976 18893 12274 22834 11348...

output:

19498
473297203
695948777
859588389
50630760
830518509
369627246
635248988
328502296
156223916
74697...

result:

wrong answer 4th lines differ - expected: '299749756', found: '859588389'

Test #8:

score: 0
Wrong Answer
time: 671ms
memory: 47812kb

input:

50000 50000
10654 14956 14287 25326 8102 30579 11682 23553 272 22672 14460 30241 13026 12738 4912 72...

output:

717018991
140916081
668632104
537214647
978664504
424812511
10388
4939
283493752
941592478
581312372...

result:

wrong answer 3rd lines differ - expected: '273712387', found: '668632104'

Test #9:

score: 0
Wrong Answer
time: 1389ms
memory: 48124kb

input:

90000 90000
29538 28214 24706 30393 27759 9002 13458 10243 15713 14881 10630 5593 7942 24578 29370 1...

output:

738835738
738703020
3888
402391875
37270
872563699
273399892
807398793
365897262
176491710
93280847
...

result:

wrong answer 10th lines differ - expected: '255303782', found: '176491710'

Test #10:

score: 0
Wrong Answer
time: 1151ms
memory: 48196kb

input:

100000 100000
23515 49 31372 25112 16779 21279 30735 32743 14678 15189 1763 23114 32215 14873 20487 ...

output:

576735050
562509678
553431297
662173102
348894296
478400370
879269281
684402470
389558468
1679282
16...

result:

wrong answer 5th lines differ - expected: '515338212', found: '348894296'