ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Educational Codeforces Round 132 (Rated for Div. 2)

2022-07-22 11:05:45  阅读:173  来源: 互联网

标签:Educational Rated const int Codeforces long read ch define


寅壬年六月廿三,公历2022年7月21日夜,与同机房大佬打CF,心态大崩,遂作此篇

T1 Three Doors

题目传送门

题目大意:有3个门,编号分别为1、2、3,其中两扇门后藏有钥匙。有3把钥匙,其中两把藏在门后,一把在手中。编号为i的门只能用编号为i的钥匙打开,藏在门后的钥匙只有在那扇门打开后才能使用。

整体思路:。。。。签到题,简单模拟一下就行,并没有什么奇技淫巧巧妙的方法

附上代码(水点长度

点击查看代码
#include <bits/stdc++.h>
using namespace std;

#define Multicase() for(int T = read() ; T ; T--)
#define lowbit(x) (x & (-x))
#define ls(p) (p<<1)
#define rs(p) (p<<1|1)
#define l(p) tree[p].l
#define r(p) tree[p].r
#define sum(p) tree[p].sum
#define tag(p) tree[p].tag
#define F(i,a,b) for(int i=(a) ;i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i< (b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define endl '\n'
#define ENDL putchar('\n')
#define forGraph(u) for(int i=head[u];i;i=G[i].next)
#define _file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);

const int N=5e5+5;
const int M=1e6+5;
const int MN=1e3+5;
const int iinf=INT_MAX;
const double eps=1e-9;
const double pi=acos(-1);
const long long linf=LLONG_MAX;
const long long mod=1000000007,mod2=998244353;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<string,int> msi;

inline int read(){int x(0), f(0); char ch=getchar(); while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48); ch=getchar();} return f?-x:x;}
template <typename T> void read(T &x){x=0; T f(0); char ch=getchar(); while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48); ch=getchar();} x=f?-x:x;}
template <typename T,typename ...Arg>void read(T& x,Arg& ...arg){read(x);read(arg...);}
template <typename T> inline void write(T x){static char buf[64]; static int tot(0); if(x<0) putchar('-'),x=-x; do buf[++tot]=(x%10)+48,x/=10; while(x); do putchar(buf[tot--]); while(tot);}
template <typename T> void write(T x,char c){static char buf[64]; static int tot(0); if(x<0) putchar('-'),x=-x; do buf[++tot]=(x%10)+48,x/=10; while(x); do putchar(buf[tot--]); while(tot); putchar(c);}
void judge(bool x){printf(x?"YES\n":"NO\n");}

void Solve();

struct Graph{
	int to,w,next;
}G[M<<1];
int head[N],_cnt;
void addEdge(int u,int v,int w){G[++_cnt]=(Graph){v,w,head[u]}; head[u]=_cnt;}

int n,m,q,k,p;
int a[5];
bool vis[10];
vector<int> v;

int main(){
	Multicase()
		Solve();
}

void Solve(){
	memset(vis,0,sizeof(vis));
	read(q);
	F(i,1,3) read(a[i]);
	vis[q]=1;
	while(a[q]) vis[a[q]]=1,q=a[q];
	F(i,1,3) if(vis[i]==0) return judge(0),void();
	judge(1);
}

T2 Also Try Minecraft

题目传送门

题目大意:自行翻译,时间不够了(英语实在太烂了

整体思路:看了下题面,不难发现的两种需要考虑的情况

1、从位置a到a+i(i>0)

image

2、从位置a到a-i(i>0)

image

机房某线性筛(此处取首字母):这有什么区别吗?我用暴力不都是 O(N) 吗??

灵魂三连问

现在的少爷机都能跑 \(10^{10}\) 了吗???

现在的线性筛都这么暴力坦率了???

现在的前缀和&后缀和的预处理已经一文不值了???

是的,正如上文中提到的,前后缀的预处理,才是本题的关键

再用刚刚的图举个栗子

image

在图片中,pre储存的是前缀和,即预处理了刚刚提及的第一种情况;而suf存储的是后缀和,即即预处理了刚刚提及的第二种情况

至于如何维护前缀和&后缀和,代码中会用注释标出,此处不多赘述

点击查看代码
#include <bits/stdc++.h>
using namespace std;

#define Multicase() for(int T = read() ; T ; T--)
#define lowbit(x) (x & (-x))
#define ls(p) (p<<1)
#define rs(p) (p<<1|1)
#define l(p) tree[p].l
#define r(p) tree[p].r
#define sum(p) tree[p].sum
#define tag(p) tree[p].tag
#define F(i,a,b) for(int i=(a) ;i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i< (b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define endl '\n'
#define ENDL putchar('\n')
#define forGraph(u) for(int i=head[u];i;i=G[i].next)
#define _file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);

const int N=5e5+5;
const int M=1e6+5;
const int MN=1e3+5;
const int iinf=INT_MAX;
const double eps=1e-9;
const double pi=acos(-1);
const long long linf=LLONG_MAX;
const long long mod=1000000007,mod2=998244353;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<string,int> msi;

inline int read(){int x(0), f(0); char ch=getchar(); while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48); ch=getchar();} return f?-x:x;}
template <typename T> void read(T &x){x=0; T f(0); char ch=getchar(); while(ch<'0'||ch>'9'){f|=ch=='-';ch=getchar();} while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48); ch=getchar();} x=f?-x:x;}
template <typename T,typename ...Arg>void read(T& x,Arg& ...arg){read(x);read(arg...);}
template <typename T> inline void write(T x){static char buf[64]; static int tot(0); if(x<0) putchar('-'),x=-x; do buf[++tot]=(x%10)+48,x/=10; while(x); do putchar(buf[tot--]); while(tot);}
template <typename T> void write(T x,char c){static char buf[64]; static int tot(0); if(x<0) putchar('-'),x=-x; do buf[++tot]=(x%10)+48,x/=10; while(x); do putchar(buf[tot--]); while(tot); putchar(c);}
void judge(bool x){printf(x?"YES\n":"NO\n");}

void Solve();

struct Graph{
	int to,w,next;
}G[M<<1];
int head[N],_cnt;
void addEdge(int u,int v,int w){G[++_cnt]=(Graph){v,w,head[u]}; head[u]=_cnt;}

int n,m,q,k,p;
ll a[N],b[N],f[N];
ll pre[N],suf[N];
vector<int> v;

int main(){
//	Multicase()
		Solve();
}

void Solve(){
	read(n,q);
	F(i,1,n) read(a[i]);
	F(i,2,n) if(a[i-1]>a[i]) pre[i]=a[i-1]-a[i];
	dF(i,n-1,1) if(a[i+1]>a[i]) suf[i]=a[i+1]-a[i];
	F(i,1,n) pre[i]+=pre[i-1];
	dF(i,n,1) suf[i]+=suf[i+1];//预处理前缀和&后缀和
	while(q--){
		int x,y;
		read(x,y);
		if(x<=y) write(pre[y]-pre[x],'\n');
		else write(suf[y]-suf[x],'\n');
	}
}

标签:Educational,Rated,const,int,Codeforces,long,read,ch,define
来源: https://www.cnblogs.com/r-y-m/p/16504799.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有