Codeforces Round #520 (Div. 2)
Codeforces Round #520 (Div. 2)
https://codeforces.com/contest/1062
A
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int a[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
int n;
cin>>n;
if(n==) {
cout<<<<endl;
return ;
}
for(int i=;i<=n;i++) cin>>a[i];
a[]=,a[n+]=;
int ans=,Max=;
for(int i=;i<=n+;i++){
if(a[i]-a[i-]==){
Max++;
}
else{
ans=max(ans,Max-);
Max=;
} }
ans=max(ans,Max-);
cout<<ans<<endl;
}
B
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int a[]; int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
ll n;
cin>>n;
ll tmp=n;
ll num=;
for(int i=;i<=n;i++){
if(tmp%i==){
num*=i;
while(tmp%i==){
tmp/=i;
}
}
}
ll ans=;
tmp=num;
while(num%n){
num*=num;
ans++;
}
cout<<tmp<<" "<<(ans+(num>n))<<endl;
}
C
数论+推公式
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ string str;
ll sum[]; ll pow_mul(ll a,ll b){
ll ans=;
while(b){
if(b&)
ans=ans*a%mod;
b>>=;
a=a*a%mod;
}
return ans;
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
int n,q;
cin>>n>>q;
cin>>str;
for(int i=;i<n;i++){
sum[i+]=sum[i]+str[i]-'';
}
int l,r;
while(q--){
cin>>l>>r;
ll ans=pow_mul(,sum[r]-sum[l-])-;
if(ans==-) ans+=mod;
ans=(ans+ans*(pow_mul(,r-l++sum[l-]-sum[r])-+mod)%mod)%mod;
cout<<ans<<endl;
}
}
D
数论
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
int n;
cin>>n;
ll ans=;
for(int i=;i<=n;i++){
for(int j=i+i;j<=n;j+=i){
ans+=j/i;
}
}
cout<<ans*<<endl;
}
E
lca+线段树+倍增
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 100005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ //int phi[maxn]; vector<int>ve[maxn]; int dep[maxn],parent[maxn][],n,cnt;
int Max[maxn<<],Min[maxn<<],id[maxn],s[maxn]; void dfs(int now,int fa,int deep){
dep[now]=deep;
parent[now][]=fa;
s[now]=++cnt;
id[cnt]=now;
for(int i=;i<ve[now].size();i++){
dfs(ve[now][i],now,deep+);
}
} void Init(){
for(int j=;j<;j++){
for(int i=;i<=n;i++){
parent[i][j]=parent[parent[i][j-]][j-];
}
}
} int lca(int x,int y){
if(dep[x]<dep[y]) swap(x,y);
for(int i=;i>=;i--){
if(dep[parent[x][i]]>=dep[y]){
x=parent[x][i];
}
}
if(x==y) return dep[x]-;
for(int i=;i>=;i--){
if(parent[x][i]!=parent[y][i]){
x=parent[x][i];
y=parent[y][i];
}
}
return dep[parent[x][]]-;
} int query1(int L,int R,int l,int r,int rt){
if(L<=l&&R>=r) return Max[rt];
int mid=l+r>>;
int ans=;
if(L<=mid) ans=max(ans,query1(L,R,lson));
if(R>mid) ans=max(ans,query1(L,R,rson));
return ans;
} int query2(int L,int R,int l,int r,int rt){
if(L<=l&&R>=r) return Min[rt];
int mid=l+r>>;
int ans=0x3f3f3f3f;
if(L<=mid) ans=min(ans,query2(L,R,lson));
if(R>mid) ans=min(ans,query2(L,R,rson));
return ans;
} void push_up(int rt){
Max[rt]=max(Max[rt<<],Max[rt<<|]);
Min[rt]=min(Min[rt<<],Min[rt<<|]);
} void update(int L,int v,int l,int r,int rt){
if(l==r){
Max[rt]=Min[rt]=v;
return;
}
int mid=l+r>>;
if(L<=mid) update(L,v,lson);
else update(L,v,rson);
push_up(rt);
} int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
int q;
cin>>n>>q;
int x,y;
for(int i=;i<=n;i++){
cin>>x;
ve[x].pb(i);
}
dfs(,,);
Init();
for(int i=;i<=n;i++){
update(i,s[i],,n,);
}
while(q--){
cin>>x>>y;
int min1=query2(x,y,,n,);
int max1=query1(x,y,,n,);
update(id[min1],0x3f3f3f3f,,n,);
int min2=query2(x,y,,n,);
update(id[min1],min1,,n,);
update(id[max1],,,n,);
int max2=query1(x,y,,n,);
update(id[max1],max1,,n,);///?
int ans1=lca(id[min1],id[max2]),ans2=lca(id[min2],id[max1]);
if(ans1>=ans2){
cout<<id[max1]<<" "<<ans1<<endl;
}
else{
cout<<id[min1]<<" "<<ans2<<endl;
}
} }
F
拓扑排序
参考博客:https://www.cnblogs.com/yqgAKIOI/p/10012279.html
#include<bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sqr(x) ((x)*(x))
#define pb push_back
#define eb emplace_back
#define maxn 300005
#define eps 1e-8
#define pi acos(-1.0)
#define rep(k,i,j) for(int k=i;k<j;k++)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,int>pli;
typedef pair<int,char> pic;
typedef pair<pair<int,string>,pii> ppp;
typedef unsigned long long ull;
const long long mod=1e9+;
/*#ifndef ONLINE_JUDGE
freopen("1.txt","r",stdin);
#endif */ int n,m;
int a[maxn],b[maxn],d[maxn],cnt[maxn];
vector<int>ve[maxn]; void topsort(int a[],int b[]){
for(int i=;i<n;i++) ve[i].clear();
for(int i=;i<m;i++){
ve[a[i]].pb(b[i]);
d[b[i]]++;
}
int num=n;
queue<int>Q;
for(int i=;i<n;i++){
if(!d[i]){
Q.push(i);
num--;
}
}
while(!Q.empty()){
int now=Q.front();
Q.pop();
if(Q.empty()) cnt[now]+=num;
else if(Q.size()==){
int tmp=;
for(int i=,y=Q.front();i<ve[y].size();i++){
tmp&=(d[ve[y][i]]>);
}
cnt[now]+=num*tmp;
}
for(int i=;i<ve[now].size();i++)
if(!--d[ve[now][i]]){
Q.push(ve[now][i]);
num--;
}
} } int main(){
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
#endif
std::ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=;i<m;i++){
cin>>a[i]>>b[i];
a[i]--,b[i]--;
}
topsort(a,b);
topsort(b,a);
int ans=;
for(int i=;i<n;i++)
ans+=(cnt[i]+>=n);
cout<<ans<<endl; }
Codeforces Round #520 (Div. 2)的更多相关文章
- Codeforces Round #520 (Div. 2) E. Company(dfs序判断v是否在u的子树里+lca+线段树)
https://codeforces.com/contest/1062/problem/E 题意 给一颗树n,然后q个询问,询问编号l~r的点,假设可以删除一个点,使得他们的最近公共祖先深度最大.每次 ...
- Codeforces Round #520 (Div. 2) B. Math 唯一分解定理+贪心
题意:给出一个x 可以做两种操作 ①sqrt(x) 注意必须是完全平方数 ② x*=k (k为任意数) 问能达到的最小的x是多少 思路: 由题意以及 操作 应该联想到唯一分解定理 经过 ...
- CF每日一练 Codeforces Round #520 (Div. 2)
比赛过程总结:过程中有事就玩手机了,后面打的状态不是很好,A题理解错题意,表明了内心不在状态,B题想法和思路都是完全正确的,但是并没有写出来,因为自己代码能力不强,思路不是特别清晰,把代码后面写乱了, ...
- Codeforces Round #520 (Div. 2) Solution
A. A Prank Solved. 题意: 给出一串数字,每个数字的范围是$[1, 1000]$,并且这个序列是递增的,求最多擦除掉多少个数字,使得别人一看就知道缺的数字是什么. 思路: 显然,如果 ...
- Codeforces Round #520 (Div. 2) D. Fun with Integers
D. Fun with Integers 题目链接:https://codeforc.es/contest/1062/problem/D 题意: 给定一个n,对于任意2<=|a|,|b|< ...
- Codeforces Round #520 (Div. 2) C. Banh-mi
C. Banh-mi time limit per test:1 second memory limit per test:256 megabytes 题目链接:https://codeforc.es ...
- Codeforces Round #520 (Div. 2) B. Math
B. Math time limit per test:1 second memory limit per test:256 megabytes Description: JATC's math te ...
- Codeforces Round #520 (Div. 2) A. A Prank
A. A Prank time limit per test 1 second memory limit per test 256 megabytes 题目链接:https://codefo ...
- Codeforces Round #520 (Div. 2) B math(素数因子的应用)
题意: 给出一个n ; 有两个操作: 1,mul A , n=n*A : 2,sqrt() , n=sqrt(n) 开更出来必须是整数 : 求出经过这些操作后得出的最小 n , 和 ...
随机推荐
- H5自动准备杂记
由于之前没做过UI自动化,近期准备做H5自动化,要学的东西还是很多. 1.本地debug环境:android studio + android SDK(想要调试通要关注:驱动.手机开发者模式要打开) ...
- openGL-------------别人的博客
https://blog.csdn.net/dcrmg/article/category/6505957 OpenGL(一)绘制圆.五角星.正弦曲线 ========================= ...
- python 可迭代对象与迭代器
生成器函数的工作原理只要 Python 函数的定义体中有 yield 关键字, 该函数就是生成器函数. 调用生成器函数时, 会返回一个生成器对象. 也就是说, 生成器函数是生成器工厂. 调用生成器函数 ...
- Python3.7中urllib.urlopen 报错问题
import urllib web = urllib.urlopen('https://www.baidu.com') f = web.read() print(f) 报错: Traceback (m ...
- Intellij IDEA使用spring-boot-devtools无效解决办法(2018年3月9日11:46:00)
步骤一:pom.xml中加入: <dependency> <groupId>org.springframework.boot</groupId> <artif ...
- Delphi编写Shell扩展
用delphi创建一个外壳扩展(Shell Extension)程序的基本步骤如下: (1) 创建一个 ActiveX Library 工程,命名为“CloudUpload“(2) 创建一个新的自动化 ...
- IE (第一部分) 浏览器 中 关于浏览器模式和文本模式的困惑
什么是浏览器模式和文本模式? 经常使用IE开发者工具的同学,肯定见过浏览器模式和文本模式,对于这两个名词,综合相关文档解释如下: 浏览器模式(Browser Mode),用于切换IE针对该网页的默认文 ...
- Unity3D脚本学习——运行时类
AssetBundle 类,继承自Object.AssetBundles让你通过WWW类流式加载额外的资源并在运行时实例化它们.AssetBundles通过BuildPipeline.BuildAss ...
- Promise 学习
参考 https://www.jianshu.com/p/43f948051d65 // Promise里面传入一个函数类型的参数,这个函数类型的参数接收两个参数resolve reject var ...
- mysql 拼接字符
Mysql的查询结果行字段拼接,可以用下面两个函数实现: 1. concat函数 mysql> select concat('1','2','3') from test ; +--------- ...