cf div2 round 688 题解
爆零了,自闭了
小张做项目入职字节
小李ak wf入职ms
我比赛爆零月薪3k
我们都有光明的前途
好吧,这场感觉有一点难了,昨天差点卡死在B上,要不受O爷出手相救我就boom zero了
第一题,看上去很唬人,我觉得还得记录变量什么的,1分钟后发现只要查出两个集合的交集大小就行了,连变量增量都不用,拿一血,此时rk 1k6,我人没了
#include <bits/stdc++.h>
using namespace std;
#define limit (315000 + 5)//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-6
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a,b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\dabiao.txt", "wt", stdout)
#define debug(x) cout<<x<<endl
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){
ll sign = 1, x = 0;char s = getchar();
while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();}
while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();}
return x * sign;
}//快读
void write(ll x){
if(x < 0) putchar('-'),x = -x;
if(x / 10) write(x / 10);
putchar(x % 10 + '0');
}
int kase;
int n,m,k;
int a[limit];
void solve(){
cin>>n>>m;
set<int>s;
rep(i,1,n){
int x;
cin>>x;
s.insert(x);
}
int tot = 0;
rep(i,1,m){
int x;
cin>>x;
if(s.find(x) != s.end())++tot;
}
cout<<tot<<endl;
}
int main() {
#ifdef LOCAL
FOPEN;
#endif
cin>>kase;
while (kase--){
solve();
}
return 0;
}
B题看上去么得啥思路,后来O神说是记录两边的插值,然后每次记录当前这全都设置成某一位的最小值就行,dbq我现在也没怎么搞懂这个怎么搞,于是滚去看C
#include <bits/stdc++.h>
using namespace std;
#define limit (3150000 + 5)//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-6
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a,b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\dabiao.txt", "wt", stdout)
#define debug(x) cout<<x<<endl
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){
ll sign = 1, x = 0;char s = getchar();
while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();}
while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();}
return x * sign;
}//快读
void write(ll x){
if(x < 0) putchar('-'),x = -x;
if(x / 10) write(x / 10);
putchar(x % 10 + '0');
}
int kase;
int n,m,k;
ll a[limit];
ll dp2[limit],dp[limit];
void solve(){
cin>>n;
ll tot = 0,ans = 0x3f3f3f3f3f3f3f;
rep(i,1,n){
cin>>a[i];
dp[i] = 0;
dp2[i] = 0;
}
dp2[1] = max(dp2[1],llabs(a[2] - a[1]));
rep(i,2,n){
ll tmp = llabs(a[i] - a[i - 1]);
tot += tmp;
dp[i] = tmp;
}
rep(i,1,n){
if(i == 1){
ans = min(ans , tot - dp[2]);
}else if(i == n){
ans = min(ans,tot - dp[n]);
}
else if((a[i] <= a[i + 1] && a[i] <= a[i - 1])){
ans = min(ans,tot + abs(a[i - 1] - a[i + 1]) - dp[i + 1 ] - dp[i]);
}else if(a[i] >= a[i + 1] && a[i] >= a[i - 1]){
ans = min(ans,tot + abs(a[i + 1] - a[i - 1]) - dp[i + 1] - dp[i]);
}
}
cout<<ans<<endl;
}
int main() {
#ifdef LOCAL
FOPEN;
#endif
cin>>kase;
while (kase--){
solve();
}
return 0;
}
C题一看就很阅读理解,先是花半个小时看题,之后大概清楚了什么意思,大概是一个0-9构成的棋盘,每次找最大的又i(i = 0 - 9)三角形构成的平行四边形面积,其中一边必须平行于坐标轴,每次可以在棋盘上改变不超过一个不影响后续的元素,求以0-9各个为顶点的最大面积
首先显然想到,三角形面积 = 底 X 高 / 2,不用/2了,好耶。大概思路就是预处理一下左右,上下两个维度的第一个元素每一行或者每一列最靠边缘的元素位置,然后枚举看每一行,对于0-9,存在以下几种对答案产生贡献的情况
1. 这行有至少两个数字i,以最边上两个元素为底寻找一个与其垂直的维度的点,或者1,n这两个端点,构成的三角形比原先大
2. 这行存在一个数字,但用次行/列第一个或者最后一个元素改变为顶点数字作为底,构成的三角形比原先大
3. 这行的情况与1相同,不添加任何数字,不做改动,构成的三角形就比原先大
然后我赛场写了100+行大模拟,好在过了,写完一身冷汗,代码如下:
#include <bits/stdc++.h>
using namespace std;
#define limit (3150000 + 5)//防止溢出
#define INF 0x3f3f3f3f
#define inf 0x3f3f3f3f3f
#define lowbit(i) i&(-i)//一步两步
#define EPS 1e-6
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ff(a) printf("%d\n",a );
#define pi(a,b) pair<a,b>
#define rep(i, a, b) for(ll i = a; i <= b ; ++i)
#define per(i, a, b) for(ll i = b ; i >= a ; --i)
#define MOD 998244353
#define traverse(u) for(int i = head[u]; ~i ; i = edge[i].next)
#define FOPEN freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\data.txt", "rt", stdin)
#define FOUT freopen("C:\\Users\\tiany\\CLionProjects\\acm_01\\dabiao.txt", "wt", stdout)
#define debug(x) cout<<x<<endl
typedef long long ll;
typedef unsigned long long ull;
inline ll read(){
ll sign = 1, x = 0;char s = getchar();
while(s > '9' || s < '0' ){if(s == '-')sign = -1;s = getchar();}
while(s >= '0' && s <= '9'){x = (x << 3) + (x << 1) + s - '0';s = getchar();}
return x * sign;
}//快读
void write(ll x){
if(x < 0) putchar('-'),x = -x;
if(x / 10) write(x / 10);
putchar(x % 10 + '0');
}
int kase;
int n,m,k;
ll a[limit];
ll dp2[limit],dp[limit];
void solve(){
cin>>n;
ll tot = 0,ans = 0x3f3f3f3f3f3f3f;
rep(i,1,n){
cin>>a[i];
dp[i] = 0;
dp2[i] = 0;
}
dp2[1] = max(dp2[1],llabs(a[2] - a[1]));
rep(i,2,n){
ll tmp = llabs(a[i] - a[i - 1]);
tot += tmp;
dp[i] = tmp;
}
rep(i,1,n){
if(i == 1){
ans = min(ans , tot - dp[2]);
}else if(i == n){
ans = min(ans,tot - dp[n]);
}
else if((a[i] <= a[i + 1] && a[i] <= a[i - 1])){
ans = min(ans,tot + abs(a[i - 1] - a[i + 1]) - dp[i + 1 ] - dp[i]);
}else if(a[i] >= a[i + 1] && a[i] >= a[i - 1]){
ans = min(ans,tot + abs(a[i + 1] - a[i - 1]) - dp[i + 1] - dp[i]);
}
}
cout<<ans<<endl;
}
int main() {
#ifdef LOCAL
FOPEN;
#endif
cin>>kase;
while (kase--){
solve();
}
return 0;
}
D题没时间搞了,但后来和Dxtst老哥讨论了下似乎是当前位上0或1,如果是1对于答案的贡献为2^k, 其他结论今晚再搞
奥里给!
cf div2 round 688 题解的更多相关文章
- [题解向] CF#Global Round 1の题解(A $\to$ G)
这里是总链接\(Link\). \(A\) 题意:求\(\sum_{i=1}^{k} a_i\times b^{k-i}\)的奇偶性, \(k = \Theta(n \log n)\) --其实很容易 ...
- CF Global Round 21 题解 (CDEG)
C 把 \(a,b\) 全拆开然后比较即可(因为分裂和合并是互逆的) 注意开 long long . using namespace std; typedef long long ll; typede ...
- CF Educational Round 78 (Div2)题解报告A~E
CF Educational Round 78 (Div2)题解报告A~E A:Two Rival Students 依题意模拟即可 #include<bits/stdc++.h> us ...
- CFEducational Codeforces Round 66题解报告
CFEducational Codeforces Round 66题解报告 感觉丧失了唯一一次能在CF上超过wqy的机会QAQ A 不管 B 不能直接累计乘法打\(tag\),要直接跳 C 考虑二分第 ...
- Codeforces Round #556 题解
Codeforces Round #556 题解 Div.2 A Stock Arbitraging 傻逼题 Div.2 B Tiling Challenge 傻逼题 Div.1 A Prefix S ...
- LibreOJ β Round #2 题解
LibreOJ β Round #2 题解 模拟只会猜题意 题目: 给定一个长为 \(n\) 的序列,有 \(m\) 次询问,每次问所有长度大于 \(x\) 的区间的元素和的最大值. \(1 \leq ...
- Codeforces Round #569 题解
Codeforces Round #569 题解 CF1179A Valeriy and Deque 有一个双端队列,每次取队首两个值,将较小值移动到队尾,较大值位置不变.多组询问求第\(m\)次操作 ...
- Codeforces Round #557 题解【更完了】
Codeforces Round #557 题解 掉分快乐 CF1161A Hide and Seek Alice和Bob在玩捉♂迷♂藏,有\(n\)个格子,Bob会检查\(k\)次,第\(i\)次检 ...
- CF Edu Round 71
CF Edu Round 71 A There Are Two Types Of Burgers 贪心随便模拟一下 #include<iostream> #include<algor ...
随机推荐
- 11/6笔记 补充(Redis持久化,RDB&&AOF)
11/6补充笔记 修改redis-6379.conf里面的save10秒2个数据发生改变 (save 10 2) 修改一次数据不发生改变,修改2次数据才发生改变 继续修改数据,发现还是一样的规律 增删 ...
- Python Tkinter小实例——模拟掷骰子
什么是Tkinter? Tkinter 是 Python 的标准 GUI 库.Python 使用 Tkinter 可以快速的创建 GUI 应用程序. 由于 Tkinter 是内置到 python 的安 ...
- SPA 路由三部曲之核心原理
为了配合单页面 Web 应用快速发展的节奏,近几年,各类前端组件化技术栈层出不穷.通过不断的版本迭代 React.Vue 脱颖而出,成为当下最受欢迎的两大技术栈. 仅 7 个月的时间,两个技术栈的下载 ...
- 手把手教你使用Vuex(三)
2.mutation属性 了解: mutation是更改Vuex的store中的状态的唯一方法.非常类似于事件,官网说的"每个mutation都有一个字符串的事件类型和一个回调函数" ...
- MySql Binlog 说明 & Canal 集成MySql的更新异常说明 & MySql Binlog 常用命令汇总
文章来源于本人的印象笔记,如出现格式问题可访问该链接查看原文 原创声明:作者:Arnold.zhao 博客园地址:https://www.cnblogs.com/zh94 目录 背景介绍 开启MySq ...
- Spring源码之循环依赖
https://www.cnblogs.com/longy2012/articles/12834762.html https://www.bilibili.com/video/BV1iD4y1o7pM ...
- linux帮助手册(help/man/info)
linux本身有数据库(数据库名whatis)--man实际是从whatis数据库里查找信息. makewhatis 刚装系统,若man不能用,用makewhatis命令.整理whatis数据库. 当 ...
- 转载 数据库优化 - SQL优化
判断问题SQL判断SQL是否有问题时可以通过两个表象进行判断: 系统级别表象CPU消耗严重IO等待严重页面响应时间过长应用的日志出现超时等错误可以使用sar命令,top命令查看当前系统状态. 也可以通 ...
- 测试_QTP使用实例
1. QTP简介 1.1QTP功能与特点 QTP是QuickTest Professional的简称,是一种自动化软件测试工具.在软件的测试过程中,QTP主要来用来通过已有的测试脚本执行重复的手动测试 ...
- python的pip快速安装代码
pip install xx,经常由于网速,或者安装版本问题导致安装速度慢超时等问题, 现提供一个py镜像安装代码,安装库文件前执行下这个程序,可以很快下载 cmd 进入命令提示符 python .p ...