QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687321 | #9221. Missing Boundaries | _Veritas# | WA | 100ms | 25460kb | C++14 | 3.6kb | 2024-10-29 18:18:33 | 2024-10-29 18:18:34 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int read() {
int x=0,w=1; char ch=0;
while(ch<'0'||ch>'9'){ if(ch=='-') w=-1; ch=getchar();}
while(ch>='0'&&ch<='9'){ x=x*10+(ch-'0'); ch=getchar();}
return x*w;
}
int n,L,lrcnt,anycnt;
struct Itv{
int l,r;
bool ck(int x,int y){
return ((l>0)==x)&&((r>0)==y);
}
};
vector<Itv> in;
vector<Itv> lr,emp,ll,rr;
struct halfitv{
int pos;
bool right;
};
map<int,int> numcnt;
bool covered(int x){
// cout<<"test cover: "<<x<<endl;
int l=0,r=lrcnt,mid,ans=-1;
while(l<=r){
mid=(l+r)/2;
if(lr[mid].l<=x) ans=mid,l=mid+1;
else r=mid-1;
}
if(ans==-1) return false;
if(lr[ans].r>=x) return true;
return false;
}
bool cmp(Itv x,Itv y){
if(x.l==y.l) return x.r<y.r;
return x.l<y.l;
}
bool cmph(halfitv x, halfitv y){
return x.pos<y.pos;
}
bool work(){
// puts("!!");
lrcnt=0;anycnt=0;
lr.clear();
emp.clear();
ll.clear();
rr.clear();
in.clear();
numcnt.clear();
// puts("??");
n=read();L=read();
in.push_back(Itv{-1,-1});
for(int i=1;i<=n;++i){
int x=read(),y=read();
numcnt[x]++;
numcnt[y]++;
if(x==-1&&y==-1) {++anycnt; }
in.push_back(Itv{-1,-1});
in[i].l=x;
in[i].r=y;
if(in[i].ck(1,1)) lr.push_back(in[i]);
if(in[i].ck(1,0)) ll.push_back(in[i]);
if(in[i].ck(0,1)) rr.push_back(in[i]);
}
for(auto x:numcnt) if(x.first!=-1&&x.second>1) return false;
sort(lr.begin(),lr.end(),cmp);
lrcnt = lr.size();
// puts(":2");
for(int i=1;i<lrcnt;++i){
if(lr[i-1].r>=lr[i].l) return false;
}
// puts(":3");
for(int i=1;i<=n;++i){
if(in[i].ck(1,0)){
if(covered(in[i].l)) return false;
}
else if(in[i].ck(0,1)){
if(covered(in[i].r)) return false;
}
}
// puts(":1");
if(lr.size()!=0){
if(lr[0].l!=1) emp.push_back(Itv{1,lr[0].l-1});
for(int i=1;i<lrcnt;++i){
if(lr[i-1].r>=lr[i].l) return false;
if(lr[i-1].r+1==lr[i].l) continue;
emp.push_back(Itv{lr[i-1].r+1,lr[i].l-1});
}
if(lr[lrcnt-1].r!=L) emp.push_back(Itv{lr[lrcnt-1].r+1,L});
}
else{
emp.push_back(Itv{1,L});
}
sort(ll.begin(),ll.end(),cmp);
sort(rr.begin(),rr.end(),cmp);
int llhead=0,lltail=0,rrhead=0,rrtail=0;
int gup=0,gdown=0;
for(auto& x:emp){
llhead=lltail;
rrhead=rrtail;
while(lltail<ll.size()&&x.l<=ll[lltail].l&&ll[lltail].l<=x.r) {
++lltail;
}
while(rrtail<rr.size()&&x.l<=rr[rrtail].r&&rr[rrtail].r<=x.r) {
++rrtail;
}
int anyup = x.r-x.l+1-(rrtail-rrhead)-(lltail-llhead);
int anydown = 0;
vector<halfitv> v;
for(int i=llhead;i<lltail;++i) v.push_back(halfitv{ll[i].l,false});
for(int i=rrhead;i<rrtail;++i) v.push_back(halfitv{rr[i].r,true});
sort(v.begin(),v.end(),cmph);
int vlen = v.size();
if(vlen==0) {
gdown++;
gup+=x.r-x.l+1;
continue;
}
if(!v[0].right) {
// anydown += v[0].pos-x.l+1;
if(v[0].pos!=x.l) anydown++;
}
if(v[vlen-1].right) {
// anydown += x.r-v[vlen-1].pos+1;
if(v[vlen-1].pos!=x.r) anydown++;
}
for(int i=1;i<vlen;++i){
if(v[i-1].right&&!v[i].right){
// anydown += v[i].pos-v[i-1].pos-1;
if(v[i-1].pos+1!=v[i].pos) anydown++;
}
}
// cout<<"DEBUG: "<<anyup<<" "<<anydown<<endl;
gup+=anyup;
gdown+=anydown;
}
// cout<<gup<<" "<<gdown<<endl;
if(gdown<=anycnt&&anycnt<=gup) return true;
return false;
}
signed main(){
int T=read();
while(T--) {
puts(work()?"TAK":"NIE");
// puts("!");
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3796kb
input:
3 4 51 1 -1 11 50 -1 -1 -1 10 3 2 -1 -1 -1 -1 -1 -1 2 3 1 2 2 3
output:
TAK NIE NIE
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 100ms
memory: 25460kb
input:
1 200000 1000000000 490669427 -1 224278942 224287156 821104480 -1 861696576 861702036 807438935 807440055 574078002 574083717 465630141 -1 195378188 -1 -1 13500961 -1 977536179 92893115 -1 -1 661145418 -1 215804863 -1 685338515 544348999 -1 465532902 -1 130346949 -1 -1 526666304 635604584 635605404 ...
output:
NIE
result:
wrong answer 1st lines differ - expected: 'TAK', found: 'NIE'