D题:https://codeforces.com/contest/1321/problem/D

题意:题目给个有向图,然后给一段序列,我们要沿着这个序列走,问走的过程中当前点到t的最短路会重构多少次,输出最小最大可能

分析:终点是不变的,我们在按照序列走到某个位置的时候,到终点有若干条长度相同的最短路,也由此有最大最小可能;

   我们考虑最短路的dis[](各点到终点的距离)我们模拟走的过程,当前点u,下一个点v,很明显地,当dis[u]+1!=dis[v]时,肯定会重构;

   当等于是,最小可能就不要加贡献,那么最大就重u的出边造出有没有另一条满足dis[u]+1==dis[k](k!=v)若存在则最大可能加一贡献

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int M=2e5+6;
#define pb push_back
struct node{
int v,cost;
node(int vv=0,int cc=0):v(vv),cost(cc){}
bool operator<(const node &b)const{
return cost>b.cost;
}
};
struct edge{
int v,cost;
edge(int vv=0,int cc=0):v(vv),cost(cc){}
};
vector<edge>g1[M],g2[M];
int vis[M],dis[M],a[M];
void dij(int n,int s){
memset(vis,0,sizeof(vis));
for(int i=1;i<=n;i++)
dis[i]=inf;
priority_queue<node>que;
while(!que.empty())
que.pop();
dis[s]=0;
que.push(node(s,0));
while(!que.empty()){
node now=que.top();
que.pop();
int u=now.v;
if(vis[u])
continue;
vis[u]=1;
for(int i=0;i<g2[u].size();i++){
int v=g2[u][i].v;
int cost=g2[u][i].cost;
if(!vis[v]&&dis[v]>dis[u]+cost){
dis[v]=dis[u]+cost;
que.push(node(v,dis[v]));
}
}
}
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
while(m--){
int u,v;
scanf("%d%d",&u,&v);
g1[u].pb(edge(v,1));
g2[v].pb(edge(u,1));
} scanf("%d",&m);
for(int i=1;i<=m;i++)
scanf("%d",&a[i]);
dij(n,a[m]); int ans1=0,ans2=0;
for(int i=2;i<=m;i++){
int x=a[i-1],y=a[i];
if(dis[x]!=dis[y]+1)
ans1++,ans2++;
else{
int flag=0;
for(int i=0;i<g1[x].size();i++){
int v=g1[x][i].v;
if(v!=y&&dis[x]==dis[v]+1){
flag=1;
break;
}
}
ans2+=flag;
}
}
printf("%d %d\n",ans1,ans2);
return 0;
}

E题:

题意:给定n个剑,m个盾,每个剑和盾都有俩个属性val和cost,p个怪兽,每个怪兽都有三个属性vala(对应剑的属性),valb(对应盾的属性),cost。题目要求一定要选一剑一盾,会对答案造成cost的消耗;你可以把属性严格小于你所选的武器的怪兽消灭来得到怪兽的cost加到贡献上,要求输出最大贡献;

分析:我们考虑枚举每一个vala作为最大值,比vala小的怪兽肯定在候选队列中,然后考虑选取哪一位置的盾来使答案最优;

   因为我们枚举的这个vala最大值,所以我们必须在[valb+1,max]中选取盾,涉及到区间,也是求区间最大值,我们考虑能否用线段树解决,于是我们把每次枚举到的valb,在线段树的[valx+1,max]加上它的cost,表示我们选了盾的属性在[valb+1,max],就可以得到他的贡献cost;

   在vala枚举的过程中我们肯定要先把vala进行升序处理,就把已经处理过的加到线段树上,区间取最大值即可;

   我们用线段树解决的盾和怪兽对盾属性的处理,那么对于剑和怪兽对剑属性,我们只要在剑属性升序的序列中找到第一个比当前vala大的位置pos,再在[pos,n]中找cost最小即可,这俩者相加就是当前vala最为最大值的最优解;

   ///实际也就分出俩部分处理,一部分(剑/盾  对 怪兽)和另一部分(剑/盾  对怪兽),任意一个用一个数据结构维护剩下的直接贪心解决;

