QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#621575 | #7752. The Only Way to the Destination | Zhou_JK | RE | 1ms | 3660kb | C++23 | 2.7kb | 2024-10-08 15:28:10 | 2024-10-08 15:28:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,m,k;
vector<pair<int,int>>wall[N],seg[N];
vector<int>col[N];
int fa[N];
int getf(int v)
{
if(v==fa[v]) return v;
else return fa[v]=getf(fa[v]);
}
void merge(int u,int v)
{
int fu=getf(u),fv=getf(v);
if(fu!=fv) fa[fu]=fv;
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
cin>>n>>m>>k;
for(int i=1;i<=k;i++)
{
int x1,x2,y;
cin>>x1>>x2>>y;
wall[y].emplace_back(x1,x2);
}
if(n==1)
{
cout<<"YES";
return 0;
}
if(m>2*k+1)
{
cout<<"NO";
return 0;
}
for(int i=1;i<=m;i++)
if(!wall[i].empty())
{
sort(wall[i].begin(),wall[i].end());
if(1<=wall[i].front().first-1) seg[i].emplace_back(1,wall[i].front().first-1);
for(int j=1;j<(int)wall[i].size();j++)
if(wall[i][j-1].second+1<=wall[i][j].first-1) seg[i].emplace_back(wall[i][j-1].second+1,wall[i][j].first-1);
if(wall[i].back().second+1<=n) seg[i].emplace_back(wall[i].back().second+1,n);
}
else seg[i].emplace_back(1,n);
int tot=0;
for(int i=1;i<=m;i++)
{
col[i].resize(seg[i].size());
// cerr<<"start"<<i<<"\n";
for(int j=0;j<(int)seg[i].size();j++)
{
auto [l,r]=seg[i][j];
int p=lower_bound(seg[i-1].begin(),seg[i-1].end(),make_pair(l+1,0))-seg[i-1].begin()-1;
int q=lower_bound(seg[i-1].begin(),seg[i-1].end(),make_pair(r+1,0))-seg[i-1].begin()-1;
// assert(p>=0&&q>=0);
// cerr<<"now"<<l<<" "<<r<<"\n";
if(p>=0&&p<=q)
{
// cerr<<"merge\n";
vector<int>pos;
for(int k=p;k<=q;k++)
{
auto [ll,lr]=seg[i-1][k];
int len=min(r,lr)-max(ll,l)+1;
if(len>1)
{
cout<<"NO";
return 0;
}
assert(len==1);
pos.emplace_back(getf(col[i-1][k]));
}
sort(pos.begin(),pos.end());
for(int k=1;k<(int)pos.size();k++)
if(pos[k]==pos[k-1])
{
cout<<"NO";
return 0;
}
for(int k=1;k<(int)pos.size();k++)
merge(pos[k],pos[k-1]);
}
else tot++,fa[tot]=tot,col[i][j]=tot;
}
}
cout<<"YES";
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3612kb
input:
5 3 2 2 5 1 1 4 3
output:
YES
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
5 3 1 2 4 2
output:
NO
result:
ok answer is NO
Test #3:
score: 0
Accepted
time: 1ms
memory: 3660kb
input:
2 4 2 2 2 1 1 1 4
output:
NO
result:
ok answer is NO
Test #4:
score: -100
Runtime Error
input:
409455775 596220461 69036 72554058 85866426 497212608 54242898 110165840 236869995 68671059 127632371 324336242 39386477 208393446 248270338 151972182 327931056 231832 36658944 75335495 293646122 29512382 138875677 205628469 149151850 327396301 590717922 114980184 165064700 323939243 1771834 7016377...