QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#866733#9986. Shiori中国入民小学附属信息I队 (Zicheng Wang, Shubang Liu, Minkai Shao)#WA 4349ms55124kbC++146.0kb2025-01-22 17:52:322025-01-22 17:52:33

Judging History

This is the latest submission verdict.

  • [2025-01-22 17:52:33]
  • Judged
  • Verdict: WA
  • Time: 4349ms
  • Memory: 55124kb
  • [2025-01-22 17:52:32]
  • Submitted

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <random>
#include <ctime>
#include <chrono>
#include <numeric>
#include <iomanip>
#include <cassert>

typedef long long ll;
typedef double lf;
typedef unsigned long long ull;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 5e5 + 10, MAXB = 750, B = 720;

int n, q; ll a[MAXN];

int bel[MAXN], lb[MAXB], rb[MAXB];
bitset <MAXN> cnt[MAXB], avl;
ll sum[MAXB], add[MAXB]; int cov[MAXB];

inline void Set(int i) { sum[bel[i]] += a[i]; if (a[i] <= 5e5) cnt[bel[i]].set(a[i]); }
inline void Rebuild(int u)
{
    for (int i = lb[u]; i <= rb[u]; i++)
        if (a[i] <= 5e5) cnt[u].reset(a[i]);
    for (int i = lb[u]; i <= rb[u]; i++) a[i] = (~cov[u] ? cov[u] : a[i]) + add[u];
    sum[u] = add[u] = 0, cov[u] = -1;
}
inline void Aset(int x) { (x <= 5e5) && (avl.set(x), 0); }
inline void Areset(int x) { (x <= 5e5) && (avl.reset(x), 0); }
inline bool Test(int l, int r, int x)
{
    if (x > 5e5) return 0;
    if (avl.test(x)) return 1;
    for (int i = l; i <= r; i++)
        if (cov[i] == x) return 1;
        else if (cov[i] == -1 && x + add[i] <= 5e5 && cnt[i].test(x + add[i])) return 1;
    return 0;
}

int main()
{
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    Read(n), Read(q);
    for (int i = 1; i <= n; i++) Read(a[i]);

    for (int i = 1; i <= n; i++) bel[i] = (i - 1) / B + 1;
    for (int i = 1; i <= bel[n]; i++) lb[i] = (i - 1) * B + 1, rb[i] = min(n, i * B), cov[i] = -1;
    for (int i = 1; i <= n; i++) Set(i);

    int op, l, r, x;
    while (q--)
    {
        Read(op), Read(l), Read(r);
        if (op == 1)
        {
            Read(x);
            if (bel[l] == bel[r])
            {
                Rebuild(bel[l]);
                for (int i = l; i <= r; i++) a[i] = x;
                for (int i = lb[bel[l]]; i <= rb[bel[l]]; i++) Set(i);
                continue;
            }
            Rebuild(bel[l]), Rebuild(bel[r]);
            for (int i = l; bel[i] == bel[l]; i++) a[i] = x;
            for (int i = lb[bel[l]]; i <= rb[bel[l]]; i++) Set(i);
            for (int i = r; bel[i] == bel[r]; i--) a[i] = x;
            for (int i = lb[bel[r]]; i <= rb[bel[r]]; i++) Set(i);
            for (int i = bel[l] + 1; i < bel[r]; i++) add[i] = 0, cov[i] = x, sum[i] = (ll)B * x;
        }
        else if (op == 2)
        {
            if (bel[l] == bel[r])
            {
                Rebuild(bel[l]);
                for (int i = l; i <= r; i++) Aset(a[i]);
                int mex = 0; while (avl.test(mex)) mex++;
                for (int i = l; i <= r; i++) Areset(a[i]), a[i] += mex;
                for (int i = lb[bel[l]]; i <= rb[bel[l]]; i++) Set(i);
                continue;
            }
            Rebuild(bel[l]), Rebuild(bel[r]);
            for (int i = l; bel[i] == bel[l]; i++) Aset(a[i]);
            for (int i = r; bel[i] == bel[r]; i--) Aset(a[i]);
            int mex = 0; while (Test(bel[l] + 1, bel[r] - 1, mex)) mex++;
            for (int i = l; bel[i] == bel[l]; i++) Areset(a[i]), a[i] += mex;
            for (int i = r; bel[i] == bel[r]; i--) Areset(a[i]), a[i] += mex;
            for (int i = bel[l] + 1; i < bel[r]; i++) add[i] += mex, sum[i] += (ll)B * mex;
            for (int i = lb[bel[l]]; i <= rb[bel[l]]; i++) Set(i);
            for (int i = lb[bel[r]]; i <= rb[bel[r]]; i++) Set(i);
        }
        else
        {
            ll ans = 0;
            if (bel[l] == bel[r])
            {
                Rebuild(bel[l]);
                for (int i = l; i <= r; i++) ans += a[i];
                for (int i = lb[bel[l]]; i <= rb[bel[l]]; i++) Set(i);
                cout << ans << "\n";
                continue;
            }
            Rebuild(bel[l]), Rebuild(bel[r]);
            for (int i = l; bel[i] == bel[l]; i++) ans += a[i];
            for (int i = r; bel[i] == bel[r]; i--) ans += a[i];
            for (int i = bel[l] + 1; i < bel[r]; i++) ans += sum[i];
            for (int i = lb[bel[l]]; i <= rb[bel[l]]; i++) Set(i);
            for (int i = lb[bel[r]]; i <= rb[bel[r]]; i++) Set(i);
            cout << ans << "\n";
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9960kb

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: 9832kb

input:

1 1
0
1 1 1 0

output:


result:

ok 0 number(s): ""

Test #3:

score: 0
Accepted
time: 42ms
memory: 9960kb

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: 42ms
memory: 9956kb

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
Wrong Answer
time: 4349ms
memory: 55124kb

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:

71434
703124
0
1537531
1932395
0
405469
4154037
1417625
354943
1391480
0
545963
2134
2284370
0
550722
4370474
1031123
0
1151393
0
373570
3666443
0
2812689
1987620
192517
0
2552418
0
0
2285294
2669393
983651
3192162
2320862
445327
340917
0
55154
5111256
2843128

result:

wrong answer 2nd numbers differ - expected: '2040073', found: '703124'