QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#400274 | #7942. $K$ Subsequences | ucup-team3160 | TL | 69ms | 3964kb | C++14 | 2.5kb | 2024-04-27 09:15:26 | 2024-04-27 09:15:28 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std ;
int n , m ;
int a[200005] ;
typedef pair< int , int > pii ;
struct pq1
{
priority_queue < pii > q1 , q2 ;
priority_queue < pii , vector < pii > , greater < pii > > q3 , q4 ;
void init()
{
while ( q1.size() ) q1.pop() ;
while ( q2.size() ) q2.pop() ;
while ( q3.size() ) q3.pop() ;
while ( q4.size() ) q4.pop() ;
}
void push( pii x )
{
// printf("push:{%d,%d}\n" , x.first , x.second) ;
q1.push( x ) ;
q3.push( x ) ;
}
void del( pii x )
{
// printf("pop:{%d,%d}\n" , x.first , x.second) ;
q2.push( x ) ;
q4.push( x ) ;
}
pii maxv()
{
while ( q1.size() && q2.size() )
{
if ( q1.top() != q2.top() ) return q1.top() ;
q1.pop() , q2.pop() ;
}
return q1.top() ;
}
pii minv()
{
// puts("qmin:") ;
while ( q3.size() && q4.size() )
{
// printf("{%d,%d} {%d,%d}\n" , q3.top().first , q3.top().second , q4.top().first , q4.top().second) ;
if ( q3.top() != q4.top() ) return q3.top() ;
q3.pop() , q4.pop() ;
}
// printf("{%d,%d}\n" , q3.top().first , q3.top().second) ;
return q3.top() ;
}
} q ;
bool check( int v )
{
// printf("check:%d\n" , v) ;
q.init() ;
for ( int i = 1 ; i <= m ; i++ ) q.push( { 0 , i } ) ;
for ( int i = 1 ; i <= n ; i++ )
{
if ( a[i] == 1 )
{
auto now = q.minv() ;
// printf("now:%d %d\n" , now.first , now.second) ;
q.del( now ) ;
if ( now.first + 1 > v ) return false ;
q.push( { now.first + 1 , now.second } ) ;
}
else
{
auto now = q.maxv() ;
if ( now.first == 0 ) continue ;
q.del( now ) ;
q.push( { now.first - 1 , now.second } ) ;
}
}
return true ;
}
int ans[200005] ;
void solve()
{
scanf("%d%d" , &n , &m) ;
for ( int i = 1 ; i <= n ; i++ ) scanf("%d" , a + i) ;
int l = 0 , r = n ;
while ( l < r )
{
int mid = ( l + r ) >> 1 ;
if ( check( mid ) ) r = mid ;
else l = mid + 1 ;
}
q.init() ;
for ( int i = 1 ; i <= m ; i++ ) q.push( { 0 , i } ) ;
for ( int i = 1 ; i <= n ; i++ )
{
if ( a[i] == 1 )
{
auto now = q.minv() ;
// printf("now:%d %d\n" , now.first , now.second) ;
q.del( now ) ;
printf("%d " , now.second) ;
q.push( { now.first + 1 , now.second } ) ;
}
else
{
auto now = q.maxv() ;
printf("%d " , now.second) ;
if ( now.first == 0 ) continue ;
q.del( now ) ;
q.push( { now.first - 1 , now.second } ) ;
}
}
// printf("%d\n" , l) ;
puts("") ;
}
int main()
{
int t ;
scanf("%d" , &t) ;
while ( t -- ) solve() ;
return 0 ;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3916kb
input:
5 3 2 1 -1 1 4 2 -1 1 1 -1 7 3 1 1 1 1 1 1 1 10 3 1 1 1 1 -1 -1 1 1 1 1 12 4 1 1 1 1 -1 -1 -1 -1 1 1 1 1
output:
1 1 1 2 1 2 2 1 2 3 1 2 3 1 1 2 3 1 1 3 3 1 2 3 1 2 3 4 4 3 2 1 1 2 3 4
result:
ok Correct (5 test cases)
Test #2:
score: 0
Accepted
time: 69ms
memory: 3964kb
input:
18434 10 1 -1 1 1 -1 -1 1 -1 -1 1 1 10 2 -1 -1 -1 1 1 -1 1 1 1 1 10 2 1 -1 -1 -1 -1 1 1 -1 1 1 10 7 1 1 -1 1 -1 1 1 -1 -1 1 9 1 -1 1 -1 1 1 -1 1 -1 1 8 1 -1 -1 -1 -1 1 1 -1 -1 10 3 -1 -1 -1 1 1 1 1 -1 -1 -1 9 1 1 -1 -1 1 -1 -1 -1 -1 -1 10 10 -1 1 1 1 1 1 1 1 1 1 10 4 -1 1 -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