QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#400280#7942. $K$ Subsequencesucup-team3160Compile Error//C++143.4kb2024-04-27 09:23:012024-04-27 09:23:01

Judging History

你现在查看的是最新测评结果

  • [2024-04-27 09:23:01]
  • 评测
  • [2024-04-27 09:23:01]
  • 提交

answer

#pragma GCC optimize("Ofast", "inline", "-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
# include <bits/stdc++.h>

using namespace std ;

int n , m ;
int a[200005] ;
typedef pair< int , int > pii ;
int cnt1 = 0 , cnt2 = 0 ;
int Read()
{
    int num=0,k=1;   //k是正负数标记
    char c=getchar();
    while(c!='-'&&(c<'0'||c>'9')) c=getchar();//注意判断'-'
    if(c=='-')
    {
        k=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        num=(num<<3)+(num<<1)+(c^48);//num<<3相当于num*8,num<<1相当于num*2,
        c=getchar();                //c^48利用位运算优化,相当于c-'0' ,但是一定要加括号
    }
    return num*k;
}
  
void print1(int x)
{
    if(x>9) print1(x/10);  //把这个数一位一位的输出
    putchar(x%10+'0');
}
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++ ) a[i] = Read() ;
	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 ) ;
			print1( now.second ) ;
			putchar(' ') ; 
//			printf("%d " , now.second) ;
			q.push( { now.first + 1 , now.second } ) ;
		}
		else
		{
			auto now = q.maxv() ;
			print1( now.second ) ;
			putchar(' ') ;
//			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()
{
//	freopen("1.in" , "r" , stdin) ;
//	freopen("1.out" , "w" , stdout) ;
	int t ;
	scanf("%d" , &t) ;
	while ( t -- ) solve() ;
//	printf("%d %d\n" , cnt1 , cnt2) ;
	return 0 ;
}

Details

answer.code: In function ‘void solve()’:
answer.code:107:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  107 |         scanf("%d%d"  , &n , &m) ;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:150:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  150 |         scanf("%d" , &t) ;
      |         ~~~~~^~~~~~~~~~~
In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:3:
/usr/include/c++/13/bits/allocator.h: In destructor ‘std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int> > >::_Vector_impl::~_Vector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = std::pair<int, int>]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/queue:63,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:157:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~