QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748679#9161. Naval battlemiaomiaomiaowu#6 2ms12200kbC++207.8kb2024-11-14 21:03:162024-11-14 21:03:16

Judging History

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

  • [2024-11-14 21:03:16]
  • 评测
  • 测评结果:6
  • 用时:2ms
  • 内存:12200kb
  • [2024-11-14 21:03:16]
  • 提交

answer

#include<bits/stdc++.h>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MP make_pair
#define pii pair<int,int>
const double PI=acos(-1.0);
template <class Miaowu>
inline void in(Miaowu &x){
    char c;x=0;bool f=0;
    for(c=getchar();c<'0'||c>'9';c=getchar())f|=c=='-';
    for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c^48);
    x=f?-x:x;
}
struct fastmod{
    typedef unsigned long long u64;
    typedef __uint128_t u128;
    int m;u64 b;
    fastmod(int m):m(m),b(((u128)1<<64)/m){}
    int reduce(u64 a){
        u64 q=((u128)a*b)>>64;
        int r=a-q*m;
        return r<m?r:r-m;
    }
}z(2);
const int N=2e5+5;
const int M=2e7+5;
int n,numx[N],numy[N],num1[N],num2[N],num3[N],num4[N];
bool ban[N];
struct Ship{
    int x,y,nx,ny;
    int xx,yy,add,dec;
    char dir;
}a[N];
struct Node{
    int x,y,tim;
    bool operator < (const Node &rhs) const{
        return tim>rhs.tim;
    }
};
priority_queue<Node>Q;
inline int max3(int x,int y,int z){
    return max(max(x,y),z);
}
inline int min3(int x,int y,int z){
    return min(min(x,y),z);
}
struct SGT{
    int rtn[N][3],rts[N][3],rtw[N][3],rte[N][3];
    int ind,pl[M],vl[M],ls[M],rs[M],pr[M],vr[M];
    inline void pu(int u){
        if(!vl[ls[u]])vl[u]=vl[rs[u]],pl[u]=pl[rs[u]];
        else vl[u]=vl[ls[u]],pl[u]=pl[ls[u]];
        if(!vr[rs[u]])vr[u]=vr[ls[u]],pr[u]=pr[ls[u]];
        else vr[u]=vr[rs[u]],pr[u]=pr[rs[u]];
    }
    inline void upd(int &u,int l,int r,int v,int p,int op){
        if(!u)u=++ind;
        if(l==r){
            if(op==1)pl[u]=pr[u]=p,vl[u]=vr[u]=v;
            else pl[u]=pr[u]=vl[u]=vr[u]=0;
            return;
        }
        int mid=l+r>>1;
        mid>=v?upd(ls[u],l,mid,v,p,op):upd(rs[u],mid+1,r,v,p,op);
        pu(u);
    }
    inline pii binary1(int u,int l,int r,int p){
        if(!u||l>p)return MP(-1,-1);
        if(r<=p)return pr[u]?MP(pr[u],vr[u]):MP(-1,-1);
        int mid=l+r>>1;
        pii qwq=binary1(rs[u],mid+1,r,p);
        if(qwq.first!=-1)return qwq;
        return binary1(ls[u],l,mid,p);
    }
    inline pii binary2(int u,int l,int r,int p){
        if(!u||r<p)return MP(-1,-1);
        if(l>=p)return pl[u]?MP(pl[u],vl[u]):MP(-1,-1);
        int mid=l+r>>1;
        pii qwq=binary2(ls[u],l,mid,p);
        if(qwq.first!=-1)return qwq;
        return binary2(rs[u],mid+1,r,p);
    }
}sgt;
inline void upd(int i,int x){
    if(a[i].dir=='N'){
        sgt.upd(sgt.rtn[a[i].xx][0],1,n,a[i].ny,i,x);
        sgt.upd(sgt.rtn[a[i].dec][1],1,n,a[i].ny,i,x);
        sgt.upd(sgt.rtn[a[i].add][2],1,n,a[i].ny,i,x);
    }
    else if(a[i].dir=='S'){
        sgt.upd(sgt.rts[a[i].xx][0],1,n,a[i].ny,i,x);
        sgt.upd(sgt.rts[a[i].dec][1],1,n,a[i].ny,i,x);
        sgt.upd(sgt.rts[a[i].add][2],1,n,a[i].ny,i,x);
    }
    else if(a[i].dir=='W'){
        sgt.upd(sgt.rtw[a[i].yy][0],1,n,a[i].nx,i,x);
        sgt.upd(sgt.rtw[a[i].dec][1],1,n,a[i].nx,i,x);
        sgt.upd(sgt.rtw[a[i].add][2],1,n,a[i].nx,i,x);
    }
    else{
        sgt.upd(sgt.rte[a[i].yy][0],1,n,a[i].nx,i,x);
        sgt.upd(sgt.rte[a[i].dec][1],1,n,a[i].nx,i,x);
        sgt.upd(sgt.rte[a[i].add][2],1,n,a[i].nx,i,x);
    }
}
inline pii Find(int i){
    pii qwq0,qwq1,qwq2;
    if(a[i].dir=='N'){
        qwq0=sgt.binary1(sgt.rts[a[i].xx][0],1,n,a[i].ny);
        qwq1=sgt.binary1(sgt.rte[a[i].dec][1],1,n,a[i].nx);
        qwq2=sgt.binary2(sgt.rtw[a[i].add][2],1,n,a[i].nx);
        if(qwq0.first!=-1)qwq0.second=(a[i].y-numy[qwq0.second]>>1);
        if(qwq1.first!=-1)qwq1.second=a[i].x-numx[qwq1.second];
        if(qwq2.first!=-1)qwq2.second=numx[qwq2.second]-a[i].x;
    }
    else if(a[i].dir=='S'){
        qwq0=sgt.binary2(sgt.rtn[a[i].xx][0],1,n,a[i].ny);
        qwq1=sgt.binary1(sgt.rte[a[i].add][2],1,n,a[i].nx);
        qwq2=sgt.binary2(sgt.rtw[a[i].dec][1],1,n,a[i].nx);
        if(qwq0.first!=-1)qwq0.second=(numy[qwq0.second]-a[i].y>>1);
        if(qwq1.first!=-1)qwq1.second=a[i].x-numx[qwq1.second];
        if(qwq2.first!=-1)qwq2.second=numx[qwq1.second]-a[i].x;
    }
    else if(a[i].dir=='W'){
        qwq0=sgt.binary1(sgt.rte[a[i].yy][0],1,n,a[i].nx);
        qwq1=sgt.binary2(sgt.rtn[a[i].add][2],1,n,a[i].ny);
        qwq2=sgt.binary1(sgt.rts[a[i].dec][1],1,n,a[i].ny);
        if(qwq0.first!=-1)qwq0.second=(a[i].x-numx[qwq0.second]>>1);
        if(qwq1.first!=-1)qwq1.second=numy[qwq1.second]-a[i].y;
        if(qwq2.first!=-1)qwq2.second=a[i].y-numy[qwq2.second];
    }
    else{
        qwq0=sgt.binary2(sgt.rtw[a[i].yy][0],1,n,a[i].nx);
        qwq1=sgt.binary2(sgt.rtn[a[i].dec][1],1,n,a[i].ny);
        qwq2=sgt.binary1(sgt.rts[a[i].add][2],1,n,a[i].ny);
        if(qwq0.first!=-1)qwq0.second=(numx[qwq0.second]-a[i].x>>1);
        if(qwq1.first!=-1)qwq1.second=numy[qwq1.second]-a[i].y;
        if(qwq2.first!=-1)qwq2.second=a[i].y-numy[qwq2.second];
    }
    if(max3(qwq0.first,qwq1.first,qwq2.first)==-1)return MP(-1,-1);
    if(qwq0.first==-1)qwq0.second=2e9+5;
    if(qwq1.first==-1)qwq1.second=2e9+5;
    if(qwq2.first==-1)qwq2.second=2e9+5;
    int mn=min3(qwq0.second,qwq1.second,qwq2.second);
    if(mn==qwq0.second)return qwq0;
    if(mn==qwq1.second)return qwq1;
    return qwq2;
}
int main(){
    in(n);
    for(int i=1;i<=n;i++){
        in(a[i].x),in(a[i].y);
        char tuu[5];scanf("%s",tuu);a[i].dir=tuu[0];
        numx[++numx[0]]=a[i].x,numy[++numy[0]]=a[i].y;
        num1[++num1[0]]=a[i].x,num2[++num2[0]]=a[i].y;
        num3[++num3[0]]=a[i].x+a[i].y,num4[++num4[0]]=a[i].x-a[i].y;
    }
    stable_sort(num1+1,num1+num1[0]+1);
    num1[0]=unique(num1+1,num1+num1[0]+1)-num1-1;
    stable_sort(num2+1,num2+num2[0]+1);
    num2[0]=unique(num2+1,num2+num2[0]+1)-num2-1;
    stable_sort(num3+1,num3+num3[0]+1);
    num3[0]=unique(num3+1,num3+num3[0]+1)-num3-1;
    stable_sort(num4+1,num4+num4[0]+1);
    num4[0]=unique(num4+1,num4+num4[0]+1)-num4-1;
    stable_sort(numx+1,numx+numx[0]+1);
    stable_sort(numy+1,numy+numy[0]+1);
    numx[0]=unique(numx+1,numx+numx[0]+1)-numx-1;
    numy[0]=unique(numy+1,numy+numy[0]+1)-numy-1;
    for(int i=1;i<=n;i++){
        a[i].nx=lower_bound(numx+1,numx+numx[0]+1,a[i].x)-numx;
        a[i].ny=lower_bound(numy+1,numy+numy[0]+1,a[i].y)-numy;
        a[i].xx=lower_bound(num1+1,num1+num1[0]+1,a[i].x)-num1;
        a[i].yy=lower_bound(num2+1,num2+num2[0]+1,a[i].y)-num2;
        a[i].add=lower_bound(num3+1,num3+num3[0]+1,a[i].x+a[i].y)-num3;
        a[i].dec=lower_bound(num4+1,num4+num4[0]+1,a[i].x-a[i].y)-num4;
    }
    for(int i=1;i<=n;i++)upd(i,1);
    for(int tt=1;tt<=n;tt++){
        int mnt=2e9,x=-1,y=-1;
        for(int i=1;i<=n;i++)if(!ban[i]){
            pii qwq=Find(i);
            if(qwq.first!=-1){
                if(qwq.second<mnt)mnt=qwq.second,x=i,y=qwq.first;
            }
        }
        if(x==-1)break;
        ban[x]=ban[y]=1;
        upd(x,-1),upd(y,-1);
    }
    /*
    for(int i=1;i<=n;i++){
        pii qwq=Find(i);
        if(qwq.first!=-1)Q.push(Node{i,qwq.first,qwq.second});
    }
    while(!Q.empty()){
        vector<Node>vc;
        vc.push_back(Q.top());Q.pop();
        while(!Q.empty()&&Q.top().tim==vc[0].tim){
            vc.push_back(Q.top()),Q.pop();
        }
        set<int>S,SS;
        for(Node xx:vc){
            if(!ban[xx.x]&&!ban[xx.y]){
                SS.insert(xx.x),SS.insert(xx.y);
            }
            else{
                if(!ban[xx.x])S.insert(xx.x);
                if(!ban[xx.y])S.insert(xx.y);
            }
        }
        for(int xx:SS){
            ban[xx]=1,upd(xx,-1);
        }
        for(int xx:S)if(!ban[xx]){
            pii qwq=Find(xx);
            if(qwq.first!=-1)Q.push(Node{xx,qwq.first,qwq.second});
        }
    }
    */
    for(int i=1;i<=n;i++)if(!ban[i])printf("%d\n",i);
    return 0;
}

詳細信息

Subtask #1:

score: 6
Accepted

Test #1:

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

input:

2
675333810 792019962 W
851860476 960355168 W

output:

1
2

result:

ok 

Test #2:

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

input:

2
714148610 688520844 W
359519570 789553998 S

output:

1
2

result:

ok 

Test #3:

score: 6
Accepted
time: 1ms
memory: 12196kb

input:

2
743286406 87591094 E
108453484 326740470 S

output:

1
2

result:

ok 

Test #4:

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

input:

2
629499666 659260200 W
391550936 897208930 N

output:


result:

ok 

Test #5:

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

input:

2
509095668 374922996 W
325521434 191348762 S

output:


result:

ok 

Test #6:

score: 6
Accepted
time: 1ms
memory: 12008kb

input:

2
357656592 713571312 E
456601638 614626266 S

output:


result:

ok 

Test #7:

score: 6
Accepted
time: 1ms
memory: 12064kb

input:

2
353512742 374956722 W
265604916 462864548 N

output:


result:

ok 

Test #8:

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

input:

2
253519292 302668732 E
436627396 119560628 S

output:


result:

ok 

Test #9:

score: 6
Accepted
time: 1ms
memory: 12148kb

input:

2
741954822 709863076 W
516385128 484293380 S

output:

