QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#870028#9986. Shioriw4p3rTL 127ms16104kbC++203.8kb2025-01-25 14:29:002025-01-25 14:29:05

Judging History

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

  • [2025-01-25 14:29:05]
  • 评测
  • 测评结果:TL
  • 用时:127ms
  • 内存:16104kb
  • [2025-01-25 14:29:00]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define N 500010

int n, m;
ll a[N];
ll sum[N << 2], tadd[N << 2], tval[N << 2];
ll mn[N << 2];
int len[N << 2];

#define ls (x << 1)
#define rs (x << 1 | 1)
#define mid ((l + r) >> 1)
int st[N], top;

void pushup(int x) 
{
    sum[x] = sum[ls] + sum[rs];
    len[x] = len[ls] + len[rs];
    mn[x] = min(mn[ls], mn[rs]);
}

void push(int x, int tgadd, int tgval)
{
    if (tgval != -1)
    {
        sum[x] = 1LL * len[x] * tgval, mn[x] = tgval;
        tadd[x] = 0, tval[x] = tgval;
    }
    sum[x] += 1LL * len[x] * tgadd; mn[x] += tgadd;
    tadd[x] += tgadd;
}
void pushdown(int x)
{
    push(ls, tadd[x], tval[x]); push(rs, tadd[x], tval[x]);
    tadd[x] = 0, tval[x] = -1;
}



void build(int l, int r, int x)
{
    tadd[x] = 0, tval[x] = -1;
    if (l == r) {sum[x] = mn[x] = a[l]; len[x] = 1; return ;}
    build(l, mid, ls); build(mid + 1, r, rs);
    pushup(x);
}
void upd(int l, int r, int x, int ql, int qr, pair<int, int>tg)
{
    if (l == ql && r == qr) {push(x, tg.first, tg.second); return ;}

    pushdown(x);
    if (qr <= mid)upd(l, mid, ls, ql, qr, tg);
    else if (ql > mid)upd(mid + 1, r, rs, ql, qr, tg);
    else {upd(l, mid, ls, ql, mid, tg); upd(mid + 1, r, rs, mid + 1, qr, tg);}

    pushup(x);
}
ll qry(int l, int r, int x, int ql, int qr)
{
    if (l == ql && r == qr)return sum[x];
    pushdown(x);

    if (qr <= mid)return qry(l, mid, ls, ql, qr);
    else if (ql > mid)return qry(mid + 1, r, rs, ql, qr);
    else return qry(l, mid, ls, ql, mid) + qry(mid + 1, r, rs, mid + 1, qr);
}
void Find(int l, int r, int x, int ql, int qr)
{
    if (l == ql && r == qr){st[++ top] = x; return ;}
    pushdown(x);

    if (qr <= mid)Find(l, mid, ls, ql, qr);
    else if (ql > mid)Find(mid + 1, r, rs, ql, qr);
    else {Find(l, mid, ls, ql, mid), Find(mid + 1, r, rs, mid + 1, qr);}
}
void sol()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i ++)cin >> a[i];
    build(1, n, 1);

    while (m --)
    {
        int op;
        cin >> op;
        if (op == 1)
        {
            int l, r, v;
            cin >> l >> r >> v;
            upd(1, n, 1, l, r, {0, v});
        }
        else if (op == 2)
        {
            int l, r;
            cin >> l >> r;
            top = 0;
            Find(1, n, 1, l, r);
            priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>q;
            for (int i = 1; i <= top; i ++)q.push({mn[st[i]], st[i]});
            int ansv = 0; bool flag = 0;
            while (!q.empty())
            {
                int x = q.top().second; q.pop();
                // cout << "??:" << x << ' ' << len[x] << ' ' << mn[x] << endl;
                if (mn[x] == ansv) {flag = 1;}
                else if (mn[x] > ansv)
                {
                    if (flag) {++ ansv; flag = 0; q.push({mn[x], x}); continue;}
                    else break;
                }

                if (len[x] > 1)
                {
                    pushdown(x);
                    q.push({mn[ls], ls});
                    q.push({mn[rs], rs});
                }
            }

            if (flag) ++ ansv;
            // cout << "EE:" << l << ' ' << r << ' ' << ansv << endl;

            upd(1, n, 1, l, r, {ansv, -1});

        }
        else if (op == 3)
        {
            int l, r;
            cin >> l >> r;
            cout << qry(1, n, 1, l, r) << '\n';
        }
    }
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int T = 1;
    // cin >> T;
    while (T --) sol();

    return 0;
}

