QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#161351 | #7105. Pixel Art | ucup-team197# | AC ✓ | 367ms | 23492kb | C++14 | 3.9kb | 2023-09-02 23:29:26 | 2023-09-04 04:31:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
const int MAXN = 1e5 + 7 ;
int n , m , k ;
struct line { // 1 hr , 2 vr
int type , coord , l , r ;
};
line a[ MAXN ] ;
vector < pair < pii , int > > v[ MAXN ] ;
vector < int > opening[ MAXN ] , closing[ MAXN ] ;
int ch[ MAXN ] ;
int tot_unites ;
int prv[ MAXN ] , rnk[ MAXN ] ;
int get ( int x ) {
if ( prv[ x ] == -1 ) { return x ; }
int y = get ( prv[ x ] ) ;
prv[ x ] = y ;
return y ;
}
void unite ( int x , int y ) {
int k1 = get ( x ) , k2 = get ( y ) ;
if ( k1 == k2 ) { return ; }
++ tot_unites ;
if ( rnk[ k1 ] < rnk[ k2 ] ) { swap ( k1 , k2 ) ; }
rnk[ k1 ] += ( rnk[ k1 ] == rnk[ k2 ] ) ;
prv[ k2 ] = k1 ;
}
map < int , int > desc ;
void mod_col ( int x , int val ) {
if ( val < 0 ) {
desc.erase ( x ) ;
}
else {
desc[ x ] = val ;
}
}
void solve ( ) {
cin >> n >> m >> k ;
for ( int i = 1 ; i <= n + 1 ; ++ i ) {
v[ i ].clear ( ) ;
opening[ i ].clear ( ) ;
closing[ i ].clear ( ) ;
ch[ i ] = 0 ;
}
for ( int i = 1 ; i <= k ; ++ i ) {
int lx , ly , hx , hy ;
cin >> lx >> ly >> hx >> hy ;
++ ch[ lx ] ;
if ( lx == hx ) {
a[ i ] = { 1 , lx , ly , hy } ;
v[ lx ].push_back ( { make_pair ( ly , hy ) , i } ) ;
}
else {
a[ i ] = { 2 , ly , lx , hx } ;
opening[ lx ].push_back ( i ) ;
closing[ hx + 1 ].push_back ( i ) ;
v[ lx ].push_back ( { make_pair ( ly , ly ) , i } ) ;
v[ hx ].push_back ( { make_pair ( ly , ly ) , i } ) ;
}
}
ll tot = 0 ;
int ans = 0 ;
tot_unites = 0 ;
for ( int i = 1 ; i <= k ; ++ i ) {
prv[ i ] = -1 , rnk[ i ] = 0 ;
}
desc.clear ( ) ;
for ( int i = 1 ; i <= n ; ++ i ) {
sort ( v[ i ].begin ( ) , v[ i ].end ( ) ) ;
ans += ch[ i ] ;
for ( auto x : closing[ i ] ) {
mod_col ( a[ x ].coord , -x ) ;
}
for ( auto x : opening[ i ] ) {
mod_col ( a[ x ].coord , x ) ;
}
int sz = v[ i - 1 ].size ( ) ;
tot += desc.size ( ) ;
int wh = -1 ;
for ( auto e : v[ i ] ) {
auto [ hh , id ] = e ;
++ wh ;
if ( wh > 0 ) {
if ( v[ i ][ wh ].fi.fi - 1 == v[ i ][ wh - 1 ].fi.se ) {
unite ( v[ i ][ wh ].se , v[ i ][ wh - 1 ].se ) ;
}
}
if ( a[ id ].type == 1 ) {
tot += a[ id ].r - a[ id ].l + 1 ;
}
// unite with verts
if ( desc.find ( hh.fi - 1 ) != desc.end ( ) ) {
unite ( desc[ hh.fi - 1 ] , id ) ;
}
if ( desc.find ( hh.se + 1 ) != desc.end ( ) ) {
unite ( desc[ hh.se + 1 ] , id ) ;
}
int pos = lower_bound ( v[ i - 1 ].begin ( ) , v[ i - 1 ].end ( ) , make_pair ( make_pair ( hh.fi , hh.fi ) , -MAXN ) ) - v[ i - 1 ].begin ( ) ;
if ( pos > 0 ) { -- pos ; }
while ( pos < sz && v[ i - 1 ][ pos ].fi.fi <= hh.se ) {
if ( v[ i - 1 ][ pos ].fi.se < hh.fi ) {
++ pos ;
continue ;
}
unite ( v[ i - 1 ][ pos ].se , id ) ;
++ pos ;
}
}
cout << tot << " " << ans - tot_unites << "\n" ;
}
}
int main ( ) {
ios_base :: sync_with_stdio ( false ) ;
cin.tie ( NULL ) ;
int t = 1 ; cin >> t ;
while ( t -- ) { solve ( ) ; }
return 0 ;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 10728kb
input:
3 2 5 2 1 1 1 2 2 3 2 5 2 5 2 1 1 1 3 2 3 2 5 3 3 3 1 1 1 2 3 1 3 2 1 3 2 3
output:
2 1 5 2 3 1 6 1 3 1 4 1 6 2
result:
ok 7 lines
Test #2:
score: 0
Accepted
time: 367ms
memory: 23492kb
input:
2130 2 5 2 1 1 1 2 2 3 2 5 2 5 2 1 1 1 3 2 3 2 5 3 3 3 1 1 1 2 3 1 3 2 1 3 2 3 3 100 51 1 2 2 2 1 4 2 4 1 6 2 6 1 8 2 8 1 10 2 10 1 12 2 12 1 14 2 14 1 16 2 16 1 18 2 18 1 20 2 20 1 22 2 22 1 24 2 24 1 26 2 26 1 28 2 28 1 30 2 30 1 32 2 32 1 34 2 34 1 36 2 36 1 38 2 38 1 40 2 40 1 42 2 42 1 44 2 44 ...
output:
2 1 5 2 3 1 6 1 3 1 4 1 6 2 50 50 100 50 200 1 50 50 150 1 200 1 2 1 4 1 6 1 8 1 10 1 12 1 14 1 16 1 18 1 20 1 22 1 24 1 26 1 28 1 30 1 32 1 34 1 36 1 38 1 40 1 42 1 44 1 46 1 48 1 50 1 52 1 54 1 56 1 58 1 60 1 62 1 64 1 66 1 68 1 70 1 72 1 74 1 76 1 78 1 80 1 82 1 84 1 86 1 88 1 90 1 92 1 94 1 96 1...
result:
ok 355756 lines
Extra Test:
score: 0
Extra Test Passed