QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#104124#6400. Game: CelesteHe_RenWA 244ms9808kbC++142.3kb2023-05-08 22:57:202023-05-08 22:57:21

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-08 22:57:21]
  • 评测
  • 测评结果:WA
  • 用时:244ms
  • 内存:9808kb
  • [2023-05-08 22:57:20]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e6 + 5;
const int MAXP = MAXN * 20;

mt19937 gen(114514);

const int mod = 1e9 + 7;
const int base = uniform_int_distribution<int>(1, mod / 10)(gen) + mod / 10;

int pwbase[MAXN];

namespace SegT
{
	int ls[MAXP], rs[MAXP], val[MAXP], pcnt;
	#define lson(u) ls[u],l,mid
	#define rson(u) rs[u],mid+1,r
	int new_Node(int v)
	{
		int u = ++pcnt;
		ls[u] = ls[v]; rs[u] = rs[v];
		val[u] = val[v];
		return u;
	}
	void insert(int &u,int l,int r,int q)
	{
		u = new_Node(u);
		if(l == r){ ++val[u]; return;}
		int mid = (l+r)>>1;
		if(q<=mid) insert(lson(u),q);
		else insert(rson(u),q);
		val[u] = ((ll)val[ls[u]] * pwbase[r-mid] + val[rs[u]]) %mod;
	}
	int cmp(int u,int v,int l,int r)
	{
		if(val[u] == val[v]) return 0;
		if(l == r) return val[u] - val[v];
		int mid = (l+r)>>1;
		int res = cmp(rs[u], rson(v));
		return res == 0? cmp(ls[u], lson(v)): res;
	}
	void dfs(int u,int l,int r,vector<int> &res)
	{
		if(u == 0) return;
		if(l == r)
		{
			res.insert(res.end(), val[u], l);
			return;
		}
		int mid = (l+r)>>1;
		dfs(rson(u),res); dfs(lson(u),res);
	}
}

int a[MAXN], b[MAXN];

void solve(void)
{
	int n,L,R;
	scanf("%d%d%d",&n,&L,&R);
	for(int i=1; i<=n; ++i)
		scanf("%d",&a[i]);
	for(int i=1; i<=n; ++i)
		scanf("%d",&b[i]);
	
	SegT :: pcnt = 0;
	
	static int rt[MAXN];
	fill(rt+1, rt+n+1, 0);
	
	static int q[MAXN];
	int hd = 1, tl = 0;
	
	auto push = [&] (int i)
	{
		if(rt[i] == -1) return;
		while(hd <= tl && SegT :: cmp(rt[q[tl]], rt[i], 1, n) <= 0)
			--tl;
		q[++tl] = i;
	};
	
	SegT :: insert(rt[1],1,n, b[1]);
	
	for(int i=2,j=1; i<=n; ++i)
	{
		while(a[j] <= a[i] - L)
			push(j), ++j;
		while(hd <= tl && q[hd] < a[i] - R)
			++hd;
		
		if(hd > tl)
		{
			rt[i] = -1;
			continue;
		}
		
		rt[i] = rt[q[hd]];
		SegT :: insert(rt[i],1,n, b[i]);
	}
	
	if(rt[n] == -1)
	{
		printf("-1\n");
		return;
	}
	
	vector<int> res;
	SegT :: dfs(rt[n],1,n,res);
	
	printf("%d\n",(int)res.size());
	for(auto t: res)
		printf("%d ",t);
	printf("\n");
}

int main(void)
{
	pwbase[0] = 1;
	for(int i=1; i<MAXN; ++i)
		pwbase[i] = (ll)pwbase[i-1] * base %mod;
	
	int T;
	scanf("%d",&T);
	while(T--) solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 9808kb

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: 244ms
memory: 9516kb

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
-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 4th lines differ - expected: '6', found: '-1'