当前位置:网站首页>2022 Henan Youth Training League Game (3)
2022 Henan Youth Training League Game (3)
2022-08-02 02:08:00 【Hhangya】
A.玉米大炮
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;
const int M=1e6+100;
ll n,m,t;
ll a[N],b[N];
int check(__int128 mid)
{
__int128 sum=0;
for(int i=1;i<=n;i++)
{
sum+=(mid/b[i])*a[i];
if(sum>=m) return 1;
}
return 0;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
m-=a[i];
}
__int128 l=0,r=1e18+100;
while(l<r)
{
__int128 mid=(l+r)>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
cout<<(ll)l<<endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=6500;
const int M=1e6+100;
const int mod=998244353;
const double eps=1e-9;
typedef pair<int,int> PII;
#define endl '\n'
#define x first
#define y second
#define INF 0x3f3f3f3f
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
int n,m,t;
int a[N],f[N][N];
int tr[N];
int lowbit(int x)
{
return x&-x;
}
void add(int x,int c)
{
for(int i=x;i<N;i+=lowbit(i))
tr[i]+=c;
}
ll query(int x)
{
ll res=0;
for(int i=x;i;i-=lowbit(i))
res+=tr[i];
return res;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++) //计算[l,r]区间的逆序对个数
{
for(int j=i;j<=n;j++)
{
f[i][j]=f[i][j-1]+(j-1-i+1-query(a[j]));
add(a[j],1);
}
memset(tr,0,sizeof tr); //The tree array is cleared after each calculation
}
cin>>t;
while(t--)
{
int l,r;
cin>>l>>r;
cout<<f[1][n]+(r-l+1)*(r-l)/2-2*f[l][r]<<endl; //1~n的逆序对+(正序对-逆序对)
}
return 0;
}
C.区间操作
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4e6+100;
const int M=1e6+100;
const int mod=998244353;
const double eps=1e-9;
typedef pair<int,int> PII;
#define endl '\n'
#define x first
#define y second
#define INF 0x3f3f3f3f
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
int n,m,t;
int f[N],b[N];
int prime[N],cnt;
bool st[N];
struct Node
{
int l,r;
ll sum,add;
}tr[N<<2];
void init(int n)
{
for(int i=2;i<=n;i++)
{
if(!st[i]) prime[cnt++]=i,f[i]=1;
for(int j=0;prime[j]<=n/i;j++)
{
st[prime[j]*i]=1;
f[prime[j]*i]=f[i]+1;
if(i%prime[j]==0) break;
}
}
}
void pushup(int u)
{
tr[u].sum=tr[u<<1].sum+tr[u<<1|1].sum;
}
void pushdown(int u)
{
auto &left=tr[u<<1],&root=tr[u],&right=tr[u<<1|1];
if(root.add)
{
left.sum+=(left.r-left.l+1)*root.add,left.add+=root.add;
right.sum+=(right.r-right.l+1)*root.add,right.add+=root.add;
root.add=0;
}
}
void build(int u,int l,int r)
{
if(l==r) tr[u]={l,r,b[l],0};
else
{
tr[u]={l,r};
int mid=l+r>>1;
build(u<<1,l,mid),build(u<<1|1,mid+1,r);
pushup(u);
}
}
void modify(int u,int l,int r,ll c)
{
if(l<=tr[u].l&&tr[u].r<=r)
{
tr[u].sum+=(tr[u].r-tr[u].l+1)*c;
tr[u].add+=c;
return ;
}
pushdown(u);
int mid=tr[u].l+tr[u].r>>1;
if(l<=mid) modify(u<<1,l,r,c);
if(r>mid) modify(u<<1|1,l,r,c);
pushup(u);
}
ll query(int u,int l,int r)
{
if(l<=tr[u].l&&tr[u].r<=r) return tr[u].sum;
pushdown(u);
int mid=tr[u].l+tr[u].r>>1;
ll sum=0;
if(l<=mid) sum=query(u<<1,l,r);
if(r>mid) sum+=query(u<<1|1,l,r);
return sum;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
init(N-1);
cout<<cnt<<endl;
cin>>n;
for(int i=1;i<=n;i++) cin>>b[i],b[i]=f[b[i]];
build(1,1,n);
cin>>t;
int op,l,r,w;
while(t--)
{
cin>>op>>l>>r;
if(op==1) cout<<query(1,l,r)<<endl;
else
{
cin>>w;
modify(1,l,r,f[w]);
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;
const int M=1e6+100;
const int mod=998244353;
const double eps=1e-9;
typedef pair<int,int> PII;
#define endl '\n'
#define x first
#define y second
#define INF 0x3f3f3f3f
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
ll n,m,t;
ll get(ll x)
{
ll l=1,r=1e6;
while(l<r)
{
ll mid=l+r+1>>1;
if(mid*mid*mid<=x) l=mid;
else r=mid-1;
}
return l;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n;
int ans=0;
for(ll g=1;g<=n/g/g;g++)
{
for(ll a=g;a<=n/a/a;a+=g)
{
ll p=n-g*g*g; //Use the equation condition of the question
ll k=get(p); //求出lcm
if(k*k*k==p) //判断lcm合法
{
ll lcm=k;
ll b=lcm*g/a; //利用公式求出b
if(!b) continue; //It is possible to get floating point errors,即除0
if(__gcd(a,b)==g&&a*b/__gcd(a,b)==lcm) //Finally, return to determine whether it is satisfiedgcd,lcm
ans++;
}
}
}
cout<<ans<<endl;
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;
const int M=1e6+100;
const int mod=998244353;
const double eps=1e-9;
const double pi = acos(-1) ;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
#define endl '\n'
#define x first
#define y second
#define INF 0x3f3f3f3f
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
int n,m,t;
double x,y;
vector<PDD> ans;
double dist(double x,double y)
{
return x*x+y*y;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n;
while(n--)
{
cin>>x>>y;
double gel=atan2(y,x);
double keg=asin(2.0/sqrt(dist(x,y)));
ans.push_back({gel,min(gel+keg,pi)});
if(gel+keg>pi) ans.push_back({-pi,-pi+gel+keg-pi}); //The size can be seen in radian range[-pi,pi],小的在前,大的在后,Otherwise it will affect the final merge
ans.push_back({max(gel-keg,-pi),gel});
if(gel-keg<-pi) ans.push_back({pi-fabs(gel-keg+pi),pi});
}
sort(ans.begin(),ans.end());
double res=0,pre=-1e9;
for(int i=0;i<ans.size();i++) //合并区间
{
if(pre>ans[i].x) res+=max(0.0,ans[i].y-pre);// 可能pregreater than the right endpoint of the interval,That is, the interval has been included
else res+=ans[i].y-ans[i].x;
pre=max(pre,ans[i].y);
}
printf("%.12f",res/(2.0*pi));
return 0;
}
H.树上问题
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;
const int M=1e6+100;
const int mod=998244353;
const double eps=1e-9;
typedef pair<int,int> PII;
#define endl '\n'
#define x first
#define y second
#define INF 0x3f3f3f3f
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
int n,m,t;
vector<int> e[N];
// f表示uGo all the way down as far as you can go,r表示uThe farthest distance to continue up through the parent node,w表示u能到达的最远距离
ll f[N],r[N],w[N],dp[N],a[N];
ll res;
void dfsf(int u,int fa) //Update parent node by child node Find the furthest distance it can go down
{
f[u]=a[u];
ll t=0;
for(auto to:e[u])
{
if(to==fa) continue;
dfsf(to,u);
t=max(t,f[to]);
}
f[u]+=t;
}
void dfsw(int u,int fa) //Update child nodes by parent node 求出w
{
ll m1=0,m2=0;
for(auto to:e[u])
{
if(to==fa) continue;
if(f[to]>m1) m2=m1,m1=f[to];
else if(f[to]>m2) m2=f[to];
}
for(auto to:e[u])
{
if(to==fa) continue;
if(m1==f[to])
{
//vThe furthest distance you can go is max(The farthest distance that a child node can go down f[v],Walk up past the parent node and continue up a[v]+r[u],The node walks up past the parent node,The farthest distance that can be traveled down through the parent node(It can only be a long distance here),a[v]+a[u]+m2)
w[to]=max({f[to],a[to]+r[u],a[to]+a[u]+m2});
r[to]=max(a[to]+r[u],a[to]+a[u]+m2);
}
else
{
w[to]=max({f[to],a[to]+r[u],a[to]+a[u]+m1});
r[to]=max(a[to]+r[u],a[to]+a[u]+m1);
}
dfsw(to,u);
}
}
void dfsres(int u,int fa) // Update the selected nodeu,And choose the farthest distance that a child node can reach,And calculate the maximum of the two cases at that point
{
//m1,m2 Record the maximum of child nodes/next largest distance,m3记录选择u的子节点v,and choose another onevThe maximum reachable distance of the child nodes of
ll m1=0,m2=0,m3=0;
for(auto to:e[u])
{
if(to==fa) continue;
if(w[to]>m1) m2=m1,m1=w[to];
else if(w[to]>m2) m2=w[to];
dfsres(to,u); //First recursively find the child nodesdp值,再求最大值
m3=max(m3,dp[to]);
}
dp[u]=w[u]+m1; //更新dp值 u能到达的最远距离+The furthest distance his son can reach
res=max({m1+m2+w[u],m3+w[u],res}); //两种情况
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=0;i<n-1;i++)
{
int u,v;
cin>>u>>v;
e[u].push_back(v);
e[v].push_back(u);
}
dfsf(1,0);
w[1]=f[1]; //1为根节点,The furthest distance that can be reached isf[1]
r[1]=a[1]; //The distance to go up is only the value of its own node
dfsw(1,0);
dfsres(1,0);
cout<<res<<endl;
return 0;
}
I.旅行
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;
const int M=1e6+100;
const int mod=998244353;
const double eps=1e-9;
typedef pair<int,int> PII;
#define endl '\n'
#define x first
#define y second
#define INF 0x3f3f3f3f
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
int n,m;
int h[2*N],e[2*M],ne[2*M],idx;
ll w[2*M],x;
ll dis[2*N];
bool st[2*N];
void add(int a,int b,ll c)
{
w[idx]=c;
e[idx]=b;
ne[idx]=h[a];
h[a]=idx++;
}
void dj()
{
priority_queue<PII,vector<PII>,greater<PII>> heap;
memset(dis,0x3f,sizeof dis);
dis[1]=0; //Because the first point does not need to do nucleic acid,And the cost of the journey is 0,所以初始为0
heap.push({0,1});
while(heap.size())
{
auto t=heap.top();
heap.pop();
if(st[t.y]) continue;
st[t.y]=1;
for(int i=h[t.y];~i;i=ne[i])
{
int j=e[i];
if(dis[j]>dis[t.y]+w[i])
{
dis[j]=dis[t.y]+w[i];
heap.push({dis[j],j});
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
memset(h,-1,sizeof h);
cin>>n>>m>>x;
int a,b;
ll c;
while(m--)
{
cin>>a>>b>>c;
add(a,b+n,c+x),add(a+n,b,c);
add(b,a+n,c+x),add(b+n,a,c);
}
dj();
cout<<min(dis[n],dis[2*n])<<endl; //Because the optimal path is not knownnNucleic acid situation at the point,So you need to take bothmin.
return 0;
}
边栏推荐
猜你喜欢
垃圾回收器CMS和G1
openGauss切换后state状态显示不对
Scheduled tasks for distributed applications in Golang
6-24 exploit-vnc password cracking
Use baidu EasyDL implement factory workers smoking behavior recognition
The Paddle Open Source Community Quarterly Report is here, everything you want to know is here
AOF rewrite
Day116.尚医通:预约挂号详情 ※
Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021:解读
Constructor instance method inheritance of typescript37-class (extends)
随机推荐
Project Background Technology Express
秒懂大模型 | 3步搞定AI写摘要
软件测试 接口自动化测试 pytest框架封装 requests库 封装统一请求和多个基础路径处理 接口关联封装 测试用例写在yaml文件中 数据热加载(动态参数) 断言
待读书单列表
记录一次数组转集合出现错误的坑点,尽量使用包装类型数组进行转换
typescript31-any类型
力扣 1374. 生成每种字符都是奇数个的字符串
Shell Beginners Final Chapter
Garbage Collector CMS and G1
垃圾回收器CMS和G1
Multi-Party Threshold Private Set Intersection with Sublinear Communication-2021: Interpretation
LeetCode刷题日记:LCP 03.机器人大冒险
swift项目,sqlcipher3 -&gt; 4,无法打开旧版数据库有办法解决吗
LeetCode brushing diary: 53, the largest sub-array and
Typescript31 - any type
【服务器数据恢复】服务器Raid5阵列mdisk磁盘离线的数据恢复案例
6-25 Vulnerability Exploitation - irc Backdoor Exploitation
Simple example of libcurl accessing url saved as file
CodeTon Round 2 D. Magical Array
From 2023 onwards, these regions will be able to obtain a certificate with a score lower than 45 in the soft examination.