QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#634377 | #7752. The Only Way to the Destination | realisation | WA | 2ms | 7832kb | C++20 | 2.7kb | 2024-10-12 17:10:51 | 2024-10-12 17:10:52 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std ;
const int N = 1e5 + 10 ;
int n , m , k ;
struct walls {
int l ;
int r ;
int y ;
bool operator <( struct walls &b ) {
if( y == b.y ) return l < b.l ;
else return y < b.y ;
}
}wall[N] ;
int cnt = 0 ;
struct Node {
int l ;
int r ;
int id ;
}node[ N << 1 ] ;
vector<int> hav[N] ;
int fa[ N << 1 ] ;
int check( int x , int y ) {
int l1 = node[x].l ;
int l2 = node[y].l ;
int r1 = node[x].r ;
int r2 = node[y].r ;
if( r2 < l1 ) return -1 ;
else if( r1 < l2 ) return 1 ;
else if( r2 == l1 ) return 2 ;
else if( l2 == r1 ) return 3 ;
int s = min(r1, r2) - max(l1, l2) + 1 ;
int len = max( (int)0, s) ;
if( len >= 2 ) return -2 ;
else if( r1 == l1 ) return 3 ;
else return 2 ;
}
int find( int u ) {
if( fa[u] != u ) {
fa[u] = find( fa[u] ) ;
}
return fa[u] ;
}
void solve() {
cin >> n >> m >> k ;
for( int i = 1 ; i <= ( k << 1 ) + 10 ; i ++ )
fa[i] = i ;
for( int i = 1 ; i <= k ; i ++ )
cin >> wall[i].l >> wall[i].r >> wall[i].y ;
sort( wall + 1 , wall + 1 + k ) ;
int wall_idx = 1 ;
for( int i = 1 ; i <= m && i <= k + 10 ; i ++ ) {
// find
int l = 1 , r = l ;
while( wall_idx <= k && wall[wall_idx].y < i ) wall_idx ++ ;
while( wall_idx <= k && wall[wall_idx].y == i ) {
r = wall[ wall_idx ].l - 1 ;
if( l <= r ) {
node[ ++ cnt ] = { l , r , cnt } ;
hav[i].push_back(cnt) ;
}
l = wall[wall_idx].r + 1 ;
wall_idx ++ ;
}
if( l <= n ) {
node[ ++ cnt ] = { l , n , cnt } ;
hav[i].push_back(cnt) ;
}
// for( auto it : hav[i] )
// cout << node[i].l << ' ' << node[i].r << '\n' ;
//connect and querry
if( i >= 2 ){
int last = 0 , ed = hav[i-1].size() ;
for( auto it : hav[i] ) {
int l = node[it].l ;
int r = node[it].r ;
int t = 0 ;
// cout << it << '\n' ;
while( last < ed ) {
t = check( it , hav[i-1][last] ) ;
if( t == -1 ) last ++ ;
else if( t == 1 )
break ;
else if( t == 2 ) {
int a = find( it ) , b = find( hav[i-1][last] ) ;
if( a == b ) {
cout << "NO" ;
return ;
}
fa[a] = b ;
last ++ ;
}
else if( t == 3 ) {
int a = find( it ) , b = find( hav[i-1][last] ) ;
if( a == b ) {
return ;
}
fa[a] = b ;
break ;
}
else if( t == -2 ) {
cout << "NO" ;
return ;
}
}
if( last >= ed )
break ;
}
}
}
cout << "YES" ;
}
signed main() {
ios::sync_with_stdio(0) ;
cout.tie(0) ;
cin.tie(0) ;
solve() ;
return 0 ;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 7764kb
input:
5 3 2 2 5 1 1 4 3
output:
YES
result:
ok answer is YES
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 7832kb
input:
5 3 1 2 4 2
output:
result:
wrong output format Unexpected end of file - token expected