using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=1e18;
const int M=1e6+6;
#define pb push_back
#define lson root<<1,l,midd
#define rson root<<1|1,midd+1,r
struct node{
ll val,cost;
bool operator<(const node &no)const{
return val<no.val;
}
}a[M+6],b[M+6];
struct Node{
ll vala,valb,cost;
bool operator<(const Node &No)const{
return vala<No.vala;
}
}c[M+6];
ll tr[(M<<2)+6],ly[(M<<2)+6];
ll all[M+6],tmp[M+6],suf[M+6];
void up(int root){
tr[root]=max(tr[root<<1],tr[root<<1|1]);
}
void pushdown(int root,int l,int r){
if(ly[root]){
ll x=ly[root];
tr[root<<1]+=x;
ly[root<<1]+=x;
tr[root<<1|1]+=x;
ly[root<<1|1]+=x;
ly[root]=0;
}
}
void build(int root,int l,int r){
if(l==r){
tr[root]=-tmp[l];
return ;
}
int midd=(l+r)>>1;
build(lson);
build(rson);
up(root);
}
void update(int L,int R,ll c,int root,int l,int r){
if(L<=l&&r<=R){
tr[root]+=c;
ly[root]+=c;
return ;
}
pushdown(root,l,r);
int midd=(l+r)>>1;
if(L<=midd)
update(L,R,c,lson);
if(R>midd)
update(L,R,c,rson);
up(root);
}
ll query(int L,int R,int root,int l,int r){
if(L<=l&&r<=R){
return tr[root];
}
if(ly[root])
pushdown(root,l,r);
int midd=(l+r)>>1;
ll res=-INF;
if(L<=midd)
res=query(L,R,lson);
if(R>midd)
res=max(res,query(L,R,rson));
up(root);
return res;
}
int main(){
int n,m,p;
scanf("%d%d%d",&n,&m,&p);
ll minn1=INF,minn2=INF;
for(int i=1;i<=n;i++)
scanf("%lld%lld",&a[i].val,&a[i].cost),minn1=min(minn1,a[i].cost);
for(int i=1;i<=m;i++)
scanf("%lld%lld",&b[i].val,&b[i].cost),minn2=min(minn2,b[i].cost);
ll ans=-minn1-minn2;///因为题目说必须要选盾和剑,所以不考虑消灭了怪兽就直接减去最小的;
sort(a+1,a+1+n);
sort(b+1,b+1+m);
for(int i=1;i<=n;i++)
all[i]=a[i].val;
// all[n+1]=INF;
///求i~n的剑消耗的最小值
suf[n+1]=INF;
for(int i=n;i>=1;i--)
suf[i]=min(a[i].cost,suf[i+1]);
///初始化线段树,最优的贡献肯定是若干个价值为i的b的cost的最小的负数
for(int i=0;i<=M;i++)
tmp[i]=INF;
for(int i=1;i<=m;i++)
tmp[b[i].val]=min(tmp[b[i].val],b[i].cost);
build(1,1,M-1);
for(int i=1;i<=p;i++)
scanf("%lld%lld%lld",&c[i].vala,&c[i].valb,&c[i].cost);
sort(c+1,c+1+p);
for(int i=1;i<=p;i++){
// cout<<ans<<endl;
update(c[i].valb+1,M-1,c[i].cost,1,1,M-1);
ll res1=query(c[i].valb+1,M-1,1,1,M-1);///盾和怪兽对答案的贡献
// cout<<res1<<endl;
int pos=upper_bound(all+1,all+1+n,c[i].vala)-all;
ll res2=suf[pos];///当前情况下选择的最优的剑的消耗
ans=max(ans,res1-res2);
}
printf("%lld\n",ans);
return 0;
}
contest/1321/problem/E

