QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#714582#7108. CouleurIUT_Bhalochelera#RE 0ms0kbC++233.0kb2024-11-06 00:29:212024-11-06 00:29:22

Judging History

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

  • [2024-11-06 00:29:22]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-06 00:29:21]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
#define all(V) V.begin (), V.end ()

using LL = long long;
using ordered_multiset = tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>;

void solve (int tc) {
	int n; cin>>n;
	vector<int> a(n);
	ordered_multiset os[n + 1];
	multiset<LL> allInv;
	set<pair<int, int>> ranges; ranges.insert({0, n - 1});
	LL ans = 0;
	for(int i = 0; i < n; i++){
		cin>>a[i];
		int large = i - os[0].order_of_key(a[i] + 1);
		ans += large;
		os[0].insert(a[i]);
	}
		// cout<<ans<<'\n';
	allInv.insert(ans);
	allInv.insert(0);
	LL ansInRange[n] = {}; ansInRange[0] = ans;
	for(int i = 0; i < n; i++){
		LL p; cin>>p; 
		p ^= ans; 
		cerr<<p<<" "<<ans<<'\n'; cout<<ans<<'\n';
		p--;
		for(auto [L, R]: ranges) cerr<<"Time "<<i<<" Set e ase --> "<<L<<" "<<R<<'\n';
		auto [l, r] = *prev (ranges.upper_bound ({p, 0}));
		cerr<<"LR--> "<<l<<" "<<r<<" "<<p<<'\n';
		allInv.erase(allInv.find(ansInRange[l]));
		ranges.erase({l, r});
		if(l == r){
			// an
			continue;
		}
		if(p == r){
			ansInRange[l] -= (r - l - os[l].order_of_key(a[p] + 1));
			os[l].erase(os[l].find_by_order(os[l].order_of_key(a[p])));
			allInv.insert(ansInRange[l]);
			if(p > l) ranges.insert({l, p - 1});
			auto it = allInv.end(); it--;
			ans = *it;
			continue;
		}
		if(r - p > p - l){
			swap(os[l], os[p + 1]); 
			LL tmp = 0;
			for(int j = l; j < p; j++){
				os[p + 1].erase(os[p + 1].find_by_order(os[p + 1].order_of_key(a[j])));
				LL large = j - l - os[l].order_of_key(a[j] + 1);
				tmp += large;
				os[l].insert(a[j]);
			}
			for(int j = l; j < p; j++){
				LL small = os[p + 1].order_of_key(a[j]);
				ansInRange[l] -= small;
			}
			ansInRange[l] -= os[p + 1].order_of_key(a[p]);
			os[p + 1].erase(os[p + 1].find_by_order(os[p + 1].order_of_key(a[p])));
			ansInRange[p + 1] = ansInRange[l];
			ansInRange[l] = tmp;

			allInv.insert(ansInRange[l]);
			allInv.insert(ansInRange[p + 1]);
		}else{
			LL tmp = 0;
			for(int j = p + 1; j <= r; j++){
				os[l].erase(os[l].find_by_order(os[l].order_of_key(a[j])));
				LL large = j - p - 1 - os[p + 1].order_of_key(a[j] + 1);
				tmp += large;
				os[p + 1].insert(a[j]);
			}
			for(int j = p + 1; j <= r; j++){
				LL large = (p - l + 1) - os[l].order_of_key(a[j] + 1);
				ansInRange[l] -= large;
			}
			ansInRange[l] -= (p - l + 1) - os[l].order_of_key(a[p] + 1);
			os[l].erase(os[l].find_by_order(os[l].order_of_key(a[p])));
			ansInRange[p + 1] = tmp;

			allInv.insert(ansInRange[l]);
			allInv.insert(ansInRange[p + 1]);
		}
		if(p > l)
			ranges.insert({l, p - 1});
		if(r > p)
			ranges.insert({p + 1, r});

		for(auto ij: allInv) cerr<<ij<<" "; cerr<<'\n';
		auto it = allInv.end(); it--;
		ans = *it;
	}
} 

int main () {
	cin.tie (nullptr) -> ios_base :: sync_with_stdio (false);

	int tests = 1;
	cin >> tests;
	for (int tc = 1; tc <= tests; tc++) {
		solve (tc);
	}

	return 0;
}

详细

Test #1:

score: 0
Runtime Error

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
1
0
0
0
0
1
42
32
0

result: