QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687175 | #9223. Data Determination | _Veritas# | TL | 0ms | 0kb | C++14 | 3.1kb | 2024-10-29 17:31:49 | 2024-10-29 17:31:49 |
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);
}
}in[200005];
vector<Itv> lr,emp,ll,rr;
struct halfitv{
int pos;
bool right;
};
map<int,int> numcnt;
bool covered(int x){
int l=1,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(){
n=read();L=read();
for(int i=1;i<=n;++i){
int x=read(),y=read();
numcnt[x]++;
numcnt[y]++;
if(x==-1&&y==-1) {++anycnt; }
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();
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;
}
}
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){
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(!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++;
}
}
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: 0
Time Limit Exceeded
input:
3 6 4 42 41 43 41 57 41 42 4 2 4 1 2 5 8 7 5 57 101 2 42 5 57 7 13