QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#266434#7108. CouleurUtopianZ#AC ✓2460ms38468kbC++143.0kb2023-11-26 14:13:142023-11-26 14:13:14

Judging History

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

  • [2023-11-26 14:13:14]
  • 评测
  • 测评结果:AC
  • 用时:2460ms
  • 内存:38468kb
  • [2023-11-26 14:13:14]
  • 提交

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[j], 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;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3700kb

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 0 0 0 0 
42 31 21 14 14 4 1 1 1 0 0 0 0 0 0 

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 2460ms
memory: 38468kb

input:

11116
10
10 5 10 3 6 4 8 5 9 8
31 27 24 11 12 3 0 2 3 1
10
8 2 7 2 8 10 1 10 9 10
6 5 2 13 2 1 0 1 3 1
10
7 10 7 6 1 3 10 6 7 9
21 18 10 1 6 5 4 8 9 10
10
2 10 4 8 8 5 7 2 6 7
20 10 9 1 15 0 4 2 9 7
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10
1 2 3 4 5 6 7 8 9 10
6 3 5 2 7 10 9 1 4 8
10
1 10 1 3...

output:

21 18 16 12 10 6 4 1 1 0 
12 12 10 10 4 4 4 2 1 0 
20 16 9 5 3 3 3 0 0 0 
22 14 8 8 5 5 2 1 1 0 
0 0 0 0 0 0 0 0 0 0 
0 0 0 0 0 0 0 0 0 0 
19 12 7 4 4 2 2 1 0 0 
20 18 8 3 1 1 0 0 0 0 
45 21 21 10 3 3 3 0 0 0 
17 11 8 2 1 1 1 0 0 0 
13 4 1 0 0 0 0 0 0 0 
29 27 22 15 9 7 4 3 1 0 
26 16 9 2 1 1 1 1 1 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed