首页 > 其他分享 >Educational Codeforces Round 132 (Rated for Div. 2)

Educational Codeforces Round 132 (Rated for Div. 2)

时间:2022-12-03 12:22:55浏览次数:60  
标签:Educational Rated int ed Codeforces st maxn cnt wh

https://codeforces.com/contest/1709

C. Recover an RBS

题意:

这里原本有一个合法的括号序列,现在将这个合法的括号序列中的一部分字符串替换为 ?

你可以将 ?替换为 ( 或者 )问替换出合法括号序列的方式是否唯一

分析:

题目要求判断方式是否唯一 考虑每个?是否唯一即可

void slove() {
    cin >> s;
    int wh = 0, cnt = 0;//问号
    for (char c : s) {
        if (c == '(')cnt++;
        if (c == ')')cnt--;
        if (c == '?')wh++;
        if (cnt + wh == 1) {
            cnt = 1;
            wh = 0;
        }
    }
    if (abs(cnt) == wh)YES;
    else NO;
}

D. Rorororobot

分析:

void slove() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++)cin >> a[i];
    segtree<int, op, e>seg(a, m);//区间最大值线段树
    int q; cin >> q;
    while (q--) {
        cin >> st_x >> st_y >> ed_x >> ed_y >> k;
        if (abs(st_x - ed_x) % k || abs(st_y - ed_y) % k) {
            NO;
            continue;
        }
        //int d = (n - st_x); 
        int nowx = st_x + (n - st_x) / k * k;
        if (seg.que(min(st_y, ed_y), max(st_y, ed_y)) < nowx)YES;
        else NO;
    }
}

很好的一道启发式合并题

E. XOR Tree

#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) x&(-x)
#define ll long long
#define int ll 
const int maxn=2e5+5;
vector<int>Q[maxn];
multiset<int>st[maxn];
multiset<int>::iterator it;
int n,ans;
int a[maxn],dis[maxn];
void solve();
void dfs(int u,int fa){
	for(int i=0;i<Q[u].size();i++){
		int to=Q[u][i];
		if(to==fa)continue;
		dis[to]=dis[u]^a[to];
		dfs(to,u);
	}
}
void dff(int u,int fa){
	bool pd=0;
	st[u].insert(dis[u]);
	for(int i=0;i<Q[u].size();i++){
		int to=Q[u][i];
		if(to==fa)continue;
		dff(to,u);
		if(st[u].size()<st[to].size())
		st[u].swap(st[to]);
		for(it=st[to].begin();it!=st[to].end();it++)
			if(st[u].count((*it)^a[u])){
				pd=1;break;
			}
		for(it=st[to].begin();it!=st[to].end();it++)
		st[u].insert(*it);
		st[to].clear();
	}
	if(pd){
		ans++;
		st[u].clear();//u选择之后 整个u子树不再与其他的点造成贡献!!!!
	}
}
signed main(){
	int T;T=1;
	while(T--)solve();
     return 0;
}
void solve(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	for(int uu,vv,i=1;i<n;i++){
		scanf("%lld%lld",&uu,&vv);
		Q[uu].push_back(vv);
		Q[vv].push_back(uu);
	}
	dis[1]=a[1];
	dfs(1,1);
	dff(1,1);
	printf("%lld",ans);
}

标签:Educational,Rated,int,ed,Codeforces,st,maxn,cnt,wh
From: https://www.cnblogs.com/wzxbeliever/p/16947317.html

相关文章

  • Codeforces Round #832 (Div. 2)
    A.TwoGroups(CF1747A)题目大意给定一个整数数组\(a\),要求将\(a\)分成两部分\(s1,s2\),要求两部分的和的绝对值的差最大。即最大化\(|\sum(s_1)|-|\sum(s_2)|\)......
  • Codeforces Round #816 (Div. 2)
    [比赛链接](Dashboard-CodeforcesRound#816(Div.2)-Codeforces)B题意:给定数组长度n,参数k,\(\sum_{1}^{n}a_i/k=b\),并且区间和是s。其中b和s都是题目给定的。核......
  • CodeForces - 476C-Dreamoon and Sums(数学思维)
    C.DreamoonandSums题解:设则有题目所求可得所以代码#include<bits/stdc++.h>typedeflonglongLL;usingnamespacestd;constintmod=1e9+7;intmain(){#ifndefO......
  • Codeforces Global Round 10 H. ZS Shuffles Cards
    题目链接设f[i]表示还有i个数不在集合内的期望步数,尝试列一下转移式,会发现式子由转移到下一轮的期望步数和之后的DP值组成,考虑DP的转移过程,就会发现答案为转移到下一轮的......
  • mvc中使用视图模板cshtml动态生成generated文件
    一、原因在MVC中,经常会使用一些模板视图,这样会把公用的页面定好,各个功能模块就可以引用调用,无需每个页面都写相同的代码,如果后续修改,也需要在一个地方就可以更改内容。比如......
  • Codeforces Round #154(Div.2)
    C.TextEditor【题意】有一篇文章,包含\(i\)行,每行有\(a_i\)个字母,也就是\(a_i+1\)个放置光标的位置。对于一个位于\((x,y)\)光标,每次操作可以上移/下移/左移/......
  • 【MySQL】Federated引擎与Federated Server访问远程数据
    文中使用的MySQL版本为5.6。之前我们有讲过在Oracle数据库中关于远程数据库的访问可以使用DBLinked来实现,那在MySQL中是否也存在类似的方式呢?答案是肯定的,在MySQL中若想访问......
  • Codeforces Global Round 21 E
    E.PlacingJinas题链稍微手写一下发现就是一个杨辉三角然后我们知道杨辉三角第n行第m个是C(m-1,n-1)我们对应转化过来就是C(n+m-2,m-1)然后我们注意处理的组合数到4e5因......
  • Codeforces Round #834 A-C
    Avoids(){stringa;cin>>a;if(a[0]!='Y'&&a[0]!='e'&&a[0]!='s'){cout<<"No\n";return;}for(inti=0;i<a.size()-1;i++){if(a[......
  • Codeforces Round #805 (Div. 3) G2
    G2.PassablePaths(hardversion)题链我们思考一条链的特性发现只要“确定”两端之后就可以用LCA一遍判断是否是一条链的我们如何确定两端首先深度最深的一定是一......