QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#707642#8338. Quad Kingdoms ChessGemini7X#WA 14ms24556kbC++142.2kb2024-11-03 16:52:282024-11-03 16:52:29

Judging History

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

  • [2024-11-03 16:52:29]
  • 评测
  • 测评结果:WA
  • 用时:14ms
  • 内存:24556kb
  • [2024-11-03 16:52:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const ull P = 1e9 + 7;
const int maxn = 1e5 + 5;
template <typename T>
void read(T &x)
{
	T sgn = 1;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}
int pw[maxn];
struct SegmentTree{
	int sz[maxn << 2], sz2[maxn << 2], st[maxn << 2], ed[maxn << 2];
	ull hsh[maxn << 2], hsh2[maxn << 2];
	pair<ull, int> fnd(int p, int l, int r, int v) {
		if (st[p] >= v) {
			return make_pair(hsh[p], sz[p]);
		}
		int mid = (l + r) >> 1;
		if (v > ed[p << 1 | 1]) return fnd(p << 1, l, mid, v);
		else {
			pair<ull, int> res = fnd(p << 1 | 1, mid + 1, r, v);
			res.first *= pw[sz2[p]];
			res.first += hsh2[p];
			res.second += sz2[p];
			return res;
		}
	}
	void pushup(int p, int l, int r) {
		st[p] = st[p << 1 | 1];
		if (ed[p << 1] < ed[p << 1 | 1]) {
			hsh[p] = hsh[p << 1 | 1];
			ed[p] = ed[p << 1 | 1];
			sz[p] = sz[p << 1 | 1];
			sz2[p] = 0;
			hsh2[p] = 0;
		} else {
			int mid = (l + r) >> 1;
			pair<ull, int> now = fnd(p << 1, l, mid, ed[p << 1 | 1]);
			hsh[p] = now.first + hsh[p << 1 | 1] * pw[now.second];
			sz[p] = sz[p << 1 | 1] + now.second;
			sz2[p] = now.second;
			hsh2[p] = now.first;
			ed[p] = ed[p << 1];
		}
	}
	void modify(int p, int l, int r, int x, int v) {
		if (l == r) {
			sz[p] = 1;
			hsh[p] = v;
			st[p] = ed[p] = v;
			return;
		}
		int mid = (l + r) >> 1;
		if (x <= mid) modify(p << 1, l, mid, x, v);
		else modify(p << 1 | 1, mid + 1, r, x, v);
		pushup(p, l, r);
	}
}tr[2];
int n, m, q;
int a[maxn], b[maxn];
int main()
{
	pw[0] = 1;
	for (int i = 1; i <= 100000; i++) pw[i] = pw[i - 1] * P;
	read(n);
	for (int i = 1; i <= n; i++) read(a[i]), tr[0].modify(1, 1, n, i, a[i]);
	read(m);
	for (int i = 1; i <= m; i++) read(b[i]), tr[1].modify(1, 1, m, i, b[i]);
	read(q);
	while (q--) {
		int op, x, y;
		read(op); read(x); read(y); op--;
		if (op == 0) {
			tr[0].modify(1, 1, n, x, y);
		} else {
			tr[1].modify(1, 1, m, x, y);
		}
		puts(tr[0].hsh[1] == tr[1].hsh[1] ? "YES" : "NO");
//		cout << tr[0].hsh[1] << " " << tr[1].hsh[1] << "\n";
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 2 3 4 5
5
5 4 3 2 1
8
1 1 5
1 4 2
1 2 4
1 5 1
1 5 5
2 1 4
2 3 5
2 5 5

output:

NO
NO
NO
YES
NO
NO
NO
YES

result:

ok 8 tokens

Test #2:

score: 0
Accepted
time: 13ms
memory: 18404kb

input:

1
2
6
2 1 1 1 1 1
200000
2 6 2
1 1 1
1 1 1
1 1 2
2 1 1
1 1 2
1 1 1
2 4 1
2 1 2
1 1 1
1 1 2
2 5 1
1 1 1
1 1 2
1 1 1
2 6 1
1 1 2
1 1 2
1 1 2
2 3 1
1 1 1
2 1 1
2 6 2
1 1 2
2 4 1
1 1 2
2 6 1
1 1 2
1 1 1
2 5 2
2 6 2
1 1 1
2 4 2
2 5 2
2 6 2
1 1 1
2 5 1
2 6 2
1 1 2
1 1 1
1 1 1
2 4 1
1 1 2
1 1 2
1 1 2
2 3 2...

output:

NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

ok 200000 tokens

Test #3:

score: 0
Accepted
time: 14ms
memory: 18400kb

input:

6
2 1 1 2 1 2
1
1
200000
2 1 1
1 1 2
1 1 1
2 1 2
2 1 1
2 1 1
2 1 2
2 1 2
1 1 2
1 3 1
1 6 2
1 5 2
1 4 2
1 3 1
2 1 2
1 4 2
1 4 2
2 1 2
2 1 2
1 3 1
1 6 1
1 1 2
2 1 1
1 6 1
1 3 1
1 5 2
1 6 2
1 5 2
2 1 2
1 2 1
1 5 2
2 1 1
2 1 1
1 6 1
2 1 2
2 1 1
1 3 2
2 1 1
1 6 1
1 4 2
1 2 1
1 1 1
2 1 1
1 2 1
1 6 2
1 6 2...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 200000 tokens

Test #4:

score: -100
Wrong Answer
time: 14ms
memory: 24444kb

input:

6
1 3 1 2 1 2
6
2 1 3 3 3 1
200000
2 4 2
1 2 1
1 6 2
2 3 2
1 1 1
1 6 2
1 6 2
1 3 2
2 6 1
2 4 3
1 1 2
2 5 2
2 6 2
2 3 1
1 4 3
1 3 1
2 5 2
2 4 2
2 1 3
1 1 1
2 2 2
2 4 2
1 5 3
1 6 3
2 6 3
1 5 3
2 5 3
2 4 1
2 4 2
1 1 2
1 6 1
2 6 1
1 2 3
1 1 3
1 1 1
2 6 3
2 4 1
1 4 2
2 2 1
1 3 1
1 1 3
1 1 3
1 4 3
1 3 3
2...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

wrong answer 27th words differ - expected: 'YES', found: 'NO'