# Educational Codeforces Round 84 Div2 题解 (ABCDEF)

## A. Sum of Odd Integers

#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
int cansel_sync=[]{ios::sync_with_stdio(0); cin.tie(0); return 0;}();
typedef long long ll;
const int N=200010;
#define int ll
int t,n,j;
signed main(){
cin>>t;
while(t--){
cin>>n>>j;
cout<<(j*(1+2*j-1)/2<=n && (j*(1+2*j-1)/2+n)%2==0?"YES":"NO")<<endl;
}
return 0;
}


## B. Princesses and Princes

#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
int cansel_sync=[]{ios::sync_with_stdio(0); cin.tie(0); return 0;}();
typedef long long ll;
const int N=200010;
#define int ll
int t,n,j;
bool f[N],g[N]; //g表示公主被匹配，f表示王子被匹配
vector<int> a[N];
void find(){
cout<<"IMPROVE"<<endl;
repeat(i,0,n)if(!g[i]){cout<<i+1; break;}
repeat(i,0,n)if(!f[i]){cout<<' '<<i+1<<endl; break;}
}
signed main(){
cin>>t;
while(t--){
cin>>n;
repeat(i,0,n)a[i].clear();
fill(f,f+n,0);
fill(g,g+n,0);
int cnt=0;
repeat(i,0,n){
int m,x; cin>>m;
repeat(j,0,m)cin>>x,x--,a[i].push_back(x);
for(auto p:a[i]){
if(!f[p]){
f[p]=1;
g[i]=1;
cnt++;
break;
}
}
}
if(cnt==n)cout<<"OPTIMAL"<<endl;
else find();
}
return 0;
}


## C. Game with Chips

emmm直接输入 $n,m$ 就好了，后面懒得输入，输出可以遍历所有点的走法

#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
int cansel_sync=[]{ios::sync_with_stdio(0); cin.tie(0); return 0;}();
typedef long long ll;
const int N=200010;
#define int ll
int t,n,m;
signed main(){
cin>>n>>m;
string s;
s+=string(m-1,'L');
s+=string(n-1,'U');
repeat(i,0,n){
if(i%2==0)s+=string(m-1,'R');
else s+=string(m-1,'L');
if(i!=n-1)s+='D';
}
cout<<s.length()<<endl;
cout<<s<<endl;
return 0;
}


## D. Infinite Path

#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
int cansel_sync=[]{ios::sync_with_stdio(0); cin.tie(0); return 0;}();
typedef long long ll;
const int N=200010;
#define int ll
int t,n,m,ans;
int a[N],co[N],vis[N];
vector<int> rec,v;
bool work2(int s,int step){
int n=rec.size();
int p=s,nxt=(p+step)%n;
while(nxt!=s){
if(rec[p]!=rec[nxt])return 0;
p=nxt,nxt=(p+step)%n;
}
return 1;
}
void work(){
int n=rec.size();
for(int i=1;i<n;i=n/(n/(i+1))) //这花里胡哨的其实是求n的所有约数
if(n%i==0){
repeat(j,0,i){
if(ans<=i)return;
if(work2(j,i)){
ans=min(ans,i);
return;
}
}
}
int i=n;
repeat(j,0,i){
if(ans<=i)return;
if(work2(j,i)){
ans=min(ans,i);
return;
}
}
}
signed main(){
cin>>t;
while(t--){
cin>>n;
fill(vis,vis+n+1,0);
repeat(i,1,n+1)cin>>a[i];
repeat(i,1,n+1)cin>>co[i];
ans=1e9;
repeat(i,1,n+1)if(!vis[i]){
int p=i;
rec.clear();
while(!vis[p]){
rec.push_back(co[p]);
vis[p]=co[p];
p=a[p];
}
work();
}
cout<<ans<<endl;
}
return 0;
}


## E. Count The Blocks

$n-i-1$ 个这样的位置所以额外乘以 $n-i-1$

$2$ 个这样的位置所以额外乘以 $2$

#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
int cansel_sync=[]{ios::sync_with_stdio(0); cin.tie(0); return 0;}();
typedef long long ll;
const int N=200010;
const int mod=(0?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
#define int ll
int t,n,m;
signed main(){
cin>>n;
repeat(i,1,n+1){
ll ans=0;
if(n-i>=2){
ans+=mul(81*(n-i-1),qpow(10,n-i-2));
ans+=mul(9*2,qpow(10,n-i-1));
ans%=mod;
}
else if(n-i==1){
ans+=mul(9*2,qpow(10,n-i-1));
ans%=mod;
}
else ans=1;
ans=mul(ans,10);
cout<<ans<<' ';
}
return 0;
}


## F. AND Segments

#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
int cansel_sync=[]{ios::sync_with_stdio(0); cin.tie(0); return 0;}();
typedef long long ll;
const int N=500010;
const int mod=(0?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
//#define int ll
int l[N],r[N],x[N],last[N],v[N];
ll sum[N],dp[N];
int n,m,k;
int main(){
cin>>n>>k>>m;
ll ans=1;
repeat(i,0,m)cin>>l[i]>>r[i]>>x[i];
repeat(i,0,k){
dp[0]=sum[0]=1;
repeat(j,1,n+2)last[j]=v[j]=0;
repeat(j,0,m)
if((x[j]>>i)&1){
++v[l[j]];
--v[r[j]+1];
}
else last[r[j]+1]=max(last[r[j]+1],l[j]);
repeat(j,1,n+2){
v[j]+=v[j-1];
last[j]=max(last[j],last[j-1]);
}
repeat(j,1,n+2){
if(!v[j]){
dp[j]=sum[j-1];
if(last[j])
dp[j]=(dp[j]-sum[last[j]-1])%mod;
}
else dp[j]=0;
sum[j]=(sum[j-1]+dp[j])%mod;
}
ans=ans*dp[n+1]%mod;
}
cout<<(ans+mod)%mod<<endl;
}

posted @ 2020-03-24 01:05  axiomofchoice  阅读(...)  评论(...编辑  收藏