QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#611914 | #6400. Game: Celeste | euphon | WA | 184ms | 1019856kb | C++20 | 3.8kb | 2024-10-05 00:13:11 | 2024-10-05 00:13:13 |
Judging History
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];
// bool DBG;
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(20061010);
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].hsh;
// std::cout<<l<<' '<<r<<'\n';
// std::cout<<tr[q].hsh.x<<' '<<tr[q].hsh.y<<'\n';
// std::cout<<val[d].x<<' '<<val[d].y<<'\n';
// std::cout<<"\n\n\n";
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(DBG)
// {
// std::cout<<l<<' '<<r<<'\n';
// std::cout<<tr[p].hsh.x<<' '<<tr[p].hsh.y<<' '<<tr[q].hsh.x<<' '<<tr[q].hsh.y<<'\n';
// std::cout<<tr[tr[p].rs].hsh.x<<' '<<tr[tr[q].rs].hsh.x<<'\n';
// std::cout<<tr[tr[p].rs].hsh.y<<' '<<tr[tr[q].rs].hsh.y<<'\n';
// std::cout<<tr[p].cnt<<' '<<tr[q].cnt<<'\n';
// std::cout<<"ENDDDD\n";
// }
if(p == 0) return true;
if(q == 0) return false;
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()};
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;
// printf("modifying node %d\n",1);
modify(0,idx,1,n,a[1]);
// std::cout<<"\n\n\n\n\n";
// q.push_back(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;
// if(i == 21)
// {
// for(auto &t : q)
// std::cout<<t<<' ';
// std::cout<<'\n';
// }
reach[i] = true;
pre[i] = q.front();
root[i] = ++idx;
// printf("modifying node %d\n",i);
modify(root[q.front()],idx,1,n,a[i]);
// std::cout<<"\n\n\n\n\n";
}
// for(int i = 1; i<= n; ++i)
// {
// std::cout<<reach[i]<<' ';
// if(i % 10 == 0)
// std::cout<<'\n';
// }
// return 0;
// show(root[21],1,n);
// show(root[11],1,n);
// std::cout<<"\n";
// show(root[12],1,n);
// std::cout<<"\n";
// DBG = true;
// std::cout<<cmp(root[11],root[12],1,n)<<"AOSJHDFA\n";
// int now = 47;
// while(now)
// {
// std::cout<<now<<' ';
// now = pre[now];
// }
// return 0;
//// 1 11 21 30 39 47 57
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: 20ms
memory: 1019856kb
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: 184ms
memory: 1019184kb
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 142nd lines differ - expected: '20 20 20 19 19 18 17 16 16 15 13 12 11 8 7 4 1', found: '20 20 20 19 19 18 16 16 15 14 13 12 11 8 7 4 1 '