Codeforces Round #625 Div. 2 D E的更多相关文章

  1. Codeforces Round #625 (Div. 2)

    Contest Info Practice Link Solved A B C D E F 4/6 O O Ø  Ø     O 在比赛中通过 Ø 赛后通过 ! 尝试了但是失败了 - 没有尝试 Sol ...

  2. Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) D. Navigation System(有向图,BFS,最短路)

    题意: n 点 m 边有向图,给出行走路径,求行走途中到路径终点最短路变化次数的最小值和最大值 . 思路 : 逆向广搜,正向模拟. #include <bits/stdc++.h> usi ...

  3. Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) C. Remove Adjacent(字符串,贪心,枚举)

    题意: 给你一个由小写字母组成的字符串,若串中两个相邻元素字典序中也相邻,移除较大字母,问最多能移除多少个字母. 思路: 从大到小依次枚举. Tips: 注意下标的处理. 以小消大: #include ...

  4. Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) B. Journey Planning(映射)

    题意: 已知 n 所城市(从 1 至 n 编号)及其美丽值,选取一条旅行路线,满足路线中两两城市美丽值之差等于编号之差,求所有旅行路线中美丽值的最大值. 思路: 美丽值与编号作差,差值为键,映射累加 ...

  5. Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round) A. Contest for Robots(数学)

    题意: n 道题,2 个答题者,已知二者的做题情况,你是受贿裁判,可以给每题指定分值(≥1),求甲乙分数(甲>乙)相差最小时最大分值的最小值. 思路: 统计只有甲或乙做出的题目数. 加一取下整判 ...

  6. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  7. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  8. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  9. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. UML软件工程复习——用例图和类图

    ------------恢复内容开始------------ 软件产品开发流程是需求.分析.设计.实现. 面向对象三大特征:继承性,封装性.多态性 模型将软件生命周期划分为软件计划.需求分析和定义.软 ...

  2. VRP CommandLines

    <> 用户视图 通过 system-view 进入系统视图 [] 系统视图 通过interface 0/0/0 进入接口视图 CTRL+Z 返回用户视图 CTRL+A 把光标移动到当前命令 ...

  3. k8s之RBAC授权模式

    导读 上一篇说了k8s的授权管理,这一篇就来详细看一下RBAC授权模式的使用 RBAC授权模式 基于角色的访问控制,启用此模式,需要在API Server的启动参数上添加如下配置,(k8s默然采用此授 ...

  4. Spring Boot Security 国际化 多语言 i18n 趟过巨坑

    网上很多的spring boot国际化的文章都是正常情况下的使用方法 如果你像我一样用了Spring Security 那么在多语言的时候可能就会遇到一个深渊 Spring Security里面的异常 ...

  5. spring boot gateway 过滤器的执行顺序

    前言 学习官方文档,发现对于过滤器有分为三类 默认过滤器 自定义过滤 全局过滤器 于是就有一个疑问,关于这些过滤器的访问顺序是怎样的,今天就以一个demo来进行测试 准备阶段 过滤器工厂类 以此为模板 ...

  6. 【Problems】Could not set property 'id' of 'xxx' with value '' Cause argument type mismatch

    一个问题:向comment表添加记录时,报错, 无法设置值. reflection.ReflectionException: Could not set property 'id' of 'class ...

  7. 2021升级版微服务教程7-OpenFeign实战开发和参数调优

    2021升级版SpringCloud教程从入门到实战精通「H版&alibaba&链路追踪&日志&事务&锁」 教程全目录「含视频」:https://gitee.c ...

  8. 【Oracle】更改oracle中的用户名称

    修改oracle中的用户名,要需要修改oracle基表中的相关内容, 1.查看user#, select user#,name from user$ s where s.name='用户修改前的'; ...

  9. ctfhub技能树—文件上传—文件头检查

    打开靶机 尝试上传一个php文件 抓包修改 放包 制作图片马 上传图片马,并修改文件类型为png 测试连接 查找flag 成功拿到flag

  10. 分布式系统:xxl-job改造spring-cloud

    目录 改造原因 主要改造思路 调度中心 调度中心 执行器侧 总结 修改后的源码仓库地址:GitHub. : 改造原因 原有的xxl-job使用自己实现的http协议进行注册以及调度等,与目前框架中本身 ...