Codeforces Round #443 Div. 1

  A:考虑每一位的改变情况,分为强制变为1、强制变为0、不变、反转四种,得到这个之后and一发or一发xor一发就行了。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 500010
char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
	while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int a[20];
signed main()
{
	int n=read(),x=0;
	while (n--)
	{
		char c=getchar();
		while (c!=‘|‘&&c!=‘^‘&&c!=‘&‘) c=getchar();
		int u=read();
		for (int i=0;i<10;i++)
		if (u&(1<<i))
		{
			if (c==‘|‘) a[i]=1;
			if (c==‘^‘)
			{
				if (a[i]==0) a[i]=3;
				else if (a[i]==1) a[i]=2;
				else if (a[i]==2) a[i]=1;
				else if (a[i]==3) a[i]=0;
			}
		}
		else
		{
			if (c==‘&‘) a[i]=2;
		}
	}
	cout<<3<<endl;
	for (int i=1;i<=3;i++)
	{
		int x=0;
		for (int j=0;j<10;j++)
		if (a[j]==i) x|=1<<j;
		if (i==2) cout<<‘&‘<<‘ ‘<<(1023^x)<<endl;
		else
		{
			if (i==1) cout<<‘|‘;else cout<<‘^‘;
			cout<<‘ ‘<<x<<endl;
		}
	}
	return 0;
	//NOTICE LONG LONG!!!!!
}

  B:先按k=1的情况处理一下。然后若考虑首尾相接是否会超过m个,若会则删掉,若恰好有k个则继续删。最后如果只剩下一种数特殊讨论。坑点比较多。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
	while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,m,k,a[N],b[N],stk[N],top;
ll ans;
signed main()
{
#ifndef ONLINE_JUDGE
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
#endif
	n=read(),m=read(),k=read();
	for (int i=1;i<=n;i++) a[i]=read();
	int u=0;int cnt=0;
	for (int i=1;i<=n;i++)
	{
		if (!top) stk[++top]=a[i],cnt++;
		else
		{
			if (stk[top]==a[i]) cnt++;
			else cnt=1;
			stk[++top]=a[i];
		}
		if (cnt==m)
		{
			top-=m;ans+=1ll*k*m;cnt=0;
			for (int j=top;j>=0;j--) if (stk[j]!=stk[top]) {cnt=top-j;break;}
		}
	}
	u=top;memcpy(b,stk,sizeof(b));
	int nnn=n;
	n=u;memcpy(a,b,sizeof(a));
	bool flag=0;
	for (int i=2;i<=n;i++) if (a[i]!=a[1]) {flag=1;break;}
	if (!flag) {cout<<1ll*nnn*k%m;return 0;}
	int l=1,r=n;
	while (l<=r)
	{
		int x=l,y=r;
		if (a[l]!=a[r]) break;
		while (a[x+1]==a[l]) x++;
		while (a[y-1]==a[r]) y--;
		if (x>=y)
		{
			ans+=(1ll*k*(r-l+1)/m)*m;
			if (1ll*k*(r-l+1)%m==0) ans+=n-(r-l+1);
			break;
		}
		if (x-l+1+r-y+1>=m)
		{
			ans+=1ll*(k-1)*m;
			if (x-l+1+r-y+1>m) break;
			else if (m==(x-l+1+r-y+1)) l=x+1,r=y-1;
			else break;
		}
		else break;
	}
	ans=1ll*nnn*k-ans;
	cout<<ans;
	return 0;
	//NOTICE LONG LONG!!!!!
}

  C:考虑建图,a向b连边表示a可以打败b。这样缩点后度数为0的点(显然只会存在一个)中的所有选手都可能取胜。考虑动态维护。每个SCC记录大小和各项的minmax。注意到所有SCC每一项都构成偏序关系(maxi<mini+1),于是用一个set,新加入一个点时找到前驱后继,看新点能否与其互相打败而合并成一个新的SCC即可。具体实现参考了这份代码https://codeforces.com/contest/878/submission/31775120,感觉过于优美。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
