关于刚才 ABC 的C 题,始终 AC 31 WA 4
  • 板块灌水区
  • 楼主Buried_Dream
  • 当前回复3
  • 已保存回复3
  • 发布时间2022/6/25 21:44
  • 上次更新2023/10/27 22:34:43
查看原帖
关于刚才 ABC 的C 题,始终 AC 31 WA 4
396974
Buried_Dream楼主2022/6/25 21:44

思路就是前缀和来维护 [1,i][1,i] 区间的 0,10, 1 个数。

那答案就是 qzh[i][0]+qzh[n][1]qzh[i][1]qzh[i][0] + qzh[n][1] - qzh[i][1]

求 hack。

int qzh[N][2], ans;

struct Node {
	int w, male;
	bool operator < (const Node &x) const {
		return w < x.w;
	}
}a[N];

signed main() 	
{
	int n = read();
	for(int i = 1; i <= n; i++) scanf("%1lld", &a[i].male);
	for(int i = 1; i <= n; i++) scanf("%lld", &a[i].w);
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; i++) {
		if(a[i].male == 1) qzh[i][1] = qzh[i - 1][1] + 1, qzh[i][0] = qzh[i - 1][0];
		else qzh[i][1] = qzh[i - 1][1], qzh[i][0] = qzh[i - 1][0] + 1;
	}
	for(int i = 1; i <= n; i++) {
		if(a[i].w == a[i + 1].w) continue;
		ans = max(ans, qzh[i][0] + qzh[n][1] - qzh[i][1]);
	}
	cout << ans;
	return 0;
} 
2022/6/25 21:44
加载中...