CEOI 2021
CEOI 2021
\(pts\):64 + 0 + 4
\(T1 : 64pts\)
首先我们肯定知道对于相同的数,一定是放在一起才是最优的,随意我们对于每段查询的区间要保证有序,然后我们发现,每个数出现的位置不同,他对答案的贡献也就不同,我们的想法是让答案最小,那么我们对于每个位置对答案的贡献一定要均摊,所以我们考虑错位排开,其实也可以打表找规律(到 \(6\) 就行了)。然后对于所有 \(q = 1\) 的就可以做出来了
点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int M = 3e5 + 7;
int a[M] , vis[M] , b[M] , t , size;
struct Query{int l , r , id;} Q[M];
bool cmp(Query a , Query b) {
return belong[a.l] == belong[b.l] ? a.r < b.r : belong[a.l] < belong[b.l];
}
signed main () {
// freopen("data.in","r",stdin);
// freopen("data.ans","w",stdout);
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n , q; cin >> n >> q;
for(int i = 1; i <= n; ++ i) cin >> a[i];
if(q == 1) {
int l , r; cin >> l >> r;
sort(a + l , a + r + 1);
int ans = 0 , cnt = 0 , sum = 0;
for(int i = l; i <= r; ++ i) {if(!vis[a[i]]) cnt ++ ;vis[a[i]] ++; sum += cnt;}
sort(vis + 1 , vis + 300000 + 1 , greater<int>());
int L = l , R = r , tot = 0;
for(int i = cnt; i >= 1; -- i) {
tot ++;
if(tot & 1)while(vis[i]) a[L] = i , vis[i] -- , L ++;
else while(vis[i]) a[R] = i , vis[i] -- , R --;
}
memset(vis , 0 , sizeof vis);
cnt = 0 , sum = 0;
for(int i = l; i <= r; ++ i) {if(!vis[a[i]]) cnt ++ ;vis[a[i]] ++; sum += cnt;}
for(int i = l; i <= r; ++ i) {
ans += sum;
vis[a[i]] --;
if(! vis[a[i]]) sum -= r - i + 1;
else sum --;
}
return cout << ans << '\n' , 0;
}
}
\(T2 : 0pts\)
\(T2\) 直接爆零了,一点思路都没有
\(T3\) : \(4pts\)
我们首先对于链的情况进行分析,我们可以知道在一条链上的话,一定是有解的,那么考虑如何让答案最优,我们发现如果我们遍历两边这条链的话,那么一定是能找到 \(Branko\) 的,但是这样是最优的嘛,我们发现,链两端的对答案没有影响,所以可以直接排除掉,故为链的答案为 \((n - 2) * 2\)。那么在考虑一般情况,那么也就是在链上多几条支链,和环。我们先来考虑环的情况,如果说这个图中有环的话,那么是一定不能找到 \(Branko\) 的。那么最后再来考虑支链的情况,因为我们知道一个长度为 \(2\) 的链是一定能找到的,那么对于长度为 \(3\) 及以上的呢。那么我们发现如果说一条支链大于 \(2\) 了,那么 \(Ankica\) 就没办法继续往下猜了, 因为这样\(Branko\) 可能就会跑到别的支链,就造成了无解,所以只要找到树的直径,再找支链即可。
点击查看代码
#include<bits/stdc++.h>
#define int long long
#define pb push_back
using namespace std;
const int M = 1e3 + 7;
int f[M] , id[M] , vis[M] , dep[M] , Max , pos;
vector<int> e[M] , a[M];
void dfs(int x , int fa , int sum) {
if(Max < sum) Max = sum , pos = x;
f[x] = fa;
for(auto i : e[x]) {
if(i == fa) continue;
dfs(i , x , sum + 1);
}
}
void dfs_1(int x , int fa) {
dep[x] = 1;
for(auto i : e[x]) {
if(i == fa) continue;
dfs_1(i , x);
dep[x] = dep[i] + 1;
}
}
signed main () {
ios::sync_with_stdio(0),cin.tie(0);
int n , m; cin >> n >> m;
if(n == 1) return cout << "YES" << '\n' << 1 << '\n' << 1 << '\n' , 0;
if(n == 2) return cout << "YES" << '\n' << 2 << '\n' << "1 1" << '\n' , 0;
for(int i = 1; i <= m; ++ i) {
int u ,v; cin >> u >> v;
e[u].pb(v) , e[v].pb(u);
}
if(m >= n) return cout << "NO" << '\n' , 0;
int pos1;
dfs(1 , 0 , 0) , memset(f , 0 , sizeof f) , Max = 0 , pos1 = pos, dfs(pos , 0 , 0);
int cnt = 0;
for(int i = pos; i ; i = f[i]) {
id[++ cnt] = i; vis[i] = 1;
}
for(int i = 1; i <= n; ++ i) {
if(! vis[i] && vis[f[i]]) {
dfs_1(i , f[i]);
if(dep[i] >= 3) return cout << "NO" << '\n' , 0;
if(dep[i] > 1) a[f[i]].pb(i);
}
}
cout << "YES" << '\n';
vector<int> ans;
for(int i = 2; i < cnt; ++ i) {
ans.pb(id[i]);
for(auto j : a[id[i]]) {
ans.pb(j); ans.pb(id[i]);
}
}
for(int i = cnt - 1; i > 1; -- i) {
ans.pb(id[i]);
for(auto j : a[id[i]]) {
ans.pb(j);ans.pb(id[i]);
}
}
cout << ans.size() << '\n';
for(auto i : ans) cout << i << ' ';
return 0;
}
CEOI 2021的更多相关文章
- codevs 2021 中庸之道
2021 中庸之道 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 给定一个长度为N的序列,有Q次询问,每次 ...
- Bzoj 1982: [Spoj 2021]Moving Pebbles 博弈论
1982: [Spoj 2021]Moving Pebbles Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 130 Solved: 88[Submi ...
- poj 2021 Relative Relatives(暴力)
题目链接:http://poj.org/problem?id=2021 思路分析:由于数据较小,采用O(N^2)的暴力算法,算出所有后代的年龄,再排序输出. 代码分析: #include <io ...
- iPhone屏蔽IOS更新、iPhone系统更新的提示(免越狱,有效期更新至2021年)
iPhone屏蔽IOS更新.iPhone系统更新的提示(免越狱,有效期更新至2021年) 1.在Safari浏览器中粘贴如下链接,按提示打开链接. 输入http://apt.dataage.pub 2 ...
- HDU 2021 发工资咯:)
http://acm.hdu.edu.cn/showproblem.php?pid=2021 Problem Description 作为杭电的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的 ...
- Math.abs(~2020) 按位取反后的绝对值是多少 2021, 按位取反后,比正数多1
Math.abs(~2020) 按位取反后的绝对值是多少 2021, 按位取反后,比正数多1 int 值的取值 范围: -128 --- 127 之间, 0000 0000 按位取 ...
- 部分PR回写的数量带有小数,分别是2023工厂的纸箱104007000389,2021工厂的纸盒404002005930;
描述:部分PR回写的数量带有小数,分别是2023工厂的纸箱104007000389,2021工厂的纸盒404002005930: 原因:所有物料规划PR时对舍入值的先后考虑逻辑影响到回写出来的temp ...
- codves 2021中庸之道
2021 中庸之道 http://codevs.cn/problem/2021/ 题目描述 Description 给定一个长度为N的序列,有Q次询问,每次询问区间[L,R]的中位数. 数据保证序列中 ...
- HDU 2021 发工资咯:)(最水贪心)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2021 发工资咯:) Time Limit: 2000/1000 MS (Java/Others) ...
- 【BZOJ】2021: [Usaco2010 Jan]Cheese Towers(dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=2021 噗,自己太弱想不到. 原来是2次背包. 由于只要有一个大于k的高度的,而且这个必须放在最顶,那 ...
随机推荐
- 【驱动 】frambuffer中显示屏参数的修改
1.在x210板子的kernel中,默认LCD显示屏是800*400的,修改在 kernel/arch/arm/mach-s5pv210/mach-x210.c 中 258行 #define S5PV ...
- CCF-CSP准备
dfs序,unique vector sort(que+1,que+1+cnt); len = unique(que+1,que+cnt+1)-que-1; for(int i = 1;i <= ...
- Django操作mongo数据库二(MongoClient方式)
一.基本环境 1.开发环境: Python环境:Python 3.8.16 Django环境:4.1 2.需要安装的包 pip install pymongo pip install mongoeng ...
- 如何用python脚本采集某网图片
一.前言: 今天学了两个工具urlopen 和etree,这两个小工具至关重要.urllib.request模块提供了最基本的构造HTTP请求的方法,利用它可以模拟浏览器的一个请求发起过程,同时它还 ...
- 【二】python学习总结
一i.python概念 python是一种解释型语言,速度比java慢 二.运算符和格式输出.导入 1.Python3 运算符 | 菜鸟教程 (runoob.com) 2.格式输出 % 和.form ...
- cAPP.h头文件
前言 最近几天闲的没事,写了一个可以用来写简单的app程序的头文件,分享给大家! 头文库 #ifndef CAPP_H #define CAPP_H #include<bits/stdc++.h ...
- window向linux传递文件
1.需要在window建一个ftp的server 2.在linux的指定目录下输入: curl ftp://192.168.98.90/libalgorithm.so -u "embftp: ...
- 【OBS Studio】使用 VLC 视频源播放视频报错:Unhandled exception: c0000005
使用 OBS Studio 和 VLC media player 可以实现视频播放列表的推流,参考『OBS如何添加播放列表?』. 但是使用过程中发现使用 VLC 视频源播放视频时,一个视频播放完切换下 ...
- gl-ar750 配置
镜像下载https://docs.gl-inet.com/en/3/release_notes/gl-ar750/设置sd卡安装软件https://openwrt.org/docs/guide-use ...
- mybatis-关联查询1-一对多关联查询
或者多表单独查询方式