QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#339143#6400. Game: CelesteDualqwqWA 99ms5272kbC++173.1kb2024-02-26 20:01:112024-02-26 20:01:11

Judging History

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

  • [2024-02-26 20:01:11]
  • 评测
  • 测评结果:WA
  • 用时:99ms
  • 内存:5272kb
  • [2024-02-26 20:01:11]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

namespace FastIO {
	#define iL (1 << 20)
	char ibuf[iL],*iS = ibuf + iL,*iT = ibuf + iL;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread(ibuf,1,iL,stdin),iS == iT ? EOF : *iS++) : *iS++)
	template<typename T>
	inline void read(T &a)
	{
		char ch;int sign = 0;
		for(ch = gc();!isdigit(ch);ch = gc())
			if(ch == '-') sign = 1;
		a = ch & 15;
		for(ch = gc();isdigit(ch);ch = gc())
			a = (a << 3) + (a << 1) + (ch & 15);
		if(sign) a = -a;
	}
	char Out[iL],*iter = Out;
	#define flush() fwrite(Out,1,iter - Out,stdout),iter = Out
	template<typename T>
	inline void write(T x,char end = '\n')
	{
		int c[40],l = 0;if(x < 0) *iter++ = '-',x = -x;
		do c[++l] = x % 10,x /= 10; while(x);
		while(l) *iter++ = c[l--] + '0';
		*iter++ = end;flush();
	}
	#undef iL 
	#undef gc
	#undef flush
}
using namespace FastIO;

const int N = 1e6 + 5,Sz = N * 43;
typedef unsigned long long ull;
int n,x[N],a[N],L,R;
int lc[Sz],rc[Sz],cnt[Sz],rt[N],tot;
ull hsh[Sz],Pow[N];
const ull base = 1e6 + 3;
void pushup(int k) { 
	cnt[k] = cnt[lc[k]] + cnt[rc[k]];
	hsh[k] = hsh[lc[k]] + Pow[cnt[lc[k]]] * hsh[rc[k]];
}
int clone(int v) {
	int p = ++tot;
	lc[p] = lc[v];rc[p] = rc[v];cnt[p] = cnt[v];hsh[p] = hsh[v];
	return p;
}
void insert(int &k,int lst,int l,int r,int pos,int v) {
	k = clone(lst);
	if(l == r) { cnt[k] += v;hsh[k] += v;return;}
	int mid = l + r >> 1;
	if(pos <= mid) insert(lc[k],lc[lst],l,mid,pos,v);
	else insert(rc[k],rc[lst],mid + 1,r,pos,v);
	pushup(k);
}
bool Compare(int rt1,int rt2,int l,int r) {
	if(l == r) return cnt[rt1] < cnt[rt2];
	int mid = l + r >> 1;
	if(hsh[rc[rt1]] == hsh[rc[rt2]]) return Compare(lc[rt1],lc[rt2],l,mid);
	else return Compare(rc[rt1],rc[rt2],mid + 1,r);
}
void build(int &k,int l,int r) {
	k = ++tot;cnt[k] = hsh[k] = 0;
	if(l == r) return;
	int mid = l + r >> 1;
	build(lc[k],l,mid);build(rc[k],mid + 1,r);
}
bool Cmp(int x,int y) { return Compare(rt[x],rt[y],1,n);}
void print(int k,int l,int r) {
	if(l == r) {
		for(int i = 1;i <= cnt[k];i++) printf("%d ",l);
		return;
	}
	int mid = l + r >> 1;
	print(rc[k],mid + 1,r);print(lc[k],l,mid);
}
inline void work() {
	read(n);read(L);read(R);
	for(int i = 1;i <= n;i++) read(x[i]);
	for(int i = 1;i <= n;i++) read(a[i]);
	for(int i = 0;i <= n;i++) rt[i] = 0;
	for(int i = 1;i <= tot;i++)
		lc[i] = rc[i] = cnt[i] = hsh[i] = 0;
	tot = 0;
	Pow[0] = 1;
	for(int i = 1;i <= n;i++) Pow[i] = Pow[i - 1] * base;
	build(rt[0],1,n);
	insert(rt[1],rt[0],1,n,a[1],1);
	deque<int> Q;
	for(int i = 2,p = 1;i <= n;i++) {
		// printf("i:%d\n",i);
		while(p < i && x[p] <= x[i] - L) {
			if(!rt[p]) { ++p;continue;}
			while(!Q.empty() && Cmp(Q.back(),p)) Q.pop_back();
			Q.push_back(p);++p;
		}
		while(!Q.empty() && Q.front() < x[i] - R) Q.pop_front();
		if(Q.size()) {
			int v = Q.front();//printf("v:%d\n",v);
			insert(rt[i],rt[v],1,n,a[i],1);
			// printf("dp[%d]: ",i);
			// print(rt[i],1,n);printf("\n");
		}
	}
	if(!rt[n]) puts("-1");
	else {
		printf("%d\n",cnt[rt[n]]);
		print(rt[n],1,n);printf("\n");
	}
}
int main() {
	int T;
	read(T);
	while(T--) work();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3760kb

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: 99ms
memory: 5272kb

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 19 16 14 11 10 3 
-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 12 12 12 11 ...

result:

wrong answer 2nd lines differ - expected: '20 20 19 14 12 11 3', found: '20 19 16 14 11 10 3 '