/*
 5 8
 0 7 2 1 0
 1 2 4 0
 2 1 3
 2 3 4
 3 1 3
 1 2 3 4
 3 1 4
 2 1 5
 3 2 5
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 8
0 7 2 1 0
1 2 4 0
2 1 3
2 3 4
3 1 3
1 2 3 4
3 1 4
2 1 5
3 2 5

output:

5
11
22

result:

ok 3 number(s): "5 11 22"

Test #2:

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

input:

1 1
0
1 1 1 0

output:


result:

ok 0 number(s): ""

Test #3:

score: 0
Accepted
time: 127ms
memory: 15928kb

input:

10 500000
0 0 0 0 0 0 0 0 0 0
3 2 9
2 4 10
2 2 7
2 7 9
3 1 1
3 5 8
1 5 10 0
3 1 9
3 5 9
2 2 4
1 2 4 0
2 5 6
3 8 8
1 4 6 0
1 6 6 0
2 4 10
3 1 9
3 5 7
1 4 10 0
3 6 9
3 2 6
2 1 8
1 5 9 0
3 7 8
3 4 8
2 4 8
2 5 8
2 1 9
2 3 8
1 5 10 0
2 4 8
3 1 6
2 1 4
2 3 7
3 4 10
1 4 6 0
1 1 6 0
2 3 7
1 1 1 0
2 1 10
1 5...

output:

0
0
10
7
0
0
6
3
0
0
0
1
25
12
10
0
0
0
0
17
23
1
20
2
11
27
26
2
18
2
2
0
0
0
2
4
1
0
0
0
7
2
0
4
32
15
7
11
0
4
5
2
8
5
1
6
0
7
0
7
6
3
2
5
0
0
0
7
14
2
5
0
2
0
0
6
12
6
0
2
3
0
0
1
16
12
1
1
12
0
3
4
4
10
3
16
0
17
2
4
0
0
16
8
2
8
18
23
2
24
4
12
7
4
14
5
0
2
8
4
16
10
6
4
21
15
1
3
3
0
2
5
0
2
...

result:

ok 166844 numbers

Test #4:

score: 0
Accepted
time: 126ms
memory: 16104kb

input:

10 500000
0 0 0 0 0 0 0 0 0 0
2 9 10
1 1 3 0
1 1 2 0
2 2 4
3 8 8
2 6 6
2 5 6
3 2 9
2 4 4
1 2 6 0
2 5 7
1 2 10 0
3 1 4
3 1 10
1 6 7 0
1 1 1 0
1 3 9 0
3 4 7
3 2 8
1 6 9 0
1 3 5 0
1 5 10 0
3 2 5
1 2 9 0
1 7 8 0
2 5 10
3 2 3
2 5 5
2 8 9
3 1 6
2 2 6
2 3 6
3 4 5
1 1 6 0
1 1 5 0
3 3 8
3 2 9
3 3 7
1 2 10 0
...

output:

0
9
0
0
0
0
0
0
2
5
2
3
1
0
5
7
1
0
1
3
20
1
23
13
7
14
6
19
0
2
1
2
1
1
0
1
2
2
3
1
0
0
12
28
20
0
0
0
0
0
1
0
1
1
0
2
21
6
9
2
5
10
0
0
0
1
2
1
0
0
0
1
1
0
3
0
2
0
2
0
2
2
2
0
8
3
2
1
0
2
12
4
2
0
0
6
0
9
3
15
0
0
6
0
14
11
6
0
5
4
4
26
11
8
7
7
10
0
4
6
2
4
4
6
4
7
0
3
6
4
20
3
17
14
18
14
9
13
8...

result:

ok 166636 numbers

Test #5:

score: -100
Time Limit Exceeded

input:

500000 500000
472024 143520 268267 155743 162119 212911 326774 283734 445407 353394 432929 138490 36366 247037 157063 203731 162782 54322 321700 39379 6459 358816 32001 245189 167252 460348 113630 85323 283872 285182 191285 487821 395892 328168 467455 469639 234067 325083 145477 450046 16029 142429 ...

output:


result: