QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571576#9315. Rainbow Bracket SequenceSmilingWeepingCompile Error//C++981.1kb2024-09-18 00:45:332024-09-18 00:45:37

Judging History

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

  • [2024-09-18 00:45:37]
  • 评测
  • [2024-09-18 00:45:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2010;
ll n, a[N], rk[N], s[N], b[N][N], c[N][N], sb[N][N];
bool check(ll x) {
	for(int i = 1; i <= n; i++) {
		// 前缀和 
		s[i] = s[i-1] + (a[i]>x);
	}
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = i; j <= n; j++) {
			b[i][j] = !(j-i+1-s[j]+s[i-1] >= (j-i+2)/2);
		}
	}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			sb[i][j] = sb[i-1][j] + sb[i][j-1]+b[i][j]-sb[i-1][j-1];
	for(int i = 1; i <= n; i++)
		for(int j = i; j <= n; j++) {
			c[i][j] = (sb[j][i] - sb[i-1][j] - sb[i][j-1] + sb[i-1][j-1]);
			int sz = (j-i+2)*(j-i+1)/2;
			if(sz-c[i][j] >= (sz+1)/2)
				cnt++;
		}
		return cnt >= (n*(n+1)/2+1)/2;
}
void solve() {
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i], rk[i] = a[i];
	sort(rk+1, rk+n+1);
	int l=1, r=n, mid;
	while(l<=r) {
		mid = (l+r) >> 1;
		if(check(rk[mid]))
			r = mid-1;
		else l = mid+1
	}
	cout << rk[l] << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	while(t--)
		solve();
	return 0;
} 

Details

answer.code: In function ‘void solve()’:
answer.code:39:31: error: expected ‘;’ before ‘}’ token
   39 |                 else l = mid+1
      |                               ^
      |                               ;
   40 |         }
      |         ~