using namespace std;
#define ll long long
#define N 50010
#define M 12
char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
	while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,m;
struct data
{
	int size,min[M],max[M];
	bool operator <(const data&a) const
	{
		for (int i=1;i<=m;i++) if (max[i]>a.min[i]) return 0;
		return 1;
	}
	void merge(const data&a)
	{
		size+=a.size;
		for (int i=1;i<=m;i++)
		{
			if (a.min[i]<min[i]) min[i]=a.min[i];
			if (a.max[i]>max[i]) max[i]=a.max[i];
		}
	}
};
multiset<data> q;
signed main()
{
#ifndef ONLINE_JUDGE
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
#endif
	n=read(),m=read();
	for (int i=1;i<=n;i++)
	{
		data p;p.size=1;
		for (int j=1;j<=m;j++) p.min[j]=p.max[j]=read();
		multiset<data>::iterator first_beat_p=q.lower_bound(p),first_p_cannot_beat=q.upper_bound(p);
		while (first_beat_p!=first_p_cannot_beat)
		{
			p.merge(*first_beat_p);
			first_beat_p=q.erase(first_beat_p);
		}
		q.insert(p);multiset<data>::iterator tmp=q.end();tmp--;
		printf("%d\n",(*tmp).size);
	}
	return 0;
	//NOTICE LONG LONG!!!!!
}

  D:考虑所有数值都为01的情况。这样一共只有2k种本质不同的特征,可以bitset记录每种特征最后的答案直接暴力过去。不为01的话容易想到二分答案之类,实际上使用完全相同的做法得到01时的答案,最后类似于二分答案的做即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<bitset>
using namespace std;
#define ll long long
#define N 100010
#define K 12
char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
	while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int n,q,k,a[K][N],b[N][K],cnt,u;
bitset<(1<<K)> S[N];
bool cmp(const int &x,const int &y)
{
	return a[x][u]<a[y][u];
}
signed main()
{
#ifndef ONLINE_JUDGE
	freopen("d.in","r",stdin);
	freopen("d.out","w",stdout);
#endif
	n=read(),k=read(),q=read();
	for (int i=0;i<k;i++)
		for (int j=1;j<=n;j++)
		a[i][j]=read();
	for (int i=0;i<k;i++)
	{
		for (int j=0;j<(1<<k);j++)
		S[i][j]=(j&(1<<i))>0;
	}
	for (u=1;u<=n;u++)
	{
		for (int j=0;j<k;j++) b[u][j]=j;
		sort(b[u],b[u]+k,cmp);
	}
	cnt=k-1;
	for (int i=1;i<=q;i++)
	{
		int op=read(),x=read()-1,y=read();
		if (op==1) S[++cnt]=S[x]|S[y-1];
		if (op==2) S[++cnt]=S[x]&S[y-1];
		if (op==3)
		{
			u=0;
			for (int j=k-1;j>=0;j--)
			{
				u|=1<<b[y][j];
				if (S[x][u]) {printf("%d\n",a[b[y][j]][y]);break;}
			}
		}
	}
	return 0;
	//NOTICE LONG LONG!!!!!
}

  

原文地址:https://www.cnblogs.com/Gloid/p/10473806.html

时间: 2024-08-30 17:43:09

Codeforces Round #443 Div. 1的相关文章

Codeforces Round #443 (Div. 2)ABC

A. Borya's Diagnosis It seems that Borya is seriously sick. He is going visit n doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Bor

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除

Codeforces Round #339 (Div. 2) B. Gena&#39;s Code

B. Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, f

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un

DP Codeforces Round #303 (Div. 2) C. Woodcutters

题目传送门 1 /* 2 题意:每棵树给出坐标和高度,可以往左右倒,也可以不倒 3 问最多能砍到多少棵树 4 DP:dp[i][0/1/2] 表示到了第i棵树时,它倒左或右或不动能倒多少棵树 5 分情况讨论,若符合就取最大值更新,线性dp,自己做出来了:) 6 */ 7 #include <cstdio> 8 #include <algorithm> 9 #include <cstring> 10 #include <cmath> 11 #include &