QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#266431#7108. CouleurUtopianZ#WA 0ms4076kbC++143.0kb2023-11-26 14:12:152023-11-26 14:12:15

Judging History

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

  • [2023-11-26 14:12:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4076kb
  • [2023-11-26 14:12:15]
  • 提交

answer

#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

#define ll long long
#define ull unsigned long long
#define pii std :: pair<int, int>
#define pb push_back
#define fi first
#define se second
#define lep(i, l, r) for(int i = l; i <= r; i++)
#define rep(i, r, l) for(int i = r; i >= l; i--)
#define mset(s, t) memset(s, t, sizeof(s))
#define mcpy(s, t) memcpy(s, t, sizeof(t))

template <typename T1, typename T2> void Min(T1 &x, T2 y) {
	if (x > y) x = y;
}

template <typename T1, typename T2> void Max(T1 &x, T2 y) {
	if (x < y) x = y;
}

int read() {
	int x = 0, f = 0;
	char ch = getchar();
	while (!isdigit(ch)) f |= ch == '-', ch = getchar();
	while (isdigit(ch)) x = 10 * x + ch - '0', ch = getchar();
	return f ? -x : x;
}

template <typename T> void print(T x) {
	if (x < 0) putchar('-'), x = -x;
	if (x >= 10) print(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void Print(T x, char let) {
	print(x), putchar(let);
}

const int N = 2e5 + 5;
const int M = N * 20;

int n;
int a[N];

int tot;
int rt[N], s[M], ls[M], rs[M];
void Add(int &x, int l, int r, int p) {
	tot++, ls[tot] = ls[x], rs[tot] = rs[x], s[tot] = s[x] + 1, x = tot;
	if (l == r) return;
	int mid = (l + r) >> 1;
	if (p <= mid) Add(ls[x], l, mid, p); else Add(rs[x], mid + 1, r, p); 
}
int Query(int x, int l, int r, int ql, int qr) {
	if (l > qr || r < ql) return 0;
	if (ql <= l && r <= qr) return s[x];
	int mid = (l + r) >> 1;
	return Query(ls[x], l, mid, ql, qr) + Query(rs[x], mid + 1, r, ql, qr);
}

ll sp[N];
ll G(int l, int r) {
	ll ans = 0;
	for (int i = l + 1; i <= r; i++) 
		ans += Query(rt[i - 1], 0, n + 1, a[i] + 1, n + 1) - 
		Query(rt[l - 1], 0, n + 1, a[i] + 1, n + 1);
	return ans;
}

void Solve() {
	n = read();
	for (int i = 1; i <= n; i++) a[i] = read(), rt[i] = rt[i - 1], Add(rt[i], 0, n + 1, a[i]);
	std :: set <int> S;
	std :: multiset <ll> ans;
//		puts("?");
	S.insert(0), S.insert(n + 1), sp[1] = G(1, n), ans.insert(sp[1]);
	for (int i = 1; i <= n; i++) {
		ll lst = *--ans.end();
		printf("%lld ", lst);
		if (i == n) puts("");
//		int v = read() ^ lst;
		ll v;
		scanf("%lld", &v), v ^= lst;
		auto p = S.lower_bound(v);
		int r = *p - 1, l = *--p + 1;
		S.insert(v), ans.erase(ans.lower_bound(sp[l]));
		ll cur = sp[l];
		if (v - l > r - v) {
			for (int j = r; j >= v; j--) 
				cur -= Query(rt[j - 1], 0, n + 1, a[j] + 1, n + 1) - 
				Query(rt[l - 1], 0, n + 1, a[j] + 1, n + 1);
			sp[l] = cur, sp[v + 1] = G(v + 1, r);
		}
		else {
			for (int j = l; j <= v; j++) {
				cur -= Query(rt[r], 0, n + 1, 0, a[j] - 1) - 
				Query(rt[i], 0, n + 1, 0, a[j] - 1);
			}
			sp[l] = G(l, v - 1), sp[v + 1] = cur;
		}
		ans.insert(sp[l]), ans.insert(sp[v + 1]);
	}
	for (int i = 1; i <= tot; i++) ls[i] = rs[i] = s[i] = 0;
	tot = 0;
}

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int T = read();
	while (T--) Solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 4076kb

input:

3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10

output:

7 0 0 0 0 
20 11 7 2 0 0 2 2 2 2 
42 31 21 14 14 4 1 1 1 3 3 3 3 3 3 

result:

wrong answer 2nd lines differ - expected: '20 11 7 2 0 0 0 0 0 0', found: '20 11 7 2 0 0 2 2 2 2 '