QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#600892 | #6400. Game: Celeste | A_programmer | WA | 126ms | 20232kb | C++17 | 2.3kb | 2024-09-29 19:51:26 | 2024-09-29 19:51:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll base = 19260817;
const ll mod = 998244353;
const int maxn = 1e6 + 5;
const int N = 2e7 + 5;
int a[maxn], x[maxn];
ll mi[maxn];
int q[maxn], hd, tl;
int rt[maxn], cnt;
bool blk[maxn];
struct Tree
{
int ls[N], rs[N], vl[N];
ll hs[N];
int update(int p, int l, int r, int x)
{
int k = ++cnt; ls[k] = ls[p], rs[k] = rs[p], hs[k] = (hs[p] + mi[x]) % mod, vl[k] = vl[p] + 1;
if (l == r) return k;
int mid = (l + r) >> 1;
if (x <= mid) ls[k] = update(ls[p], l, mid, x);
else rs[k] = update(rs[p], mid + 1, r, x);
return k;
}
bool cmp(int k1, int k2, int l, int r)
{
if (!k1) return true;
if (!k2) return false;
if (l == r) return (vl[k1] <= vl[k2]);
int mid = (l + r) >> 1;
if (hs[ls[k1]] != hs[ls[k2]]) return cmp(ls[k1], ls[k2], l, mid);
else return cmp(rs[k1], rs[k2], mid + 1, r);
}
void travel(int k, int l, int r)
{
if (!k) return;
if (l == r)
{
for (int i = 1; i <= vl[k]; i++) cout << l << " ";
return;
}
int mid = (l + r) >> 1;
travel(rs[k], mid + 1, r); travel(ls[k], l, mid);
}
}T;
void work()
{
int n, L, R;
cin >> n >> L >> R; cnt = 0;
for (int i = 1; i <= n; i++) rt[i] = blk[i] = 0;
for (int i = 1; i <= n; i++) cin >> x[i];
for (int i = 1; i <= n; i++) cin >> a[i];
hd = 1, tl = 0; int pos = 1;
for (int i = 1; i <= n; i++)
{
while (pos <= n && x[pos] <= x[i] - L)
{
if (blk[pos]) { pos++; continue; }
while (hd <= tl && T.cmp(rt[q[tl]], rt[pos], 1, n)) tl--;
q[++tl] = pos++;
}
while (hd <= tl && x[q[hd]] < x[i] - R) hd++;
if (hd <= tl) rt[i] = T.update(rt[q[hd]], 1, n, a[i]);
else if (i == 1) rt[i] = T.update(0, 1, n, a[i]);
else blk[i] = 1;
}
if (blk[n]) return cout << "-1\n", void();
cout << T.vl[rt[n]] << "\n";
T.travel(rt[n], 1, n);
cout << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T; cin >> T;
mi[0] = 1; for (int i = 1; i < maxn; i++) mi[i] = mi[i - 1] * base % mod;
while (T--) work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 19980kb
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: 126ms
memory: 20232kb
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 11 9 7 7 3 2 1 -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 12 12...
result:
wrong answer 2nd lines differ - expected: '20 20 19 14 12 11 3', found: '11 9 7 7 3 2 1 '