QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#610763#6400. Game: CelesteeuphonWA 240ms1024364kbC++202.4kb2024-10-04 17:19:062024-10-04 17:19:17

Judging History

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

  • [2024-10-04 17:19:17]
  • 评测
  • 测评结果:WA
  • 用时:240ms
  • 内存:1024364kb
  • [2024-10-04 17:19:06]
  • 提交

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;
	}
	Hash operator += (const Hash &t) const
	{
		return {x + t.x, y + t.y};
	}
	bool operator == (const Hash &t) const
	{
		return x == t.x && y == t.y;
	}
}val[N];

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].cnt++;
	if(l == r)
	{
		tr[q].cnt = 1;
		tr[q].hsh = val[d];
		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 main()
{
	std::ios::sync_with_stdio(false),std::cin.tie(0);
	std::cin>>T;
	tr[0] = {0,0,0,Hash()};
	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)
			val[i] = Hash(rnd(),rnd());
		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]);
		q.push_back(1);
		int id = 1;

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

				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()) break;
			reach[i] = true;
			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: 76ms
memory: 1020772kb

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: 240ms
memory: 1024364kb

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:

8
20 16 11 3 2 1 
28
20 19 16 15 14 13 12 11 8 7 6 5 4 2 1 
6
6 5 3 2 1 
10
19 18 17 11 10 9 7 
185
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 
21
20 19 17 15 10 9 8 7 6 5 4 2 1 
3
14 6 2 
162
20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 
17
15 14 13 12 11 10 8 7 6 3 2 1 
12
19 17 15 1...

result:

wrong answer 1st lines differ - expected: '7', found: '8'