QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#610807#6400. Game: CelesteeuphonWA 176ms1025536kbC++202.5kb2024-10-04 17:31:392024-10-04 17:31:42

Judging History

This is the latest submission verdict.

  • [2024-10-04 17:31:42]
  • Judged
  • Verdict: WA
  • Time: 176ms
  • Memory: 1025536kb
  • [2024-10-04 17:31:39]
  • Submitted

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];


inline void init(int u)
{
	tr[u] = {0,0,0,Hash()};
}


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)
	{
		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 = 1; i <= n; ++i)
		// 	std::cout<<val[i].x<<' '<<val[i].y<<'\n';

		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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 43ms
memory: 1024164kb

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: 176ms
memory: 1025536kb

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 11 11 4 3 1 
28
20 19 16 16 15 15 14 13 13 12 12 11 11 8 8 7 7 6 6 5 5 4 4 4 4 4 2 1 
6
6 5 3 2 1 1 
10
19 18 18 17 17 11 10 9 7 7 
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 ...

result:

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