E:

题意:

给出n个整数ai和m个区间[li,ri] 你可以选择一些区间,并且将区间内的数字都减一。你要选择一些区间,然后使得改变后的数列中maxbi-minbi的值最大。

题解:

假设我们已经知道了这n个数中最大值的位置pmax,和最小值的位置pmin,那么对于一个区间[li,ri],有三种情况。

1.如果pmax和pmin在区间[li,ri]内,那么这个区间加不加都对答案没有贡献。

2.如果pmin在区间内pmax不在区间内,那么这个区间加上对答案的贡献就为1

3.如果pmax在区间内pmin不在区间内,那么加上这个区间对答案的贡献为-1.

所以我们发现,只要pmin在区间内的区间,选上它答案一定不会变的更差。

那么n*m的复杂度就可以解决这个问题了,将区间按照左区间排序,从1到n扫,当前i为某个区间的开始或者结束点的时候,更新和消除影响。

F:

题意:

给出n个点和m条边,没有重边和自环。问你最少要给多少条边的权值+1使得MST不变且唯一。

题解:

我们定义一下冲突边:存在一些边,权值都是当前都小的,且只能从这里面选一条边加入MST,即,原本他们都能加入MST,但是加入一条以后剩余的都没法加入MST了。

对于所有的冲突边,选一条加入MST,然后其他边的权值都要+1.

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream> using namespace std;
const int maxn=2e5+;
struct Edge{
int from,to,w;
bool operator<(const Edge& rhs)const{
return w<rhs.w;
}
}edges[maxn];
int n,m;
int p[maxn];
int find(int x){
return p[x]==x?x:p[x]=find(p[x]);
} int main(){
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)p[i]=i;
for(int i=;i<=m;i++)
scanf("%d%d%d",&edges[i].from,&edges[i].to,&edges[i].w);
sort(edges+,edges++m);
int ans=;
for(int i=;i<=m;){
int j=i;
while(edges[j].w==edges[i].w){
j++;
}
j--;
int num=;
for(int k=i;k<=j;k++){
int x=find(edges[k].from);
int y=find(edges[k].to);
if(x!=y)
num++;
}
for(int k=i;k<=j;k++){
int x=find(edges[k].from);
int y=find(edges[k].to);
if(x!=y){
p[x]=y;
num--;
}
}
ans+=num;
i=j+;
}
printf("%d\n",ans);
return ;
}

Codeforces Round #535 (Div. 3)的更多相关文章

  1. Codeforces Round #535 (Div. 3) 题解

    Codeforces Round #535 (Div. 3) 题目总链接:https://codeforces.com/contest/1108 太懒了啊~好久之前的我现在才更新,赶紧补上吧,不能漏掉 ...

  2. Codeforces Round #535 (Div. 3) E2. Array and Segments (Hard version) 【区间更新 线段树】

    传送门:http://codeforces.com/contest/1108/problem/E2 E2. Array and Segments (Hard version) time limit p ...

  3. Codeforces Round #535 (Div. 3) [codeforces div3 难度测评]

    hhhh感觉我真的太久没有接触过OI了 大约是前天听到JK他们约着一起刷codeforces,假期里觉得有些颓废的我忽然也心血来潮来看看题目 今天看codeforces才知道居然有div3了,感觉应该 ...

  4. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  5. D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心

    D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  6. Codeforces Round #535 (Div. 3) 解题报告

    CF1108A. Two distinct points 做法:模拟 如果两者左端点重合就第二条的左端点++就好,然后输出左端点 #include <bits/stdc++.h> usin ...

  7. Codeforces Round #535 (Div. 3) 1108C - Nice Garland

    #include <bits/stdc++.h> using namespace std; int main() { #ifdef _DEBUG freopen("input.t ...

  8. Codeforces Round #535(div 3) 简要题解

    Problem A. Two distinct points [题解] 显然 , 当l1不等于r2时 , (l1 , r2)是一组解 否则 , (l1 , l2)是一组合法的解 时间复杂度 : O(1 ...

  9. Codeforces Round #535 (Div. 3) F

    F. MST Unification 题目传送门 题意: 给你n个顶点,m条边:保证没有重边,其中存在多个MST(最小生成树), 你可以修改一些边的权值,让其中有且仅有一个最小生成树,求最少操作的边数 ...

随机推荐

  1. [转]关于vs2005、vs2008和vs2010项目互转的总结

    关于vs2005.vs2008和vs2010项目互转的总结 分类: Asp.Net2010-11-16 16:59 18239人阅读 评论(12) 收藏 举报 2010.net框架编译器 有做.net ...

  2. 致Python初学者:Anaconda入门使用指南

    http://python.jobbole.com/87522/ Anaconda使用总结 pasting

  3. python 使用selenium和requests爬取页面数据

    目的:获取某网站某用户下市场大于1000秒的视频信息 1.本想通过接口获得结果,但是使用post发送信息到接口,提示服务端错误. 2.通过requests获取页面结果,使用html解析工具,发现麻烦而 ...

  4. 从jar包还原出java源码(项目文件)

    原文转载至:https://blog.csdn.net/mxmxz/article/details/73043156 上周接到个新任务,一个遗留的接口工程需要改造,然而根据前任开发留下的文档看,这个工 ...

  5. 朴素贝叶斯-对数似然Python实现-Numpy

    <Machine Learning in Action> 为防止连续乘法时每个乘数过小,而导致的下溢出(太多很小的数相乘结果为0,或者不能正确分类) 训练: def trainNB0(tr ...

  6. IO流程及优化

    http://blog.csdn.net/xypzwl/article/details/51416883 一.存储设备的存储原理 机械硬盘: 机械硬盘使用磁性物质作为存储介质,用N.S极性来代表0或1 ...

  7. XPath 常用语法札记

    * 不包含属性的元素 例如不包含属性的span: span[not(@*)] * 文本包含某部分的元素 例如文本包含Rank的元素: *[contains(text(),'Rank')] * 选择匹配 ...

  8. InterlliJ IDEA 2017.3.x / 2017.3.4 License Server激活

    InterlliJ IDEA 2017.3.x / 2017.3.4 License Server激活 1.Lincense Server激活 // 激活IDEA的License Server 地址 ...

  9. 建造者模式(Builder)

    Separate the construction of a complex object form its representation so that the same construction ...

  10. 0_Simple__vectorAdd + 0_Simple__vectorAdd_nvrtc + 0_Simple__vectorAddDrv

    ▶ 使用 CUDA Runtime API,运行时编译,Driver API 三种接口计算向量加法 ▶ 源代码,CUDA Runtime API #include <stdio.h> #i ...