QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#21574#2849. 弗雷兹的玩具商店hy_zheng_zai_nei_juan#WA 367ms202084kbC++203.0kb2022-03-07 15:15:002022-05-08 03:39:21

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 03:39:21]
  • Judged
  • Verdict: WA
  • Time: 367ms
  • Memory: 202084kb
  • [2022-03-07 15:15:00]
  • Submitted

answer

#include <bits/stdc++.h>

const int N = 2e5 + 50;
const int M = 61;

int n, m, q, c[N], v[N];

inline int lc(int o) { return o << 1; }
inline int rc(int o) { return o << 1 | 1; }

struct node_t {
	int v[M];
	node_t() {
		memset(v, 0, sizeof v);
	}
} node[N << 2];

struct tag_t {
	int add, cyc;
	tag_t() : add(0), cyc(0) {

	}
} tag[N << 2];

void apply(node_t &o, tag_t &to, int add, int cyc) {
	static int dummy[M];
	for (int i = 1; i <= m; ++i)
		o.v[i] += add;
	for (int i = 1; i <= m; ++i) {
		int x = (i + cyc - 1) % m + 1;
		dummy[x] = o.v[i];
	}
	for (int i = 1; i <= m; ++i)
		o.v[i] = dummy[i];
	to.add += add;
	to.cyc += cyc;
}

void push_down(int o) {
	if (tag[o].add || tag[o].cyc) {
		apply(node[lc(o)], tag[lc(o)], tag[o].add, tag[o].cyc);
		apply(node[rc(o)], tag[rc(o)], tag[o].add, tag[o].cyc);
		tag[o].add = tag[o].cyc = 0;
	}
}
void push_up(int o) {
	for (int i = 1; i <= m; ++i)
		node[o].v[i] = std::max(node[lc(o)].v[i], node[rc(o)].v[i]);
}
void modify(int o, int l, int r, int ql, int qr, int add, int cyc) {
	if (ql <= l && r <= qr) {
		apply(node[o], tag[o], add, cyc);
	}
	else {
		const int mid = l + r >> 1;
		push_down(o);
		if (ql <= mid) modify(lc(o), l, mid, ql, qr, add, cyc);
		if (qr > mid) modify(rc(o), mid + 1, r, ql, qr, add, cyc);
		push_up(o);
	}
}
void build(int o, int l, int r) {
	if (l == r) {
		node[o].v[c[l]] = v[l];
		//printf("node[%d].v[%d] = %d\n", o, c[l], node[o].v[c[l]]);
	}
	else {
		const int mid = l + r >> 1;
		build(lc(o), l, mid);
		build(rc(o), mid + 1, r);
		push_up(o);
		//for (int i = 1; i <= m; ++i)
		//	if (node[o].v[i])
		//		printf("node[%d].v[%d] = %d\n", o, i, node[o].v[i]);
	}
}
int ansv[M];
void query(int o, int l, int r, int ql, int qr) {
	if (ql <= l && r <= qr) {
		for (int i = 1; i <= m; ++i)
			ansv[i] = std::max(ansv[i], node[o].v[i]);
	}
	else {
		const int mid = l + r >> 1;
		push_down(o);
		if (ql <= mid) query(lc(o), l, mid, ql, qr);
		if (qr > mid) query(rc(o), mid + 1, r, ql, qr);
	}
}
long long dp[M];
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout.tie(nullptr);
	std::cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		std::cin >> c[i];
	for (int i = 1; i <= n; ++i)
		std::cin >> v[i];
	build(1, 1, n);
	std::cin >> q;
	while (q--) {
		int op, l, r, d;
		std::cin >> op >> l >> r;
		if (op == 1) {
			std::cin >> d;
			modify(1, 1, n, l, r, 0, d);
		}
		else if (op == 2) {
			std::cin >> d;
			modify(1, 1, n, l, r, d, 0);
		}
		else {
			memset(ansv, 0, sizeof ansv);
			query(1, 1, n, l, r);
			memset(dp, 0, sizeof dp);
			for (int i = 1; i <= m; ++i)
				if (ansv[i]) {
					for (int j = i; j <= m; ++j)
						dp[j] = std::max(dp[j], dp[j - i] + ansv[i]);
				}
			long long sum = 0, xsum = 0;
			for (int i = 1; i <= m; ++i) {
				sum += dp[i];
				xsum ^= dp[i];
			}
			std::cout << sum << " " << xsum << '\n';
		//	for (int i = 1; i <= m; ++i)
		//		if (ansv[i])
		//			printf("ansv[%d] = %d\n", i, ansv[i]);
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 35ms
memory: 200500kb

input:

4 10
1 6 10 2
100 2333 666 300
7
3 1 4
3 1 3
1 2 4 1
3 1 4
2 2 3 -1000
2 2 3 -600
3 2 4

output:

15165 2865
14165 2169
36630 798
4899 1273

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 367ms
memory: 202084kb

input:

200000 60
21 16 58 5 26 44 30 40 31 27 50 21 59 50 37 39 26 9 15 14 9 59 40 29 32 5 2 25 57 18 4 9 25 1 13 42 36 34 21 6 53 2 18 51 51 55 29 17 3 36 22 11 26 1 40 58 57 33 22 53 42 26 1 6 18 6 47 54 31 59 51 23 60 1 13 43 55 34 59 49 9 12 51 34 4 22 31 1 47 45 45 28 10 38 34 19 35 12 4 5 11 47 28 2 ...

output:

304478979 5965183
302725180 6346266
263891804 12270170
206665590 7376160
224407908 12588660
302401755 6812441
298016030 8641780
187482000 7499280
276575975 13386421
302685395 8377169
304347825 5950953
296928490 9925716
273952510 11264178
185846328 1238664
276368626 13405014
200927082 49156
84263735 ...

result:

wrong answer 17th lines differ - expected: '84257215 7195871', found: '84263735 7195415'