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 , 和 ...
随机推荐
- Excel快捷生成想要的xml或text
1.新建一个xml格式的A.xml文本,里面有4条以上的内容,注意哦,里面的元素与Excel里面的标题列数是一直的,不然会少了对应的某列数据.如: 2.打开Excel——>新建一个sheetl— ...
- 【坑】tableView cell默认选中
在tableView展示的过程时候,如果想一开始就有一些cell默认被选中,不能在cellForRowAtIndexPath中cell.selected=YES, 必须在willDisplayCell ...
- java 线程状态相关测试
1. 启动netty server 等待接受客户端连接 package io.netty.example.myTest.nio; import java.io.IOException; import ...
- 2018SDIBT_国庆个人第三场
A - A CodeForces - 1042A There are nn benches in the Berland Central park. It is known that aiai peo ...
- 尚硅谷springboot学习9-配置文件值注入
首先让我想到的是spring的依赖注入,这里我们可以将yaml或者properties配置文件中的值注入到java bean中 配置文件 person: lastName: hello age: 18 ...
- js总结001
JSTL 表达式与 EL 语言 http://leon906998248.iteye.com/blog/1502569 2 jquery中$each()方法的使用指南 http: ...
- webpack 自动发现 entry 的配置和引用方式
假定我们的项目目录为如下的样子: - root/ - assets/ - app/ - global.js - index/ - index.js - auth/ - login.js - regis ...
- mysql分表实战
本文主要讲述如何使用存储过程完成本表.并不讨论其他问题.首先我们得看看手册上关于meger引擎的说明: MERGE存储引擎,也被认识为MRG_MyISAM引擎,是一个相同的可以被当作一个来用的MyIS ...
- 修改maven项目的编译版本
在pom.xml中添加如下代码 <build> <!-- 配置了很多插件 --> <plugins> <plugin> <groupId>o ...
- python3进行汉字和unicode码的转换
输出某个unicode码对应的汉字和某个汉字对应的unicode编码. # -*- coding=UTF-8 -*- str1 = "\u6000"#某个汉字的unicode码 s ...