Educational Codeforces Round 132 (Rated for Div. 2) ABD
Educational Codeforces Round 132 (Rated for Div. 2)
A - Three Doors
只有三扇门,模拟每一个门后面是否有钥匙打开新的门即可
点击查看代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
#define int ll
#define lfor(i,a,b) for(int i=(a);i<=b;i++)
#define rfor(i,a,b) for(int i=(b);i>=a;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define _IOS (ios::sync_with_stdio(0),cin.tie(0),0)
#define db(i) printf("%d ",i);
#define endl "\n"
#define AC return
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
const int N=200005;
const int inf=0x3f3f3f3f;
const ll INF=~0ull>>2;
const ll mod=1e9+7;
ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;}
const lf pi=acos(-1.0);
lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;}
typedef pair<ll,ll> pii;
ll mul(ll a,ll b,ll m=mod){return a*b%m;}
ll qmul(ll x, ll y, ll mod){ll ret = 0;while(y) {if(y & 1) ret = (ret + x) % mod;x = x * 2 % mod;y >>= 1;}return ret;}
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 gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
void exgcd(ll a,ll b,ll &d,ll &x,ll &y){ if(!b)d=a,x=1,y=0;else exgcd(b,a%b,d,y,x),y-=x*(a/b);}
ll gcdinv(ll v,ll m=mod){ ll d,x,y;exgcd(v,m,d,x,y);return (x%m+m)%m;}
ll getinv(ll v,ll m=mod){ return qpow(v,m-2,m);}
ll qpows(ll a,ll b,ll m=mod){if(b>=0)return qpow(a,b,m);else return getinv(qpow(a,-b,m),m);}
int a[5];
void Solve(){
int n;
cin>>n;
for(int i=1;i<=3;i++){
cin>>a[i];
}
int ans=1;
while(true){
int t=n;
n=a[t];
ans++;
if(n==0){
no;
return;
}
if(ans==3)
{
yes;
return;
}
}
}
signed main()
{
//freopen("data.txt","r",stdin);
//_IOS;
int kase=1;
kase=read();
lfor(i,1,kase){
Solve();
}
return 0;
}
B - Also Try Minecraft
从高处跳到低处会扣血,从低处飞往高出不扣血
维护前缀和和后缀和
点击查看代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
#define int ll
#define lfor(i,a,b) for(int i=(a);i<=b;i++)
#define rfor(i,a,b) for(int i=(b);i>=a;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define _IOS (ios::sync_with_stdio(0),cin.tie(0),0)
#define db(i) printf("%d ",i);
#define endl "\n"
#define AC return
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
const int N=200005;
const int inf=0x3f3f3f3f;
const ll INF=~0ull>>2;
const ll mod=1e9+7;
ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;}
const lf pi=acos(-1.0);
lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;}
typedef pair<ll,ll> pii;
ll mul(ll a,ll b,ll m=mod){return a*b%m;}
ll qmul(ll x, ll y, ll mod){ll ret = 0;while(y) {if(y & 1) ret = (ret + x) % mod;x = x * 2 % mod;y >>= 1;}return ret;}
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 gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
void exgcd(ll a,ll b,ll &d,ll &x,ll &y){ if(!b)d=a,x=1,y=0;else exgcd(b,a%b,d,y,x),y-=x*(a/b);}
ll gcdinv(ll v,ll m=mod){ ll d,x,y;exgcd(v,m,d,x,y);return (x%m+m)%m;}
ll getinv(ll v,ll m=mod){ return qpow(v,m-2,m);}
ll qpows(ll a,ll b,ll m=mod){if(b>=0)return qpow(a,b,m);else return getinv(qpow(a,-b,m),m);}
int a[N],b[N],sum[N],c[N],sum_[N];
void Solve(){
int n;
cin>>n;
int m;
cin>>m;
mem(b,0);mem(c,0);
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=2;i<=n;i++){
if(a[i]<a[i-1])
b[i]=a[i-1]-a[i];
}
for(int i=n-1,j=2;i>=1;i--,j++){
if(a[i]<a[i+1])
c[j]=a[i+1]-a[i];
}
for(int i=2;i<=n;i++){
sum[i]=sum[i-1]+b[i];
}
for(int i=2;i<=n;i++){
sum_[i]=sum_[i-1]+c[i];
}
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
if(x<y)
cout<<sum[y]-sum[x]<<endl;
else{
cout<<sum_[n-y+1]-sum_[n-x+1]<<endl;
}
}
}
signed main()
{
//freopen("data.txt","r",stdin);
//_IOS;
int kase=1;
//kase=read();
lfor(i,1,kase){
Solve();
}
return 0;
}
D - Rorororobot
题意比较简单
用线段树维护区间最大值,然后模拟是否可以到达即可
点击查看代码
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
#define lfor(i,a,b) for(int i=(a);i<=b;i++)
#define rfor(i,a,b) for(int i=(b);i>=a;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define _IOS (ios::sync_with_stdio(0),cin.tie(0),0)
#define db(i) printf("%d ",i);
#define endl "\n"
#define AC return
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int maxnn=200005;
const int inf=0x3f3f3f3f;
const ll INF=~0ull>>2;
const ll mod=1e9+7;
ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;}
const lf pi=acos(-1.0);
lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;}
typedef pair<ll,ll> pii;
ll mul(ll a,ll b,ll m=mod){return a*b%m;}
ll qmul(ll x, ll y, ll mod){ll ret = 0;while(y) {if(y & 1) ret = (ret + x) % mod;x = x * 2 % mod;y >>= 1;}return ret;}
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 gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
void exgcd(ll a,ll b,ll &d,ll &x,ll &y){ if(!b)d=a,x=1,y=0;else exgcd(b,a%b,d,y,x),y-=x*(a/b);}
ll gcdinv(ll v,ll m=mod){ ll d,x,y;exgcd(v,m,d,x,y);return (x%m+m)%m;}
ll getinv(ll v,ll m=mod){ return qpow(v,m-2,m);}
ll qpows(ll a,ll b,ll m=mod){if(b>=0)return qpow(a,b,m);else return getinv(qpow(a,-b,m),m);}
int maxn[maxnn<<2];
void pushup(int rt){
maxn[rt] = max(maxn[rt<<1],maxn[rt<<1|1]);
}
void build(int l,int r,int rt){
if(l==r){
scanf("%d",&maxn[rt]);
return;
}
int m = (l+r)>>1;
build(lson);
build(rson);
pushup(rt);
}
int query(int L,int R,int l,int r,int rt){
if(L<=l && R>= r){
return maxn[rt];
}
int m = (l+r)>>1;
int cnt = -1;
if(L<=m)cnt = max(query(L,R,lson),cnt);
if(R>m)cnt = max(query(L,R,rson),cnt);
return cnt;
}
void Solve(){
int n,m;
scanf("%d%d",&n,&m);
build(1,m,1);
int q;
scanf("%d",&q);
while(q--){
int x,y,x_,y_,k;
scanf("%d%d%d%d%d",&x,&y,&x_,&y_,&k);
//cin>>x>>y>>x_>>y_>>k;
if(y==y_){
if(abs(x_-x)%k==0){
yes;
}
else
no;
}
else{
if(abs(y-y_)%k!=0){
no;
}
else{
int ans;
if(y<y_){
ans=query(y,y_,1,m,1);
//cout<<ans<<endl;
int t=(n-x)%k;
if(ans>=n-t){
no;
continue;
}
int t_=(n-t-x_)%k;
if(t_==0)
yes;
else
no;
}
else{
ans=query(y_,y,1,m,1);
int t=(n-x_)%k;
if(ans>=n-t){
no;
continue;
}
int t_=(n-t-x)%k;
if(t_==0)
yes;
else
no;
}
}
}
}
}
signed main()
{
//freopen("data.txt","r",stdin);
//_IOS;
int kase=1;
//kase=read();
lfor(i,1,kase){
Solve();
}
return 0;
}

浙公网安备 33010602011771号