codeforce round#782(div2) A-D

Problem - A - CodeforcesCodeforces. Programming competitions and contests, programming communityhttps://codeforces.com/contest/1659/problem/A

inline void solve() {
	int cnt = 1;
	int k = r / (b + 1);
	int res = r % (b + 1);
	for (int i = 1; i <= b + 1; i++) {
		for (int j = 1; j <= k; j++) {
			printf("R");
		}
		if (res-- > 0) {
			printf("R");
		}
		if (i <= b) {
			printf("B");
		}
	}
	printf("\n");
}

Problem - B - Codeforceshttps://codeforces.com/contest/1659/problem/B

inline void solve(){
	int n,k;
	memset(a,0,sizeof(a));
	scanf("%d %d",&n,&k);
	string s;
	cin>>s;
	s=" "+s;
	if(k&1){
		for(int i=1;i<=n;i++){
			if(s[i]=='1'){
				if(k>0){
					a[i]++;
					k--;
				}else{
					s[i]='0';
				}
			}else{
				s[i]='1';
			}
		}
		if(k>0){
			a[n]+=k;
			if(k&1){
				if(s[n]=='1'){
					s[n]='0';
				}else{
					s[n]='1';
				}
			}
		}
	}else{
		for(int i=1;i<=n;i++){
			if(s[i]=='0'){
				if(k>0){
					a[i]++;
					k--;
					s[i]='1';
				}
			}
		}
		if(k>0){
			a[n]+=k;
			if(k&1){
				if(s[n]=='1'){
					s[n]='0';
				}else{
					s[n]='1';
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		cout<<s[i];
	}
	printf("\n");
	for(int i=1;i<=n;i++){
		printf("%d ",a[i]);
	}
	printf("\n");
}

Problem - C - Codeforcesicon-default.png?t=M3C8https://codeforces.com/contest/1659/problem/C

inline void solve() {
	ll d = 0;
	scanf("%lld %lld %lld", &n, &a, &b);
	for (int i = 1; i <= n; i++) {
		scanf("%d", x + i);
		d += x[i];
	}
	ll ans = b * d;
	//ll last = 0;
	ll t;
	for (int i = 1; i < n; i++) {
		d -= x[i];
		//last += a * (x[i] - x[i - 1]) + b * (x[i] - x[i - 1]);
		t = b * (d - (n - i) * x[i]) + x[i] * (a + b);
		ans = min(ans, t);
	}
	printf("%lld\n", ans);
}

Problem - D - Codeforcesicon-default.png?t=M3C8https://codeforces.com/contest/1659/problem/D

#define lowbit(x) ((x)&(-x))
int tree[MAXN];
int c[MAXN];
int ans[MAXN];
int n;

inline void update(int pos, int x) {
	for (; pos <= n; pos += lowbit(pos)) {
		tree[pos] += x;
	}
}

inline int query(int pos) {
	int rec = 0;
	for (; pos; pos -= lowbit(pos)) {
		rec += tree[pos];
	}
	return rec;
}

inline void solve() {
	memset(tree, 0, sizeof(tree));
	memset(ans, 0, sizeof(ans));
	scanf("%d", &n);
	ll num = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", c + i);
		num += c[i];
	}
	num /= n;
	for (int i = n; i >= 1; i--) {
		if (num == 0) {
			break;
		}
		if (c[i] + query(i) >= i) {
			ans[i]++;
		}
		update(i - num + 1, -1);
		if (ans[i]) {
			num--;
		}
	}
	for (int i = 1; i <= n; i++) {
		printf("%d ", ans[i]);
	}
	printf("\n");
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值