QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#158049#7108. Couleurucup-team866#AC ✓1725ms31720kbC++142.9kb2023-09-02 16:09:342023-09-02 16:09:34

Judging History

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

  • [2023-09-02 16:09:34]
  • 评测
  • 测评结果:AC
  • 用时:1725ms
  • 内存:31720kb
  • [2023-09-02 16:09:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5, NN = 2e6 + 6;
int T, n, root[N], nodes, ls[NN], rs[NN], tree[NN], cnt, l[N], r[N], id[N], a[N]; ll inv[N], x;
void update(int &rt, int lrt, int l, int r, int x) {
	rt = ++ nodes;
	if (l == r) return void (tree[rt] = tree[lrt] + 1);
	int mid = l + r >> 1;
	if (x <= mid) rs[rt] = rs[lrt], update(ls[rt], ls[lrt], l, mid, x);
	else ls[rt] = ls[lrt], update(rs[rt], rs[lrt], mid+1, r, x);
	tree[rt] = tree[ls[rt]] + tree[rs[rt]];
}
int query(int rt, int l, int r, int x, int y) {
	if (! rt || x > y) return 0;
	if (l == x && r == y) return tree[rt];
	int mid = l + r >> 1;
	if (y <= mid) return query(ls[rt], l, mid, x, y);
	else if (x > mid) return query(rs[rt], mid+1, r, x, y);
	else return query(ls[rt], l, mid, x, mid) + query(rs[rt], mid+1, r, mid+1, y);
}
int main() {
	cin >> T;
	while (T --) {
		scanf ("%d", &n);
		for (int i=1; i<=n; i++)
			root[i] = 0; nodes = 0;
		cnt = 1, l[1] = 1, r[1] = n, inv[1] = 0, id[n+1] = 0;
		for (int i=1; i<=n; i++)
			scanf ("%d", &a[i]), update(root[i], root[i-1], 1, n, a[i]), 
			inv[1] += query(root[i-1], 1, n, a[i] + 1, n), id[i] = 1;
		priority_queue <ll> que, del;
		que. push(inv[1]);
		for (int i=1; i<=n; i++) {
			while (! del. empty() && del. top() == que. top())
				del. pop(), que. pop();
			printf (i < n ? "%lld " : "%lld\n", que. top());
			scanf ("%lld", &x), x ^= que. top();
			int y = id[x]; id[x] = 0, del. push(inv[y]);
			if (! id[x-1] && ! id[x+1]) continue;
			if (x - l[y] <= r[y] - x) {
				inv[y] -= query(root[x-1], 1, n, a[x] + 1, n) - query(root[l[y]-1], 1, n, a[x] + 1, n);
				for (int j=l[y]; j<=x; j++)
					inv[y] -= query(root[r[y]], 1, n, 1, a[j] - 1) - query(root[x], 1, n, 1, a[j] - 1);
				if (x > l[y]) {
					cnt ++, l[cnt] = l[y], r[cnt] = x - 1, inv[cnt] = 0;
					for (int j=l[cnt]; j<=r[cnt]; j++)
						id[j] = cnt;
					for (int j=l[cnt]+1; j<=r[cnt]; j++)
						inv[cnt] += query(root[j-1], 1, n, a[j] + 1, n) - query(root[l[cnt]-1], 1, n, a[j] + 1, n);
					inv[y] -= inv[cnt], que. push(inv[cnt]);
				} l[y] = x + 1, que. push(inv[y]);
			} else {
				inv[y] -= query(root[r[y]], 1, n, 1, a[x] - 1) - query(root[x], 1, n, 1, a[x] - 1);
				for (int j=x; j<=r[y]; j++)
					inv[y] -= query(root[x-1], 1, n, a[j] + 1, n) - query(root[l[y]-1], 1, n, a[j] + 1, n);
				if (x < r[y]) {
					cnt ++, l[cnt] = x + 1, r[cnt] = r[y], inv[cnt] = 0;
					for (int j=l[cnt]; j<=r[cnt]; j++)
						id[j] = cnt;
					for (int j=l[cnt]+1; j<=r[cnt]; j++)
						inv[cnt] += query(root[j-1], 1, n, a[j] + 1, n) - query(root[l[cnt]-1], 1, n, a[j] + 1, n);
					inv[y] -= inv[cnt], que. push(inv[cnt]);
				} r[y] = x - 1, que. push(inv[y]);
			}
/*			puts ("");
			for (int i=1; i<=n; i++)
				printf ("%d ", id[i]);
			puts ("");
			for (int i=1; i<=n; i++)
				if (id[i] && id[i] != id[i-1])
					printf ("%d : %lld\n", id[i], inv[id[i]]);
			puts (""); */
		}
	}
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7896kb

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: 1725ms
memory: 31720kb

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 0
0 0 0 0 0 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed