题解:
我们可以得知,人可以往左边推箱子或者往右边推。
所以我们可以把所有负数放在一起,所有正数放在一起,也就是左边一堆,右边一堆。

然后开始枚举每一个special positions,假设这个点之前的所有箱子都被推到了这个点和这个点之前连续的几个点,然后查询这一段长度覆盖了几个special positions(用二分查找即可),然后再看看这个点之后,是否有箱子就在special positions上,这两个值加起来,取最大的即可。

这里我是用了multiset来水了一下二分,相同操作也可以二分来操作。

代码:

/*Keep on going Never give up*/
//#pragma GCC optimize(2)
#include<bits/stdc++.h>
//#include<iostream>
//#include<string>
//#include<cmath>
//#include<vector>
//#include<algorithm>
//#include<queue>
//#include<string.h>#define int long long
#define endl '\n'using namespace std;
const int maxn=2e5+10;
const int mo=1000;//int a[maxn],b[maxn];int last[maxn];
int sol(multiset<int> a,vector<int>b){int n=b.size();last[n+1]=last[n]=0;for(int i=n-1;i>=0;i--){if(a.count(b[i])) last[i]=last[i+1]+1;else last[i]=last[i+1];}int res=last[0];multiset<int>::iterator it=a.begin();int len=0;for(int i=0;i<n;i++){while(*it<=b[i]&&it!=a.end()){it++;len++;}if(len==0) continue;int val=b[i]-len+1;int pos=lower_bound(b.begin(),b.end(),val)-b.begin();int qian=i-pos+1;int now=qian+last[i];if(a.count(b[i])) now--;res=max(res,now);}return res;
}
signed main(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int t;cin>>t;while(t--){int n,m;cin>>n>>m;vector<int> y,b;multiset<int> x,a;for(int i=0;i<n;i++){int z;cin>>z;if(z<0) x.insert(-z);else a.insert(z);}for(int i=0;i<m;i++){int z;cin>>z;if(z<0) y.push_back(-z);else b.push_back(z);}reverse(y.begin(),y.end());int ans=0;ans+=sol(x,y);ans+=sol(a,b);cout<<ans<<endl;}}

Educational Codeforces Round 105 (Rated for Div. 2) C. 1D Sokoban相关推荐

  1. Educational Codeforces Round 105 (Rated for Div. 2) 题解

    Educational Codeforces Round 105 (Rated for Div. 2) A. ABC String 枚举ABC分别为"( "和 " )&q ...

  2. Educational Codeforces Round 105 (Rated for Div. 2) A-D题解

    A. ABC String 题意 给你一个只包含 A.B.C的字符串,每类字符都有可能代表左右括号中的一种,问你是否能找到一个方式使得括号匹配合法 三个字符,每个字符有两种情况 总计 2^3 = 8次 ...

  3. Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...

  4. Educational Codeforces Round 61 (Rated for Div. 2)(A、B、C、D、E、F)

    欢迎访问本菜鸡的独立博客:Codecho 比赛名称 Educational Codeforces Round 61 (Rated for Div. 2) 比赛链接 https://codeforces ...

  5. Educational Codeforces Round 117 (Rated for Div. 2)题解(A~D)

    Educational Codeforces Round 117 (Rated for Div. 2) 今天这场没打,赛后从九点半到十一点把前面四个题目给补了一下,E题明天有时间看看能不能弄出来. A ...

  6. Educational Codeforces Round 98 (Rated for Div. 2) D. Radio Towers

    Educational Codeforces Round 98 (Rated for Div. 2) D. Radio Towers 题目链接 There are n+2 towns located ...

  7. Educational Codeforces Round 133 (Rated for Div. 2)(CD题解)

    Educational Codeforces Round 133 (Rated for Div. 2)CD题解 过AB补CD C. Robot in a Hallway 题意 题意:现有 2∗m 的方 ...

  8. Educational Codeforces Round 100 (Rated for Div. 2)

    文章目录 Educational Codeforces Round 100 (Rated for Div. 2) A. Dungeon B. Find The Array C. Busy Robot ...

  9. Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...

最新文章

  1. WMI Series :事件预订和处理
  2. 【深度学习】——常见深度学习模型总结、anchor-free和anchor-based
  3. SingnalR 开发到生产部署闭坑指南
  4. 【转】GitHub上README.md教程
  5. 从文本分类问题中的特征词选择算法追踪如何将数学知识,数学理论迁移到实际工程中去...
  6. Tomcat Post请求参数长度限制
  7. Remoting疑惑续集之再续
  8. mysql int 转 varchar_Java后端程序员必备:MySQL索引失效的十大杂症
  9. mysql install语句_MySQL入门学习(一)安装与基本操作
  10. python webkit内核_GitHub - yufengsoft/wke: 基于Webkit精简的纯C接口的浏览器内核,可用于桌面UI、浏览器。...
  11. 嵌入式linux交叉开发环境,构建嵌入式Linux交叉开发环境
  12. 通达OA2017恢复数据库Access denied for user 'root'@'localhost' (using password: YES)报错的解决办法
  13. java 验证码 仿12306_Java仿12306图片验证码
  14. 渐进符号与基本效率类型
  15. VB.NET转C# Constants.vbCrLf替换
  16. Python-qqbot实现QQ群翻译机器人
  17. UE5的项目建立及UE5(虚幻引擎5)个人视角移动按键操作及运行项目/day.2
  18. 国产服务器(麒麟操作系统),springboot应用并发访问redis数据错乱解决方案
  19. 使用GRUB2制作多重系统引导程序
  20. 【什么是iMessage苹果推?】什么是苹果推信?什么是苹果推?

热门文章

  1. VSCODE安装必要的插件实现浏览器中打开,以及显示网址
  2. 如何让自己在云服务器上部署的项目一直运行
  3. Python之Scrapy爬虫的常用命令
  4. 收藏 | 多目标跟踪(MOT)入门
  5. 归一化 vs 标准化 定量的分析
  6. Kubernetes(基础 一):进程
  7. 更改VMWare 虚拟机的硬件设置
  8. ZOJ 3329 One Person Game 带环的概率DP
  9. 1.mongodb在centos上面安装
  10. Javascript全局变量var与不var的区别深入解析