QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#158273#7108. Couleurucup-team918#AC ✓1496ms31576kbC++172.1kb2023-09-02 16:22:312023-09-02 16:22:33

Judging History

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

  • [2023-09-02 16:22:33]
  • 评测
  • 测评结果:AC
  • 用时:1496ms
  • 内存:31576kb
  • [2023-09-02 16:22:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
set<array<ll, 3>> s;
multiset<ll> st;
int n, a[100010], rt[100010], cnt;
struct node {
	int sz, lson, rson;
} t[100010 * 40];
#define mid (l + r >> 1)
void change(int &now, int from, int x, int l = 1, int r = n) {
	t[now = ++cnt] = t[from], t[now].sz++;
	if (l == r) return;
	if (x <= mid) change(t[now].lson, t[from].lson, x, l, mid);
	else change(t[now].rson, t[from].rson, x, mid + 1, r);
}
int query(int now, int from, int x, int l = 1, int r = n) {
	if (x >= r) return t[now].sz - t[from].sz;
	if (x < l) return 0;
	if (x <= mid) return query(t[now].lson, t[from].lson, x, l, mid);
	return t[t[now].lson].sz - t[t[from].lson].sz + query(t[now].rson, t[from].rson, x, mid + 1, r);
}
ll calc(int l, int r) {
	ll res = 0;
	for (int i = l; i <= r; i++)
		res += query(rt[r], rt[i], a[i] - 1);
	return res;
}
void Solve(int test) {
	s.clear(), st.clear();
	cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i], change(rt[i], rt[i - 1], a[i]);
	s.insert({1, n, calc(1, n)}), st.insert(calc(1, n));
	for (int i = 1; i <= n; i++) {
		cout << *prev(st.end()) << " ";
		ll x;
		cin >> x, x ^= *prev(st.end());
		auto [l, r, p] = *prev(s.upper_bound({x, (int)1e9, 0}));
		s.erase({l, r, p}), st.erase(st.find(p));
		if (x <= (l + r) / 2) {
			ll pl = calc(l, x - 1);
			p -= pl;
			p -= x - l - query(rt[x - 1], rt[l - 1], a[x]);
			for (int i = l; i <= x; i++)
				p -= query(rt[r], rt[x], a[i] - 1);
			if (r > x) s.insert({x + 1, r, p}), st.insert(p);
			if (x > l) s.insert({l, x - 1, pl}), st.insert(pl);
		}
		else {
			ll pr = calc(x + 1, r);
			p -= pr;
			p -= query(rt[r], rt[x], a[x] - 1);
			for (int i = x; i <= r; i++)
				p -= x - l - query(rt[x - 1], rt[l - 1], a[i]);
			if (x > l) s.insert({l, x - 1, p}), st.insert(p);
			if (r > x) s.insert({x + 1, r, pr}), st.insert(pr);
		}
	}
	cout << endl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int T;
	cin >> T;
	for (int i = 1; i <= T; i++) Solve(i);
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1496ms
memory: 31576kb

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