QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#880453#9986. ShioriEBeasonWA 4492ms36088kbC++173.4kb2025-02-03 13:17:432025-02-03 13:17:44

Judging History

This is the latest submission verdict.

  • [2025-02-03 13:17:44]
  • Judged
  • Verdict: WA
  • Time: 4492ms
  • Memory: 36088kb
  • [2025-02-03 13:17:43]
  • Submitted

answer

#pragma GCC optimize(1, 2, 3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
// #define int ll
#define ls p << 1
#define rs p << 1 | 1
#define lowbit(x) ((x) & (-x))
#define endl '\n'
#define ld long double

using PII = pair<int, int>;
using vi = vector<int>;
using t3i = tuple<int, int, int>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// #define MULTI_CASES
const int MaxN =  5e5 + 10;
const int INF = 1e9;
const int SIZ = 1000;
int T, N, M, K;

struct Block {
	int addTag, coverTag = -1;
	bitset<MaxN> vis;
	ll sum;

	vi a;
	void addOne(int v) {
		a.emplace_back(v);
		sum += v;
        vis.set(v);
	}

	bool get(int v) {
		if (v < 0 || v >= MaxN) return 0;
		return vis[v];
	}

	void rebuild() {
        vis.reset();
		if (coverTag != -1) {	
			for (auto &x : a) {
				x = coverTag;
			}
			coverTag = -1;
		}
        if (addTag) {
            for (auto &x : a) {
                x += addTag;
                    if (x < MaxN) vis.set(x);
            }
            addTag = 0;
        }

	}
	void cover(int v) {
		coverTag = v;
		addTag = 0;
		sum = a.size() * coverTag;
	}
	void add(int v) {
		addTag += v;
		sum += v * a.size();
	}
	void cover(int i, int v) {
        sum += v - addTag - a[i];
		a[i] = v - addTag;
	}
	void add(int i, int v) {
		a[i] += v;
        sum += v;
	}
	bool query(int i, int v) {
		if (coverTag != -1) {
			return coverTag + addTag == v;
		} else {
			return a[i] + addTag == v;
		}
	}

	bool query(int v) {
		if (coverTag != -1) {
			return coverTag + addTag == v;
		} else {
			return get(v - addTag);
		}
	}

	ll getSum() {
		return sum;
	}

	ll getSum(int i) {
		if (coverTag != -1) {
			return coverTag + addTag;
		} else {
			return a[i] + addTag;
		}
	}
} block[MaxN / SIZ + 1];

bool getAns(int l, int r, int v) {
	for (int i = l; i <= r;) {
		if (i % SIZ == 0 && i + SIZ <= r + 1) {
			if (block[i / SIZ].query(v)) return true;
			i += SIZ;
		} else {
			if (block[i / SIZ].query(i % SIZ, v)) return true;
			i++;
		}
	}
	return false;
}

inline void Solve() {
	cin >> N >> M;
	for (int i = 0; i < N; i++) {
		int x;
		cin >> x;
		block[i / SIZ].addOne(x);
	}

	while (M--) {
		int opt, l, r;
		cin >> opt >> l >> r;
		l--, r--;
		block[l / SIZ].rebuild();
		block[r / SIZ].rebuild();
		if (opt == 1) {
			int v;
			cin >> v;
			for (int i = l; i <= r;) {
				if (i % SIZ == 0 && i + SIZ <= r + 1) {
					block[i / SIZ].cover(v);
					i += SIZ;
				} else {
					block[i / SIZ].cover(i % SIZ, v);
					i++;
				}
			}
		} else if (opt == 2) {
			int ans = 0;
			while (ans <= N && getAns(l, r, ans)) {
				ans++;
			}

			// cerr << ans << endl;

			for (int i = l; i <= r;) {
				if (i % SIZ == 0 && i + SIZ <= r + 1) {
					block[i / SIZ].add(ans);
					i += SIZ;
				} else {
					block[i / SIZ].add(i % SIZ, ans);
					i++;
				}
			}
		} else {
			ll ans = 0;
			for (int i = l; i <= r;) {
				if (i % SIZ == 0 && i + SIZ <= r + 1) {
					ans += block[i / SIZ].getSum();
					i += SIZ;
				} else {
					ans += block[i / SIZ].getSum(i % SIZ);
					i++;
				}
			}
			cout << ans << endl;
		}
		block[l / SIZ].rebuild();
		block[r / SIZ].rebuild();
	}
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
#ifdef MULTI_CASES
	int T;
	cin >> T;
	while (T--)
#endif
		Solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

1 1
0
1 1 1 0

output:


result:

ok 0 number(s): ""

Test #3:

score: 0
Accepted
time: 1941ms
memory: 34184kb

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: 1940ms
memory: 34172kb

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: 4492ms
memory: 36088kb

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:

32367
336180
0
913299
631207
0
177191
2253006
943971
314639
474219
0
202756
2134
809262
0
75574
2499976
353906
0
501135
0
237411
890825
0
1008019
528396
57991
0
782935
0
0
772129
992310
343315
721477
579293
71825
103838
0
38960
1307517
1219482

result:

wrong answer 1st numbers differ - expected: '71434', found: '32367'