QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#670599#9161. Naval battleRDFZchenyy0 2ms17972kbC++146.0kb2024-10-23 22:29:312024-10-23 22:29:33

Judging History

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

  • [2024-10-23 22:29:33]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:17972kb
  • [2024-10-23 22:29:31]
  • 提交

answer

#include<bits/stdc++.h>

#define ls (id<<1)
#define rs ((id<<1)|1)

#define MAXN 200005
#define MAXSZ 600005

const int mv=2000000001;

struct Crash{
    int t;
    int xp,yp;

    friend bool operator<(Crash a,Crash b){
        return a.t>b.t;
    }
};
struct Node{
    int pl,pr;
    int px,py;
    int s;
};

int n;
int u[MAXN],v[MAXN]; char c[MAXN];
int rk[MAXSZ]; int ans[MAXN];
int typ[MAXSZ];
int p[MAXSZ],pos[MAXSZ],pl[MAXSZ],pr[MAXSZ];
Node t[MAXSZ<<2];
std::priority_queue<Crash> pq;
std::set<int> upd,us; int lst=0;

Node merge(Node a,Node b){
    Node res;
    res.pl=a.pl,res.pr=b.pr;
    int v=mv;
    if((a.pr+1)&&(b.pl+1)){
        v=p[b.pl]-p[a.pr];
        res.px=a.pr,res.py=b.pl;
    }
    if(a.s<b.s){
        if(a.s<v) v=a.s,res.px=a.px,res.py=a.py;
    }else if(b.s<v) v=b.s,res.px=b.px,res.py=b.py;
    return res;
}
void build(int id,int l,int r){
    if(l==r){
        if(typ[l]==1) t[id].px=t[id].py=t[id].pl=-1,t[id].pr=l,t[id].s=mv;
        else t[id].px=t[id].py=t[id].pr=-1,t[id].pl=-1,t[id].s=mv;
        return;
    }
    int mid=(l+r)>>1;
    build(ls,l,mid),build(rs,mid+1,r);
    t[id]=merge(t[ls],t[rs]);
    return;
}
void del(int id,int l,int r,int pos){
    if(l==r) t[id].px=t[id].py=t[id].pl=t[id].pr=-1,t[id].s=mv;
    else{
        int mid=(l+r)>>1;
        if(pos<=mid) del(ls,l,mid,pos);
        else del(rs,mid+1,r,pos);
        t[id]=merge(t[ls],t[rs]);
    }
    return;
}
Node query(int id,int l,int r,int tl,int tr){
    if(tl<=l&&r<=tr) return t[id];
    int mid=(l+r)>>1;
    if(tr<=mid) return query(ls,l,mid,tl,tr);
    else if(tl>mid) return query(rs,mid+1,r,tl,tr);
    else return merge(query(ls,l,mid,tl,tr),query(rs,mid+1,r,tl,tr));
}

int read(){
    int res=0; char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9') res=(res<<3)+(res<<1)+(c^48),c=getchar();
    return res;
}
char readL(){
    char c=getchar();
    while(c<'A'||c>'Z') c=getchar();
    return c;
}

bool chk(int x,char a,char b){
    return c[x]=='a'||c[x]=='b';
}

bool cmp1(int x,int y){
    if(chk(x,'N','W')^chk(y,'N','W')) return chk(x,'N','W');
    else if(u[x]+v[x]!=u[y]+v[y]) return u[x]+v[x]<u[y]+v[y];
    else return u[x]<u[y];
}
bool cmp2(int x,int y){
    if(chk(x,'N','E')^chk(y,'N','E')) return chk(x,'N','E');
    else if(u[x]-v[x]!=u[y]-v[y]) return u[x]-v[x]<u[y]-v[y];
    else return u[x]<u[y];
}
bool cmp3(int x,int y){
    if(chk(x,'N','S')^chk(y,'N','S')) return chk(x,'N','S');
    else{
        if(chk(x,'N','S')){
            if(u[x]!=u[y]) return u[x]<u[y];
            else return v[x]<v[y];
        }else{
            if(v[x]!=v[y]) return v[x]<v[y];
            else return u[x]<u[y];
        }
    }
}

