QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#490596#7683. Hard Brackets Problemucup-team3160#WA 0ms16168kbC++141.5kb2024-07-25 15:48:252024-07-25 15:48:26

Judging History

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

  • [2024-07-25 15:48:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:16168kb
  • [2024-07-25 15:48:25]
  • 提交

answer

# include <bits/stdc++.h>

using namespace std ;

typedef pair< int , int > pii ;
int n , m ;
int a[500005] ;
int nxt[500005] ;
int pos[500005] ;
vector < pii > qe[500005] ;
bool cmp( pair< pii , int > a , pair< pii , int > b )
{
	return a.first.second < b.first.second ;
}
int lowbit( int x  )
{
	return x & -x ;
}
int s[500005] ;
void add( int x , int v )
{
	for ( int i = x ; i <= n ; i += lowbit( i ) ) s[i] += v ;
}
void add( int l , int r , int v )
{
	add( l , v ) , add( r + 1 , -v ) ;
}
int query( int x )
{
	int res = 0 ;
	for ( int i = x ; i >= 1 ; i -= lowbit( i ) ) res += s[i] ;
	return res ;
}
void solve()
{
	scanf("%d%d" , &n , &m) ;
	for ( int i = 1 ; i <= n ; i++ ) qe[i].clear() , s[i] = 0 ;
	for ( int i = 1 ; i <= n ; i++ ) scanf("%d" , a + i) ;
	for ( int i = 1 ; i <= n + 1 ; i++ ) pos[a[i]] = 0 , pos[i] = 0 ;
	for ( int i = 1 ; i <= n ; i++ )
	{
		nxt[i] = pos[a[i]] ;
		pos[a[i]] = i ;
		if ( nxt[i] < i - 1 ) qe[i - 1].push_back( { nxt[i] + 1 , a[i] } ) ;
	}
	int nc = 0 ;
	for ( int i = 1 ; i <= m + 1 ; i++ )
		if ( ! pos[i] ) 
		{
			nc = i ;
			break ;
		}
	for ( int i = 1 ; i <= n ; i++ )
		if ( i == pos[a[i]] ) qe[n].push_back( { i + 1 , a[i] } ) ;
	int ans = 0 ;
	for ( int i = 1 ; i <= n ; i++ )
	{
		add( nxt[i] + 1 , i , 1 ) ;
		for ( auto t : qe[i] ) 
		{
			ans = max( ans , query( t.first ) - t.second ) ;
		}
	}
	ans = max( ans , query( 1 ) - nc ) ;
	printf("%d\n" , ans) ;
}

int main()
{
	int t ;
	scanf("%d" , &t) ;
	while ( t -- ) solve() ;
	return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 16168kb

input:

3
((()))
(
)))()

output:

0
0
0

result:

wrong answer the answer string contains illegal characters (test case 1)