QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#610820 | #6400. Game: Celeste | euphon | WA | 36ms | 1024384kb | C++20 | 2.7kb | 2024-10-04 17:34:18 | 2024-10-04 17:34:27 |
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];
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];
if(T == 9999)
{
// for(int i = 1; i <= n; ++i)
// std::cout<<pos[i]<<' ';
// std::cout<<'\n';
for(int i = 1; i <= n; ++i)
{
std::cout<<a[i]<<' ';
if(i % 10 == 0)
std::cout<<'\n';
}
std::cout<<'\n';
return 0;
}
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 20ms
memory: 1024384kb
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: 36ms
memory: 1022244kb
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:
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 11 2 15 11 19 5 16 4 3
result:
wrong answer 1st lines differ - expected: '7', found: '11 16 7 7 10 13 9 14 10 1 '