QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#610949#6400. Game: CelesteeuphonWA 200ms1020856kbC++202.4kb2024-10-04 18:12:282024-10-04 18:12:29

Judging History

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

  • [2024-10-04 18:12:29]
  • 评测
  • 测评结果:WA
  • 用时:200ms
  • 内存:1020856kb
  • [2024-10-04 18:12:28]
  • 提交

answer

#include<bits/stdc++.h>

typedef long long ll;
const int mod1 = 999662017, mod2 = 998244353, N = 1e6+10;
int T,n,L,R;
struct Hash
{
	ll x,y;
	Hash(ll a = 0, ll b = 0)
	{
		x = a % mod1, y = b % mod2;
	}

}val[N];
// bool DBG;
Hash operator + (const Hash a, const Hash b)
{
	return {a.x + b.x, a.y + b.y};
}
bool operator == (const Hash a, const Hash b)
{
	return a.x == b.x && a.y == b.y;
}

struct node
{
	int ls,rs,cnt;
	Hash hsh;
}tr[N<<5];
int idx;
int root[N];
int pos[N],a[N];
std::mt19937_64 rnd(5201314);
bool reach[N];


void modify(int p,int q,int l,int r,int d)
{
	tr[q] = tr[p];
	tr[q].hsh = val[d] + tr[q].hsh;
	tr[q].cnt++;
	if(l == r)
	{
		return;
	}
	int mid = l + r >> 1;
	if(d <= mid)
	{
		tr[q].ls = ++idx;
		modify(tr[p].ls,tr[q].ls,l,mid,d);
	}
	else
	{
		tr[q].rs = ++idx;
		modify(tr[p].rs,idx,mid+1,r,d);
	}
}

bool cmp(int p,int q,int l,int r)
{
	if(l == r) return tr[p].cnt <= tr[q].cnt;
	int mid = l + r >> 1;
	if(tr[tr[p].rs].hsh == tr[tr[q].rs].hsh)
		return cmp(tr[p].ls,tr[q].ls,l,mid);
	return cmp(tr[p].rs,tr[q].rs,mid+1,r);
}

void show(int u,int l,int r)
{
	if(l == r)
	{
		for(int i = 0; i < tr[u].cnt; ++i)
			std::cout<<l<<' ';
		return;
	}
	int mid = l + r >> 1;
	show(tr[u].rs,mid+1,r),show(tr[u].ls,l,mid);
}
int pre[N];

int main()
{
	std::ios::sync_with_stdio(false),std::cin.tie(0);
	std::cin>>T;
	tr[0] = {0,0,0,Hash()};
	for(int i = 1; i <= 1e6; ++i)
		val[i] = Hash(rnd(),rnd());

	while(T--)
	{
		std::cin>>n>>L>>R;
		for(int i = 1; i <= n; ++i)
			std::cin>>pos[i];
		for(int i = 1; i <= n; ++i)
			std::cin>>a[i];

		for(int i = 1; i <= n; ++i)
			reach[i] = false;
		reach[1] = true;
		std::deque<int> q;
		idx = 0;
		root[1] = ++idx;
		modify(0,idx,1,n,a[1]);
		int id = 0;

		for(int i = 2; i <= n; ++i)
		{
			while(pos[id+1] + L <= pos[i])
			{
				++id;
				if(!reach[id]) continue;
				assert(id < i);

				while(q.size() && cmp(root[q.back()],root[id],1,n))
				{					
					q.pop_back();
				}
				q.push_back(id);
			}
			while(q.size() && pos[q.front()] < pos[i] - R) q.pop_front();
			if(!q.size()) continue;
			reach[i] = true;
			pre[i] = q.front();
			root[i] = ++idx;
			modify(root[q.front()],idx,1,n,a[i]);
		}

		if(!reach[n]) std::cout<<"-1\n";
		else
		{
			std::cout<<tr[root[n]].cnt<<'\n';
			show(root[n],1,n);
			std::cout<<'\n';
		}
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 48ms
memory: 1020856kb

input:

2
5 2 3
1 2 3 4 5
5 2 3 1 4
3 1 2
1 4 7
3 3 3

output:

3
5 4 3 
-1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 200ms
memory: 1019620kb

input:

10000
57 8 11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
11 16 7 7 10 13 9 14 10 1 12 4 8 13 3 20 16 7 16 19 20 8 19 7 16 6 17 13 7 19 17 11 12 17 6 3 7 8 14 2 4 15 5 18 16 7 20 9 1...

output:

7
20 20 19 14 12 11 3 
-1
6
6 5 3 2 1 1 
-1
185
20 20 20 20 20 20 20 20 19 19 19 19 19 19 19 19 19 19 19 19 18 18 18 18 18 17 17 17 17 17 17 17 17 16 16 16 16 16 16 16 16 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 14 14 14 14 14 14 14 13 13 13 13 13 13 13 13 13 12 12 12 12 12 12 12 ...

result:

wrong answer 860th lines differ - expected: '20 20 20 20 20 20 20 20 19 19 ...12 12 12 11 11 10 9 8 8 7 6 4 3', found: '20 20 20 20 20 20 20 20 19 19 ...12 12 11 11 10 9 8 7 6 6 4 3 1 '