이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std ;
#define fi first
#define se second
#define mid (l+r)/2
#define le node*2
#define ri node*2+1
typedef vector < int > vi ;
typedef pair < int , int > pi ;
#include "seats.h"
int N , n , m , crnt ;
int a [10009] , b [10009] , ans [10009] ;
pair < pi , pi > info [10009] ;
pair < pi , pi > tree [400009] ;
pair < pi , pi > merge ( pair < pi ,pi > x , pair < pi , pi > y ) {
pair < pi , pi > ret ;
ret .fi.fi = min ( x .fi.fi , y .fi.fi ) ;
ret .fi.se = max ( x .fi.se , y .fi.se ) ;
ret .se.fi = min ( x .se.fi , y .se.fi ) ;
ret .se.se = max ( x .se.se , y .se.se ) ;
return ret ;
}
void build ( int node , int l , int r ) {
if ( l == r ) {
tree [node] = { { a [l] , a [l] } , { b [l] , b [l] } } ;
return ;
}
build ( le , l , mid ) ;
build ( ri , mid + 1 , r ) ;
tree [node] = merge ( tree [le] , tree [ri] ) ;
}
pair < pi , pi > query ( int node , int l , int r , int s , int e ) {
if ( s > r || e < l ) return { { 1e9 , 0 } , { 1e9 , 0 } } ;
if ( s <= l && e >= r ) return tree [node] ;
return merge ( query ( le , l , mid , s , e ) , query ( ri , mid + 1 , r , s , e ) ) ;
}
void give_initial_chart ( int H , int W , vi R, vi C ) {
n = H , m = W , N = n * m ;
for ( int i = 0 ; i < N ; i ++ ) {
a [i] = R [i] ;
b [i] = C [i] ;
}
int r1 = 1e9 , r2 = 0 , c1 = 1e9 , c2 = 0 ;
for ( int i = 0 ; i < N ; i ++ ) {
r1 = min ( r1 , a [i] ) ;
r2 = max ( r2 , a [i] ) ;
c1 = min ( c1 , b [i] ) ;
c2 = max ( c2 , b [i] ) ;
info [i] = { { r1 , r2 } , { c1 , c2 } } ;
ans [i] = ( ( r2 - r1 + 1 ) * ( c2 - c1 + 1 ) == i + 1 ) ;
crnt += ans [i] ;
}
// build ( 1 , 0 , N - 1 ) ;
}
int swap_seats ( int x , int y ) {
swap ( a [x] , a [y] ) ;
swap ( b [x] , b [y] ) ;
if ( x > y ) swap ( x , y ) ;
int r1 = ( x ? info [x-1].fi.fi : 1e9 ) ;
int r2 = ( x ? info [x-1].fi.se : 0 ) ;
int c1 = ( x ? info [x-1].se.fi : 1e9 ) ;
int c2 = ( x ? info [x-1].se.se : 0 ) ;
for ( int i = x ; i <= y ; i ++ ) {
r1 = min ( r1 , a [i] ) ;
r2 = max ( r2 , a [i] ) ;
c1 = min ( c1 , b [i] ) ;
c2 = max ( c2 , b [i] ) ;
info [i] = { { r1 , r2 } , { c1 , c2 } } ;
crnt -= ans [i] ;
ans [i] = ( ( r2 - r1 + 1 ) * ( c2 - c1 + 1 ) == i + 1 ) ;
crnt += ans [i] ;
}
return crnt ;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |