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)的更多相关文章

  1. Codeforces Round #520 (Div. 2) E. Company(dfs序判断v是否在u的子树里+lca+线段树)

    https://codeforces.com/contest/1062/problem/E 题意 给一颗树n,然后q个询问,询问编号l~r的点,假设可以删除一个点,使得他们的最近公共祖先深度最大.每次 ...

  2. Codeforces Round #520 (Div. 2) B. Math 唯一分解定理+贪心

    题意:给出一个x 可以做两种操作  ①sqrt(x)  注意必须是完全平方数  ② x*=k  (k为任意数)  问能达到的最小的x是多少 思路: 由题意以及 操作  应该联想到唯一分解定理   经过 ...

  3. CF每日一练 Codeforces Round #520 (Div. 2)

    比赛过程总结:过程中有事就玩手机了,后面打的状态不是很好,A题理解错题意,表明了内心不在状态,B题想法和思路都是完全正确的,但是并没有写出来,因为自己代码能力不强,思路不是特别清晰,把代码后面写乱了, ...

  4. Codeforces Round #520 (Div. 2) Solution

    A. A Prank Solved. 题意: 给出一串数字,每个数字的范围是$[1, 1000]$,并且这个序列是递增的,求最多擦除掉多少个数字,使得别人一看就知道缺的数字是什么. 思路: 显然,如果 ...

  5. Codeforces Round #520 (Div. 2) D. Fun with Integers

    D. Fun with Integers 题目链接:https://codeforc.es/contest/1062/problem/D 题意: 给定一个n,对于任意2<=|a|,|b|< ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #520 (Div. 2) B math(素数因子的应用)

    题意: 给出一个n ; 有两个操作: 1,mul A   ,   n=n*A   : 2,sqrt()  ,  n=sqrt(n)  开更出来必须是整数 : 求出经过这些操作后得出的最小  n , 和 ...

随机推荐

  1. mac 关于默认python2下的pip,和python3下pip 的坑

    pip是常用的python包管理工具,类似于java的maven.用python的同学,都离不开pip. 1.在Python2.7的安装包中,easy_install.py是默认安装的,而pip需要手 ...

  2. Django之集合函数使用与mysql表的创建特殊字段分析

    1. 集合函数的使用场景: -- 单独使用: 不分组, 只查聚合结果 -- 分组使用: 按字段分组, 可查询分组字段与聚合结果 2. 导入聚合函数 from django.db.models impo ...

  3. PRC远程过程调用

    RPC(Remote Promote Call) 一种进程间通信方式.允许像调用本地服务一样调用远程服务. RPC框架的主要目标就是让远程服务调用更简单.透明.RPC框架负责屏蔽底层的传输方式(TCP ...

  4. Unity系列文章

    1.IoC模式:http://www.cnblogs.com/qqlin/archive/2012/10/09/2707075.html  这篇博客是通过一个播放器的例子来说明什么是依赖,依赖倒置,控 ...

  5. sublime text 3 build 3143 安装详解

    sublime text 3 build 3143 安装详解   环境:ubuntu 16 (x64) 0x00 下载   官网下载地址   下载的文件是个压缩包,笔者解压之后将整个sublime-t ...

  6. Jupyter notebook 文件路径

    Jupyter notebook 文件路径 1. 默认工作路径:C:\Users\think 2. 修改工作路径: C:\Users\think\.jupyter路径下,无配置文件 打开命令提示符:( ...

  7. easyui分页,根据网友的一段代码优化了一下

    千言万语尽在代码中,可以自己看,不清楚留言吧! <%@ Page Language="C#" AutoEventWireup="true" CodeBeh ...

  8. Unity3D初学之2D动画制

    作者:Alex Rose Unity最近宣布推出额外的2D游戏支持,添加了Box 2D物理和一个精灵管理器. 但这里还是有些技巧需要牢记在心.逐帧更改图像只是动画制作的冰山一角,若要让你的游戏出色运行 ...

  9. java-学习8

    方法的声明及使用 public class function { public static void main(String[] args) { printInfo();//调用printInfo( ...

  10. python添加到环境变量

    1.命令 vi ~/.bashrc export PATH="/home/tiany/software/python/python3/3.6.1/bin:$PATH" export ...