QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209808#7108. CouleurPetroTarnavskyi#AC ✓2335ms25888kbC++172.6kb2023-10-10 17:42:512023-10-10 17:42:52

Judging History

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

  • [2023-10-10 17:42:52]
  • 评测
  • 测评结果:AC
  • 用时:2335ms
  • 内存:25888kb
  • [2023-10-10 17:42:51]
  • 提交

answer

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

using namespace __gnu_pbds;
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first	
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

typedef tree<PII, null_type, less<PII>, rb_tree_tag,
	tree_order_statistics_node_update> ordered_set;

const int INF = 1'000'000'747;
const int N = 100'447;

struct node
{
	int sz;
	ordered_set s;
	LL ans;
	
	node()
	{
		sz = 0;
		ans = 0;
	}
	
	void clear()
	{
		sz = 0;
		ans = 0;
		s.clear();
	}
	
	void addR(int x, int i)
	{
		ans += sz - s.order_of_key({x, INF});
		s.insert({x, i});
		sz++;
	}
	
	void addL(int x, int i)
	{
		ans += s.order_of_key({x, -1});
		s.insert({x, i});
		sz++;
	}
	
	void removeR(int x, int i)
	{
		sz--;
		s.erase({x, i});
		ans -= sz - s.order_of_key({x, INF});
	}
	
	void removeL(int x, int i)
	{
		sz--;
		s.erase({x, i});
		ans -= s.order_of_key({x, -1});
	}
};

node A[N];

void solve()
{
	int n;
	cin >> n;
	
	int idx = 1;
	
	map<int, int> s;
	multiset<LL> ans;
	VI a(n);
	FOR (i, 0, n)
	{
		cin >> a[i];
		A[0].addR(a[i], i);
	}
	s[0] = 0;
	s[n] = -1;
	ans.insert(A[0].ans);
	
	LL z = 0;
	FOR (i, 0, n)
	{
		z = *prev(ans.end());
		if (i)
			cout << ' ';
		cout << z;
		
		LL p;
		cin >> p;
		p ^= z;
		p--;
		auto it = prev(s.upper_bound(p));
		int l = it->F;
		int r = next(it)->F - 1;
		int id = it->S;
		ans.erase(ans.find(A[id].ans));
		s.erase(p);
		
		if (p - l <= r - p)
		{
			FOR (j, l, p)
			{
				A[id].removeL(a[j], j);
				A[idx].addR(a[j], j);
			}
			A[id].removeL(a[p], p);
			
			s[l] = idx;
			ans.insert(A[idx].ans);
			s[p + 1] = id;
			ans.insert(A[id].ans);
			//cerr << "1 " << A[id].ans << ' ' << A[idx].ans << '\n';
		}
		else
		{
			RFOR (j, r + 1, p + 1)
			{
				A[id].removeR(a[j], j);
				A[idx].addL(a[j], j);
			}
			A[id].removeR(a[p], p);
			
			s[l] = id;
			ans.insert(A[idx].ans);
			s[p + 1] = idx;
			ans.insert(A[id].ans);
			
			//cerr << "2 " << A[id].ans << ' ' << A[idx].ans << '\n';
		}
		idx++;
		s[p] = -1;
	}
	FOR (i, 0, n)
	{
		A[i].clear();
	}
	cout << '\n';
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(15);

	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
		
	cerr << double(clock()) / CLOCKS_PER_SEC << '\n';
	return 0;
}

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

详细

Test #1:

score: 100
Accepted
time: 6ms
memory: 15044kb

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: 2335ms
memory: 25888kb

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