QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#244209#7108. CouleurwushiRE 1ms5684kbC++143.8kb2023-11-08 21:58:122023-11-08 21:58:14

Judging History

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

  • [2023-11-08 21:58:14]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5684kb
  • [2023-11-08 21:58:12]
  • 提交

answer

#include<bits/stdc++.h>
#define fi first
#define se second
//#define int ll
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
int mod = 1e9 + 7, mod2 = 998244353;
const long long LNF = 0x3f3f3f3f3f3f3f3f;
const int N = 4e5 + 10, INF = 0x3f3f3f3f;
ll n, m, k;
int qmi(int a, int b) {
	ll res = 1;
	while (b) {
		if (b & 1)res = res * a % mod;
		a = (ll)a * a % mod;
		b >>= 1;
	}
	return res;
}

ll a[N];




struct node {
	ll he = 0;
} sg[N << 5];
int root[N];

int ls[N << 5], rs[N << 5];

int idx;


node up(node t1, node t2) {
	node t3;
	ll he = t1.he + t2.he;
	t3 = {he};
	return t3;
}

void modify(int &x, int pass, int l, int r, int p) {
	x = ++ idx;
	sg[x].he = sg[pass].he;
	ls[x] = ls[pass];
	rs[x] = rs[pass];
	if (l == r) {
		sg[x].he++;
		return ;
	}
	int mid = l + r >> 1;
	if (p <= mid) modify(ls[x], ls[pass], l, mid, p);
	else modify(rs[x], rs[pass], mid + 1, r, p);
	sg[x] = up(sg[ls[x]], sg[rs[x]]);
}

node query(int x, int l1, int r1, int l, int r) {
	if (r1 < l1) return {0};
	node t;
	t = {0};
	if (l1 <= l && r1 >= r) return sg[x];
	int mid = l + r >> 1;
	if (l1 <= mid) t = query(ls[x], l1, r1, l, mid);
	if (r1 > mid) t = up(t, query(rs[x], l1, r1, mid + 1, r));
	return t;
}

map<int, ll>mp;
multiset<ll>ms;

void spilt(int L, int R, int x) {
	ll d = mp[L];
	L++, R--;
	ms.erase(ms.find(d));
	ll res1 = query(root[R], 1, a[x] - 1, 1, n).he - query(root[x], 1, a[x] - 1, 1, n).he;
	ll res2 = query(root[x - 1], a[x] + 1, n, 1, n).he - query(root[L - 1], a[x] + 1, n, 1, n).he;
	if (x - L + 1 <= R - x + 1) {
		ll ans1 = 0;
		ll res3 = 0;
		for (int i = L; i < x; i++) {
			ans1 += query(root[i], a[i] + 1, n, 1, n).he - query(root[L - 1], a[i] + 1, n, 1, n).he;
			res3 += query(root[R], 1, a[i] - 1, 1, n).he - query(root[x], 1, a[i] - 1, 1, n).he;
		}
//		if (L != x) 
		{
			mp[L - 1] = ans1;
			ms.insert(mp[L - 1]);
		}
//		if (x + 1 <= R) 
		{
			mp[x] = d - res1 - res2 - res3 - ans1;
			ms.insert(mp[x]);
		}
	} else {
		ll ans2 = 0;
		ll res3 = 0;
		for (int i = x + 1; i <= R; i++) {
			ans2 += query(root[i], a[i] + 1, n, 1, n).he - query(root[x], a[i] + 1, n, 1, n).he;
			res3 += query(root[x - 1], a[i] + 1, n, 1, n).he - query(root[L - 1], a[i] + 1, n, 1, n).he;
		}
//		if (L != x) 
		{
			mp[L - 1] = d - res1 - res2 - res3 - ans2;
			ms.insert(mp[L - 1]);
		}
//		if (x + 1 <= R) 
		{
			mp[x] = ans2;
			ms.insert(mp[x]);
		}

	}
}





void solve() {
	ms.clear();
	mp.clear();
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		modify(root[i], root[i - 1], 1, n, a[i]);
	}

	ll tmp = 0;
	for (int i = 1; i <= n; i++) {
		tmp += query(root[i], a[i] + 1, n, 1, n).he;
//		cout << i << ": " << tmp << '\n';
	}
//	cout << query(root[5], 1, n, 1, n).he << '\n';
	ms.insert(tmp);
	mp[0] = tmp;
	mp[n + 1] = 0;
	ms.insert(0);
//	for (int i = 1; i <= n; i++) {
//		ll x;
//		cin >> x;
//		cout << x << " ";
//	}
//	cout << '\n';
	for (int i = 1; i <= n; i++) {
		auto o = ms.end();
		o--;
		ll x;
		cin >> x;
		x = x ^ (*o);
//		cout << x << " ";
		cout << (*o) << " ";
//		cout << x << " ";
//		cout << ms.size() << '\n';
		auto t = prev(mp.lower_bound(x));
		auto R = next(t);
//		cout << t.first << " " << t.second << '\n';
		spilt((*t).first, (*R).first, x);
	}
	cout << '\n';
}
signed main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(2);
	int T = 1;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}
/*
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

*/


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: -100
Runtime Error

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: