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 , 和 ...
随机推荐
- Appium -选择、操作元素
选择界面元素 操作元素(点击.输入字符.拖拽.获取页面元素的各种属性) 根据Appium获取的数据进行分析和处理 desired_capabilities 查看appPackage 和appActiv ...
- ACM__菜鸟之经典错误
1:多组输入与单组输入 Input contains multiple test cases. Input contains a single test case. 2: EOF=-1 while( ...
- docker之docker-machine用法
转自:https://www.cnblogs.com/jsonhc/p/7784466.html docker-machine 是docker官方提供的docker管理工具.通过docker-mach ...
- 修改 计算机名后,修改SQLserver 注册服务器对象的名称,及登陆名
select @@ServerName --查看当前所有数据库服务器名称select * from Sys.SysServers --修改数据库服务器名称sp_dropserver 'old_serv ...
- vmware搭建lnmp环境配置域名
找到nginx配置文件,修改server_name 然后找到/etc/hosts文件 修改成如下 之后在Windows本地的C盘的hosts文件中添加解析 好了,这样就可以访问了 通往牛逼的路上,在意 ...
- [重点]delphi 实现 根据给定的标题去《中国青年报》网上电子报数据中查找匹配的内容,并从该内容中取出引题、正题、副题、作者和正文。
项目要求:根据给定的标题去<中国青年报>网上电子报数据中查找匹配的内容,并从该内容中取出引题.正题.作者和正文. unit Unit1; interface uses Winapi.Win ...
- [原创]delphi在win7下创建共享文件夹源代码
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- 多线程 死锁 wait(int i) notifyAll()
public class ThreadDemo5 { public static void main(String[] args){ Pool pool = new Pool(); Productor ...
- 传输层——TCP报文头介绍
16位源端口号 16位目的端口号 32位序列号 32位确认序列号 4位头部长度 保留6位 U R G A C K P S H R S T S Y N F I N 16位窗口大小 16位检验和 16位紧 ...
- spring boot集成MyBatis