QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#444038 | #6400. Game: Celeste | haozexu134 | WA | 151ms | 12096kb | C++14 | 2.3kb | 2024-06-15 17:08:32 | 2024-06-15 17:16:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
typedef long long ll;
#include<chrono>
#include<random>
unsigned int TS_since_epoch(){
using namespace chrono;
return duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
}
struct rnd{
mt19937 *_rand;
rnd(){_rand=new mt19937(TS_since_epoch());}
ll operator()(){return (*_rand)()%(100000);}
}rnd;
struct SegT{
int ls,rs;
ll hash;
}t[N*4];
int f[N],tot,mp[N],x[N],a[N],L,R,n;
#define ls(p) (t[p].ls)
#define rs(p) (t[p].rs)
#define hsh(p) (t[p].hash)
void Update(int p){hsh(p)=hsh(ls(p))+hsh(rs(p));}
int Alloc(int cpy){return t[++tot]=t[cpy],tot;}
void Insert(int &p,int old,int l,int r,int x){
p=Alloc(old);
if(l==r) return hsh(p)+=mp[x],void();
int mid=(l+r)/2;
if(x<=mid) Insert(ls(p),ls(old),l,mid,x);
else Insert(rs(p),rs(old),mid+1,r,x);
Update(p);
}
bool LessThan(int a,int b,int l,int r){
if(hsh(a)==hsh(b)) return true;
if(l==r) return hsh(a)<=hsh(b);
int mid=(l+r)/2;
if(hsh(rs(a))==hsh(rs(b))) return LessThan(rs(a),rs(b),mid+1,r);
else return LessThan(ls(a),ls(b),l,mid);
}
vector<int> ans;
void Output(int a,int l,int r){
if(l==r){
if(hsh(a)) for(int i=1;i<=hsh(a);i+=mp[l]) ans.push_back(l);
return;
}
int mid=(l+r)/2;
Output(rs(a),mid+1,r),Output(ls(a),l,mid);
}
void dp(){
fill(f+1,f+1+n,-1),f[0]=0;
deque<int> q;Insert(f[1],f[0],1,n,a[1]);
auto add=[&](int i){
while(!q.empty() and LessThan(f[q.back()],f[i],1,n)) q.pop_back();
q.push_back(i);
};
q.push_back(1);int cur=2;
for(int i=2;i<=n;i++){
while(cur<i and x[cur]<x[i]-R) cur++;
while(cur<i and (x[i]-R<=x[cur] and x[cur]<=x[i]-L)) add(cur++);
while(!q.empty() and q.front()<x[i]-R) q.pop_front();
if(!q.empty()) Insert(f[i],f[q.front()],1,n,a[i]);
}
}
void Clear(){
#define C(x) (memset(x,0,sizeof x))
tot=0;
}
void Read(){
Clear(),cin>>n>>L>>R;
for(int i=1;i<=n;i++) cin>>x[i];
for(int i=1;i<=n;i++) cin>>a[i];
}
int main(){
ios::sync_with_stdio(false);
int T;cin>>T;
for(int i=1;i<=1e6;i++) mp[i]=rnd();
while(T--){
Read(),dp();
if(f[n]==-1) cout<<"-1\n";
else{
ans.clear();
Output(f[n],1,n),cout<<ans.size()<<"\n";
for(int i:ans) cout<<i<<" ";
cout<<"\n";
}
}
}
/*FOOTNOTE
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11996kb
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: 151ms
memory: 12096kb
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:
8 16 16 12 11 11 10 4 3 28 20 19 16 16 15 15 14 13 13 12 12 11 11 8 8 7 7 6 6 5 5 4 4 4 4 4 2 1 -1 10 19 18 18 17 17 11 10 9 7 7 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...
result:
wrong answer 1st lines differ - expected: '7', found: '8'