A Colour the Flag

#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#pragma
#define
#define
#define
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
char s[100][100];
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);
int t=read();
while(t--) {
int n=read(),m=read();
For(i,n) cin>>(s[i]+1);
char h[3]={'R','W'};
bool fl1=0,fl2=0;
For(i,n) {
For(j,m) {
if(s[i][j]==h[(i+j)&1]) fl2=1;
if(s[i][j]==h[((i+j)&1)^1]) fl1=1;
}
}
if(!fl1) {
puts("YES");
For(i,n) {
For(j,m) {
cout<<h[(i+j)&1];
}cout<<endl;
}
}
else if(!fl2) {
puts("YES");
For(i,n) {
For(j,m) {
cout<<h[((i+j)&1)^1];
}cout<<endl;
}
}else {
puts("NO");
}
}
return 0;
}

B Histogram Ugliness

#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#pragma
#define
#define
#define
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int t,n,a[412345];
int main()
{
// freopen("B.in","r",stdin);
// freopen(".out","w",stdout);

int t=read();
while(t--) {
n=read();
For(i,n)
a[i]=read();
a[n+1]=0;
ll ans=0;
For(i,n) {
ans+=max(0,a[i]-a[i+1])+max(0,a[i]-a[i-1]);
if (a[i]>a[i+1]&&a[i]>a[i-1])
ans-=a[i]-max(a[i-1],a[i+1]);
}
cout<<ans<<endl;
}
return 0;
}

C Little Alawn’s Puzzle

#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#pragma
#define
#define
#define
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int a[3][412345];
class bingchaji
{
public:
int father[412345],n,cnt;
void mem(int _n)
{
n=cnt=_n;
For(i,n) father[i]=i;
}
int getfather(int x)
{
if (father[x]==x) return x;

return father[x]=getfather(father[x]);
}
void unite(int x,int y)
{
x=getfather(x);
y=getfather(y);
if (x^y) {
--cnt;
father[x]=y;
}
}
bool same(int x,int y)
{
return getfather(x)==getfather(y);
}
}S;
ll work() {
int n=2,m=read();
For(i,n)For(j,m) a[i][j]=read();
For(j,m) if(a[1][j]==a[2][j]) return 0;
S.mem(m);
For(j,m) {
S.unite(a[1][j],a[2][j]);
}
ll p=1;
For(j,m) if(S.getfather(j)==j) p=p*2%F;return p;
}
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout);
int t=read();
while(t--) {
cout<<work()<<endl;
}
return 0;
}

E Lost Tree

交互题,有n个数,每次可以询问一个大小恰为k的子集的数的xor和。最小步数求n个数的xor和。无解输-1.

dp,Codeforces LATOKEN Round 1 (Div. 1 + Div. 2)_git表示知道i个数的xor和的最小步数。

#include<bits/stdc++.h>
using namespace std;
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#define
#pragma
#define
#define
#define
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
inline int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int f[600],pr[600];
bool b[600]={};
int need[600]={};
int main()
{
// freopen("E.in","r",stdin);
// freopen(".out","w",stdout);
int n,k;cin>>n>>k;
f[0]=0;b[0]=1;
queue<int> q; q.push(0);
while(!q.empty()) {
int now=q.front();q.pop();
Rep(t,k+1) {
int nx=now+t-(k-t);
if(now<k-t || n-now<t ||nx>n||nx<0 || b[nx]) continue;
b[nx]=1;q.push(nx);f[nx]=f[now]+1;pr[nx]=now;
}
}
// PRi(f,n)
if(!b[n]) return puts("-1"),0;

stack<int> s;
int p=n;
while(p) s.push(p),p=pr[p];

ll ans=0;
int now=0;
while(!s.empty()) {
int nx=s.top();s.pop();
// int nx=now+2*t-k;
int t=(nx-now+k)>>1;
int ad=t,de=k-t;
putchar('?');
For(i,n) {
if(!need[i]&&ad) --ad,need[i]^=1,printf(" %d",i);
else if(need[i]&&de) --de,need[i]^=1,printf(" %d",i);
}
puts("");
cout.flush();
ll p;cin>>p;ans^=p;
now=nx;
}
cout<<"! "<<ans<<endl;
return 0;
}

F2 Falling Sand (Hard Version)

在一个n*m的地图,某些地图有沙块,沙块点击会下落,每次向下移动一格依次到底。如果一个位置有下落中的沙块,它四联通位置的沙块也会下落。问至少点击几次,才能使第i列至少下落沙块Codeforces LATOKEN Round 1 (Div. 1 + Div. 2)_i++_02个。

如果是打算让所有沙块下落,可以转化成tarjen,求最小点集使所有点集可从该点集拿。

考虑一个沙块下落它下面一定下落,问题转换成第i列倒数第Codeforces LATOKEN Round 1 (Div. 1 + Div. 2)_i++_02个沙块下落。

不难证明,每次沙块的影响覆盖一个区间的Codeforces LATOKEN Round 1 (Div. 1 + Div. 2)_i++_02沙块。

题目转化为区间覆盖问题。