QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#224978#5441. Quartz CollectionluanmengleiWA 3ms36216kbC++172.7kb2023-10-23 19:13:572023-10-23 19:13:58

Judging History

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

  • [2023-10-23 19:13:58]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:36216kb
  • [2023-10-23 19:13:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
bool stB;
namespace SOL {

void debug(const char *msg, ...) {
#ifdef CLESIP
    va_list arg;
    static char pbString[512];
    va_start(arg,msg);
    vsprintf(pbString,msg,arg);
    cerr << "[DEBUG] " << pbString << "\n";
    va_end(arg);
#endif    
}

#define PASSED debug("PASSED (%s) LINE #%s", __FUNCTION__, __LINE__)

using i64 = long long;
using i128 = __int128_t;
template <typename T, typename L> void chkmax(T &x, L y) { if (x < y) x = y; }
template <typename T, typename L> void chkmin(T &x, L y) { if (x > y) x = y; }

const int N = 1e5 + 10;
const int V = 1e5;
int n, q, a[N], b[N], cnt[V * 2 + 10];

namespace SegmentTree {
	const int SEG_SIZE = V * 8;
	template<typename Data>
	struct SegTree {
		#define lc (x * 2)
		#define rc (x * 2 + 1)
		#define mid ((l + r) >> 1)

		Data dat[SEG_SIZE];

		void change(int x, int l, int r, int pos, const Data &k) {
			if (l == r)
				return dat[x] = k, void();
			if (pos <= mid)
				change(lc, l, mid, pos, k);
			else
				change(rc, mid + 1, r, pos, k);
			dat[x] = dat[lc] + dat[rc];
		}

		Data query(int x, int l, int r, int ql, int qr) {
			if (ql <= l && r <= qr)
				return dat[x];
			if (ql <= mid && mid < qr)
				return query(lc, l, mid, ql, qr) + query(rc, mid + 1, r, ql, qr);
			else if (ql <= mid)
				return query(lc, l, mid, ql, qr);
			else
				return query(rc, mid + 1, r, ql, qr);
		}

		#undef lc
		#undef rc
		#undef mid
	};
}

struct Node {
	int cnt;
	array<i64, 4> f;

	Node() {
		f = { 0, 0, 0, 0 };
		cnt = 0;		
	}
};

Node operator + (const Node &lhs, const Node &rhs) {
	Node ret;
	ret.cnt = lhs.cnt + rhs.cnt;
	for (int i = 0; i < 4; i ++) {
		ret.f[i] = lhs.f[i] + rhs.f[(i + lhs.cnt) % 4];
	}
	return ret;
}

Node make_node(int v, int c) {
	Node id, ret;
	id.cnt = 1;
	if (v < 0)
		id.f = { v, 0, 0, v };
	else
		id.f = { v, 0, v, 0 };
	c %= 4;
	while (c --)
		ret = ret + id;
	return ret;
}

SegmentTree::SegTree<Node> segt;

void solve() {
	cin >> n >> q;
	i64 sum = 0;
	auto query = [&]() {
		return sum + segt.dat[1].f[0];
	};
	auto modify = [&](int i, int k) {
		int pos = a[i] - b[i] + V;
		cnt[pos] += k;
		sum += b[i] * k;
		segt.change(1, 0, 2 * V, pos, make_node(a[i] - b[i], cnt[pos]));
	};
	for (int i = 1; i <= n; i ++) {
		cin >> a[i] >> b[i];
		modify(i, 1);
	}
	cout << query() << "\n";
	while (q --) {
		int i, x, y; cin >> i >> x >> y;
		modify(i, -1);
		a[i] = x, b[i] = y;
		modify(i, 1);
		cout << query() << "\n";
	}
}

}
bool edB;
signed main() {
	// cerr << "Memory: " << (&stB - &edB) / 1024.0 / 1024.0 << "MB\n";
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	SOL::solve();
	return 0;
}

詳細信息

Test #1:

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

input:

4 5
2 4
5 7
1 7
2 1
4 5 2
1 6 2
4 4 3
2 1 3
3 6 6

output:

13
14
15
14
10
13

result:

ok 6 numbers

Test #2:

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

input:

1 1
1 1
1 1 1

output:

1
1

result:

ok 2 number(s): "1 1"

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 35812kb

input:

100 100
6 7
100 8
5 61
5 75
59 65
51 47
83 37
34 54
87 46
4 26
21 87
12 97
86 68
60 11
62 76
14 83
29 31
91 62
57 80
47 75
85 97
62 77
91 86
14 25
48 77
83 65
39 61
78 77
45 46
90 74
100 91
86 98
55 5
84 42
91 69
100 4
74 98
60 37
75 44
41 12
15 34
36 1
99 16
7 87
36 26
79 42
41 84
17 98
72 16
38 55...

output:

5017
4975
4970
4917
4885
4903
4860
4838
4830
4838
4856
4823
4793
4771
4806
4772
4837
4787
4793
4774
4730
4708
4659
4617
4546
4618
4654
4687
4677
4685
4714
4733
4710
4683
4642
4613
4610
4664
4725
4759
4746
4754
4736
4741
4697
4726
4654
4669
4682
4631
4593
4525
4505
4536
4587
4567
4514
4502
4471
4487
...

result:

wrong answer 1st numbers differ - expected: '5109', found: '5017'