1
2

result:

ok 

Test #10:

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

input:

2
268851874 524109226 E
503673708 758931058 N

output:

1
2

result:

ok 

Test #11:

score: 6
Accepted
time: 1ms
memory: 12132kb

input:

2
629380956 395789270 S
557401140 467769088 E

output:

1
2

result:

ok 

Test #12:

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

input:

2
606361496 587557658 N
667076156 526843000 W

output:

1
2

result:

ok 

Test #13:

score: 6
Accepted
time: 1ms
memory: 12068kb

input:

2
270428340 629167054 N
270428342 179345630 S

output:

1
2

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Test #14:

score: 12
Accepted
time: 1ms
memory: 11996kb

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:

ok 

Test #15:

score: 12
Accepted
time: 2ms
memory: 12032kb

input:

100
70 62 N
56 42 N
42 56 W
64 4 N
50 48 W
56 76 N
78 20 W
96 96 W
60 72 N
44 24 N
2 10 N
52 80 W
38 30 N
94 4 W
58 74 W
68 30 W
54 76 N
0 68 N
36 32 N
10 58 W
70 60 W
86 92 N
100 78 W
2 66 W
20 48 N
16 52 N
8 60 N
98 94 N
86 46 W
74 24 W
26 42 W
66 66 W
28 40 W
56 12 W
90 42 W
8 4 W
76 30 W
78 54 W...

