QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#770596#7992. 【模板】线段树ToboWA 2768ms47664kbC++204.8kb2024-11-21 22:33:162024-11-21 22:33:16

Judging History

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

  • [2024-11-21 22:33:16]
  • 评测
  • 测评结果:WA
  • 用时:2768ms
  • 内存:47664kb
  • [2024-11-21 22:33:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

bool Memory_begin;

/*
 */

// template <int mod>
// unsigned int down(unsigned int x)
// {
//     return x >= mod ? x - mod : x;
// }
// template <int mod>
// struct Modint
// {
//     unsigned int x;
//     Modint() = default;
//     Modint(unsigned int x) : x(x) {}
//     friend istream &operator>>(istream &in, Modint &a) { return in >> a.x; }
//     friend ostream &operator<<(ostream &out, Modint a) { return out << a.x; }
//     friend Modint operator+(Modint a, Modint b) { return down<mod>(a.x + b.x); }
//     friend Modint operator-(Modint a, Modint b) { return down<mod>(a.x - b.x + mod); }
//     friend Modint operator*(Modint a, Modint b) { return 1ULL * a.x * b.x % mod; }
//     friend Modint operator/(Modint a, Modint b) { return a * ~b; }
//     friend Modint operator^(Modint a, int b)
//     {
//         Modint ans = 1;
//         for (; b; b >>= 1, a *= a)
//             if (b & 1)
//                 ans *= a;
//         return ans;
//     }
//     friend Modint operator~(Modint a) { return a ^ (mod - 2); }
//     friend Modint operator-(Modint a) { return down<mod>(mod - a.x); }
//     friend Modint &operator+=(Modint &a, Modint b) { return a = a + b; }
//     friend Modint &operator-=(Modint &a, Modint b) { return a = a - b; }
//     friend Modint &operator*=(Modint &a, Modint b) { return a = a * b; }
//     friend Modint &operator/=(Modint &a, Modint b) { return a = a / b; }
//     friend Modint &operator^=(Modint &a, int b) { return a = a ^ b; }
//     friend Modint &operator++(Modint &a) { return a += 1; }
//     friend Modint operator++(Modint &a, int)
//     {
//         Modint x = a;
//         a += 1;
//         return x;
//     }
//     friend Modint &operator--(Modint &a) { return a -= 1; }
//     friend Modint operator--(Modint &a, int)
//     {
//         Modint x = a;
//         a -= 1;
//         return x;
//     }
//     friend bool operator==(Modint a, Modint b) { return a.x == b.x; }
//     friend bool operator!=(Modint a, Modint b) { return !(a == b); }
// };
// const int mod = 1e9 + 7;
// typedef Modint<mod> mint;

const int mod = 1 << 20, all = mod - 1, N = 2e5 + 5;
int n, q;
unsigned a[N];
struct node
{
    unsigned sum[20], tag;
} st[N << 2];
#define lc cur << 1
#define rc cur << 1 | 1
void pushup(int cur)
{
    for (int i = 0; i < 20; i++)
        st[cur].sum[i] = 0;
    for (int i = 0; i < 20; i++)
        for (int j = 0; i + j < 20; j++)
            st[cur].sum[i + j] += st[lc].sum[i] * st[rc].sum[j],
                st[cur].sum[i + j] &= all;
}
void pushdown(int cur)
{
    unsigned tmp = st[cur].tag;
    st[cur].tag = 0;
    st[lc].tag += tmp, st[rc].tag += tmp;
    for (int i = 0; i < 20; i++)
    {
        unsigned coef = 1;
        for (int j = i + 1; j < 20; j++)
        {
            coef *= tmp;
            coef &= all;
            st[lc].sum[i] += st[lc].sum[j] * coef;
            st[lc].sum[i] &= all;
            st[rc].sum[i] += st[rc].sum[j] * coef;
            st[rc].sum[i] &= all;
        }
    }
}
void build(int cur, int l, int r)
{
    if (l == r)
    {
        st[cur].sum[0] = a[l];
        st[cur].sum[1] = 1;
        return;
    }
    int mid = l + r >> 1;
    build(lc, l, mid);
    build(rc, mid + 1, r);
    pushup(cur);
}
void update(int cur, int l, int r, int a, int b, unsigned x)
{
    if (a <= l and r <= b)
    {
        st[cur].tag += x;
        for (int i = 0; i < 20; i++)
        {
            unsigned coef = 1;
            for (int j = i + 1; j < 20; j++)
            {
                coef *= x;
                coef &= all;
                st[cur].sum[i] += st[cur].sum[j] * coef;
                st[cur].sum[i] &= all;
            }
        }
        return;
    }
    int mid = l + r >> 1;
    pushdown(cur);
    if (a <= mid)
        update(lc, l, mid, a, b, x);
    if (b > mid)
        update(rc, mid + 1, r, a, b, x);
    pushup(cur);
}
unsigned query(int cur, int l, int r, int a, int b)
{
    if (a > r or b < l)
        return 1;
    if (a <= l and r <= b)
        return st[cur].sum[0];
    int mid = l + r >> 1;
    pushdown(cur);
    return (query(lc, l, mid, a, b) * query(rc, mid + 1, r, a, b)) & all;
}

bool Memory_end;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cerr << (&Memory_end - &Memory_begin) / 1048576.0 << "MB" << '\n';

    cin >> n >> q;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    build(1, 1, n);
    while (q--)
    {
        int opt, l, r, x;
        cin >> opt >> l >> r;
        if (opt == 1)
        {
            cin >> x;
            update(1, 1, n, l, r, x);
        }
        else
            cout << query(1, 1, n, l, r) << '\n';
    }
}
/*
 */

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3724kb

input:

10 10
969575 741825 24903 1047319 450475 256145 1045323 479255 810659 768323
1 5 6 3034
2 1 10
2 1 9
2 1 4
1 3 6 126904
2 5 5
2 9 9
1 7 7 853094
1 4 9 1025178
2 5 8

output:

1045541
1012343
558151
580413
810659
527353

result:

ok 6 lines

Test #2:

score: -100
Wrong Answer
time: 2768ms
memory: 47664kb

input:

200000 200000
496015 180543 330721 874799 740427 144379 598057 795949 323465 87657 683935 748203 748665 288301 846003 33033 746029 132621 876629 361899 701297 373189 256151 723161 377571 54947 91151 855991 433965 73347 155081 314317 790527 705555 1035217 298963 604641 203865 230029 802437 720769 843...

output:

746709
564663
426791
840425
1018481
1037209
453323
604247
266401
914641
920163
463913
669971
18535
289873
993915
551299
146251
616687
448991
505679
636767
834025
479811
685349
608699
37829
938539
457025
132629
1047407
50839
957101
782245
43917
1038315
65739
524195
254653
748597
304683
904165
392857
...

result:

wrong answer 5th lines differ - expected: '762201', found: '1018481'