int main(){
    n=read();
    for(int i=1;i<=n;i++) u[i]=read(),v[i]=read(),c[i]=readL();
    for(int i=1;i<=n;i++) rk[n+n+i]=rk[n+i]=rk[i]=i;
    std::sort(rk+1,rk+n+1,cmp1); 
    std::sort(rk+n+1,rk+n+n+1,cmp2);
    std::sort(rk+n+n+1,rk+n+n+n+1,cmp3);
    for(int i=1;i<=n;i++){
        if(chk(rk[i],'N','W')){
            if(i==1) pl[1]=1;
            else if(u[rk[i]]+v[rk[i]]==u[rk[i-1]]+v[rk[i-1]]) pl[i]=pl[i-1];
            else pl[i]=i;
            typ[i]=(c[rk[i]]=='N'?1:-1); pos[rk[i]]=i; p[i]=u[rk[i]]-v[rk[i]];
        }else{
            if(i==1) pl[1]=1;
            else if(chk(rk[i-1],'N','W')) pl[i]=i;
            else if(u[rk[i]]+v[rk[i]]==u[rk[i-1]]+v[rk[i-1]]) pl[i]=pl[i-1];
            else pl[i]=i;
            typ[i]=(c[rk[i]]=='E'?1:-1); pos[rk[i]]=i; p[i]=u[rk[i]]-v[rk[i]];
        }
    }
    for(int i=n+1;i<=2*n;i++){
        if(chk(rk[i],'N','E')){
            if(i==n+1) pl[n+1]=n+1;
            else if(u[rk[i]]-v[rk[i]]==u[rk[i-1]]-v[rk[i-1]]) pl[i]=pl[i-1];
            else pl[i]=i;
            typ[i]=(c[rk[i]]=='E'?1:-1); pos[rk[i]+n]=i,p[i]=u[rk[i]]+v[rk[i]];
        }else{
            if(i==n+1) pl[n+1]=n+1;
            else if(chk(rk[i],'N','E')) pl[i]=i;
            else if(u[rk[i]]-v[rk[i]]==u[rk[i-1]]-v[rk[i-1]]) pl[i]=pl[i-1];
            else pl[i]=i;
            typ[i]=(c[rk[i]]=='S'?1:-1); pos[rk[i]+n]=i,p[i]=u[rk[i]]+v[rk[i]];
        }
    }
    for(int i=2*n+1;i<=3*n;i++){
        if(chk(rk[i],'N','S')){
            if(i==2*n+1) pl[2*n+1]=2*n+1;
            else if(u[rk[i]]==u[rk[i-1]]) pl[i]=pl[i-1];
            else pl[i]=i;
            typ[i]=(c[rk[i]]=='D'?1:-1); pos[rk[i]+n*2]=i,p[i]=v[rk[i]];
        }else{
            if(i==2*n+1) pl[2*n+1]=2*n+1;
            else if(chk(rk[i],'N','S')) pl[i]=i;
            else if(v[rk[i]]==v[rk[i-1]]) pl[i]=pl[i-1];
            else pl[i]=i;
            typ[i]=(c[rk[i]]=='E'?1:-1); pos[rk[i]+n*2]=i,p[i]=u[rk[i]];
        }
    }
    pr[3*n]=3*n;
    for(int i=3*n-1;i>=1;i--){
        if(pl[i]==pl[i+1]) pr[i]=pr[i+1];
        else pr[i]=i;
    }

    build(1,1,3*n);
    
    for(int i=1;i<=3*n;i++){
        if(pl[i]==i){
            Node d=query(1,1,3*n,pl[i],pr[i]);
            if(d.s!=mv) pq.push((Crash){d.s,d.px,d.py});
        }
    }
    while(!pq.empty()){
        if(pq.top().t>lst){
            us.clear();
            for(int i:upd){
                del(1,1,3*n,pos[i]); del(1,1,3*n,pos[i+n]); del(1,1,3*n,pos[i+2*n]);
                us.insert(pl[i]); us.insert(pl[i+n]); us.insert(pl[i+2*n]);
            }
            for(int i:us){
                Node d=query(1,1,3*n,pl[i],pr[i]);
                if(d.s!=mv) pq.push((Crash){d.s,d.px,d.py});                
            }
            upd.clear();
        }
        if(ans[rk[pq.top().xp]]<pq.top().t||ans[rk[pq.top().yp]]<pq.top().t){
            pq.pop(); continue;
        }
        ans[rk[pq.top().xp]]=ans[rk[pq.top().yp]]=pq.top().t;
        del(1,1,3*n,pq.top().xp),del(1,1,3*n,pq.top().yp);
        upd.insert(rk[pq.top().xp]),upd.insert(rk[pq.top().yp]);
        Node d=query(1,1,3*n,pl[pq.top().xp],pr[pq.top().xp]);
        if(d.s!=mv) pq.push((Crash){d.s,d.px,d.py});          
        lst=pq.top().t;
    }
    for(int i=1;i<=n;i++){
        if(!ans[i]) std::cout<<i<<'\n';
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 6
Accepted
time: 0ms
memory: 17948kb

input:

2
675333810 792019962 W
851860476 960355168 W

output:

1
2

result:

ok 

Test #2:

score: 6
Accepted
time: 2ms
memory: 17940kb

input:

2
714148610 688520844 W
359519570 789553998 S

output:

1
2

result:

ok 

Test #3:

score: 6
Accepted
time: 0ms
memory: 17952kb

input:

2
743286406 87591094 E
108453484 326740470 S

output:

1
2

result:

ok 

Test #4:

score: 0
Wrong Answer
time: 2ms
memory: 17972kb

input:

2
629499666 659260200 W
391550936 897208930 N

output:

1
2

result:

FAIL Unexpected end of file - token expected (/var/uoj_data/9161/4.ans)

Subtask #2:

score: 0
Runtime Error

Test #14:

score: 0
Runtime Error

input:

100
32 46 N
8 24 W
74 86 W
2 76 N
90 70 N
34 74 N
4 68 N
42 26 N
66 94 N
28 40 W
96 12 W
82 78 W
54 24 N
36 42 W
92 68 W
0 26 N
14 54 N
94 66 N
26 52 N
66 12 W
72 6 W
64 96 W
6 20 N
4 22 W
26 42 N
40 28 W
70 76 N
18 60 N
62 16 N
30 48 N
36 36 W
42 36 W
52 94 N
62 98 N
0 78 N
70 2 W
28 50 N
80 80 W
8...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Runtime Error

Test #58:

score: 0
Runtime Error

input:

200000
526715640 430855204 E
731546662 226024182 S
254814720 702756124 E
227354364 730216480 S
764250602 193320242 S
150102088 807468756 E
204858572 752712272 S
635512190 322058654 E
403910248 553660596 S
257917918 4587926 S
949444340 8126504 S
907805098 49765746 S
553836306 403734538 S
40977864 617...

output:


result:


Subtask #7:

score: 0
Skipped

Dependency #1:

0%