output:


result:

ok 

Test #16:

score: 12
Accepted
time: 1ms
memory: 12192kb

input:

100
36 44 E
96 66 E
28 20 E
36 2 E
32 64 W
76 58 E
82 20 E
76 50 E
22 48 W
38 52 E
90 16 N
22 12 W
64 82 S
84 14 E
92 52 E
76 36 E
72 52 N
100 58 S
82 4 E
2 0 N
90 100 E
68 8 S
24 36 S
80 86 W
72 56 W
8 66 W
84 18 S
18 60 N
64 96 E
2 76 S
74 90 E
64 0 S
12 10 S
56 40 S
40 6 S
2 4 S
74 2 S
90 80 N
2 ...

output:

1
2
3
4
5
6
8
10
11
12
13
14
15
19
20
21
23
24
26
28
29
30
31
32
33
35
36
37
39
40
41
42
45
46
47
48
49
50
51
53
54
56
57
58
59
61
62
63
64
65
69
70
71
73
74
76
77
78
79
81
83
84
85
87
89
91
92
93
95
96
98
99

result:

ok 

Test #17:

score: 12
Accepted
time: 0ms
memory: 12200kb

input:

100
24 52 S
72 60 E
72 64 W
98 52 N
46 30 E
18 62 W
70 6 S
14 58 S
12 24 W
2 54 E
20 58 S
70 40 S
8 90 E
92 16 S
26 42 E
72 8 N
46 48 S
18 64 N
80 78 E
46 20 S
26 76 W
56 68 N
82 2 N
78 72 N
54 6 N
98 8 S
52 64 N
64 88 W
6 90 N
58 96 S
30 4 E
54 48 N
36 10 S
4 32 S
20 40 W
70 30 W
16 16 W
84 80 N
52...

output:

1
2
9
11
13
14
15
16
17
19
21
22
23
24
25
26
28
29
30
32
35
37
38
39
40
44
45
46
47
48
49
51
55
57
58
59
61
62
63
64
65
66
67
68
71
72
74
76
79
80
81
84
86
87
88
90
92
93
95
96
99
100

result:

ok 

Test #18:

score: 0
Wrong Answer
time: 0ms
memory: 12172kb

input:

100
58 98 W
90 40 W
62 34 W
56 72 S
96 56 E
62 62 E
54 32 S
84 98 W
62 100 N
18 82 W
36 86 N
34 64 W
94 74 N
90 78 N
14 42 S
58 78 W
6 60 N
60 92 W
64 60 N
84 58 S
0 84 N
36 80 W
12 0 N
28 54 E
24 64 N
60 16 E
26 40 S
32 30 W
26 28 S
94 78 N
26 0 E
20 84 E
0 56 S
8 48 N
76 0 S
6 94 N
6 14 W
80 22 S
...

output:

1
3
4
5
9
11
12
13
14
15
18
19
20
22
23
24
25
28
29
30
32
34
37
38
41
43
47
49
50
53
55
56
58
59
60
62
63
65
66
68
69
72
73
74
75
76
77
78
79
80
81
82
86
88
89
91
92
94
97
98
99
100

result:

wrong answer 

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Time Limit Exceeded

Test #58:

score: 0
Time Limit Exceeded

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:

100%
Accepted

Dependency #2:

0%