QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#531068 | #9221. Missing Boundaries | ucup-team4736# | RE | 1ms | 9744kb | C++14 | 1.8kb | 2024-08-24 18:12:56 | 2024-08-24 18:12:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e6+5;
int T,n,l[maxn],r[maxn],L,len[maxn];
bool vis[maxn];
signed main(){
cin>>T;
while(T--){
// cerr<<"_______________________________"<<endl;
cin>>n>>L;bool flg=1;int cnt=0;
set<int> cur;map<int,int> mp;
cur.insert(L);
for(int i=1;i<=n;i++){
cin>>l[i]>>r[i];
if(l[i]!=-1){
cur.insert(l[i]);
if(l[i]>1)cur.insert(l[i]-1);
if(l[i]<L)cur.insert(l[i]+1);
}
if(r[i]!=-1){
cur.insert(r[i]);
if(r[i]>1)cur.insert(r[i]-1);
if(r[i]<L)cur.insert(r[i]+1);
}
}
int lst=0,tot=0;
for(auto u:cur){
++tot;len[tot]=u-lst;lst=u;
mp[u]=tot;
}
for(int i=1;i<=n;i++){
if(l[i]!=-1)l[i]=mp[l[i]];
if(r[i]!=-1)r[i]=mp[r[i]];
}
for(int i=1;i<=L;i++)vis[i]=0;
set<int> st1,st2;
for(int i=1;i<=n;i++){
if(l[i]!=-1&&r[i]!=-1){
for(int j=l[i];j<=r[i];j++){
if(vis[j]){flg=0;break;}
else vis[j]=1;
}
if(!flg)break;
}else if(l[i]==-1&&r[i]==-1)++cnt;
else if(r[i]==-1){st1.insert(l[i]);if(vis[l[i]]){flg=0;break;}vis[l[i]]=1;}
else {st1.insert(r[i]);if(vis[r[i]]){flg=0;break;}vis[r[i]]=1;}
}
if(!flg){cout<<"NIE"<<endl;continue;}
int Len=0;
for(auto x:st1){
int r=x,c=len[x];
while(!vis[r+1]&&r+1<=tot)++r,c+=len[r];
for(int j=x;j<=r;j++)vis[j]=1;
Len+=c-1;
}
for(auto x:st2){
int l=x,c=len[x];
while(!vis[l-1]&&l-1>=1)--l,c+=len[l];
for(int j=l;j<=x;j++)vis[j]=1;
Len+=c-1;
}
for(int i=1;i<=tot;i++){
if(!vis[i]){
if(!cnt){flg=0;cnt=-1;break;}
int r=i,c=len[i];
while(r+1<=tot&&!vis[r+1])++r,c+=len[r];
for(int j=i;j<=r;j++)vis[j]=1;
Len+=c-1;
--cnt;
}
}
// cerr<<Len<<" "<<cnt<<endl;
if(cnt>Len)flg=0;
if(flg)cout<<"TAK"<<endl;
else cout<<"NIE"<<endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 9744kb
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
Runtime Error
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 ...