2018-2019, ICPC, Asia Yokohama Regional Contest 2018 K
传送门:https://codeforces.com/gym/102082/attachments
题解:
代码:
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0)
#define debug1(x) cout<<"["<<#x<<" "<<(x)<<"]\n"
#define debug2(x,y) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<"]\n"
#define debug3(x,y,z) cout<<"["<<#x<<" "<<(x)<<" "<<#y<<" "<<(y)<<" "<<#z<<" "<<z<<"]\n"
LL read() {
int x = , f = ; char ch = getchar();
while(ch < '' || ch > '') {
if(ch == '-')f = -;
ch = getchar();
}
while(ch >= '' && ch <= '') {
x = x * + ch - '';
ch = getchar();
}
return x * f;
}
const double eps = 1e-;
const int mod = 1e9 + ;
const int maxn = 3e5 + ;
const int INF = 0x3f3f3f3f;
const LL INFLL = 0x3f3f3f3f3f3f3f3f;
int n;
int num;
vector<pii> aa;
vector<int> a;
vector<int> b;
int get_ans() {
vector<int> tmpa;
tmpa = a;
vector<int> tmpb;
tmpb = b;
sort(tmpa.begin(), tmpa.end());
sort(tmpb.begin(), tmpb.end());
int ans = ;
int tmp = ;
for(int i = ; i < n; i++) {
if(tmp == n) break;
if(tmpa[tmp] < tmpb[i]) {
ans++;
tmp++;
}
}
return ans;
}
int len;
bool check(int pos, int mid) {
int res = ;
int tmp = ;
for(int i = ; i < len; i++) {
if(i == mid) continue;
if(tmp == n) continue;
while(tmp < n && aa[tmp].second <= pos) tmp++;
if(aa[tmp].first < b[i]) tmp++, res++;
}
if(res == num) return ;
else {
if(res + (b[mid] > a[pos]) == num) return ;
else if(res + (b[len - ] > a[pos]) == num) return ;
else return ;
}
}
int main() {
#ifndef ONLINE_JUDGE
FIN
#endif
scanf("%d", &n);
for(int i = , x; i < n; i++) {
scanf("%d", &x);
a.push_back(x);
aa.push_back(make_pair(x, i));
}
for(int i = , x; i <= n; i++) {
scanf("%d", &x);
b.push_back(x);
}
sort(aa.begin(), aa.end());
sort(b.begin(), b.end());
num = get_ans();
vector<int> ans;
for(int i = ; i < n; i++) {
len = b.size() ;
int l = , r = len - ;
while(r - l > ) {
int mid = (l + r) >> ;
// debug1(num);
// debug3(l, r, mid);
if(check(i, mid)) {
l = mid;
} else {
r = mid;
}
}
// debug1(l);
// debug3(r, (int)check(i, r), num);
if(check(i, r)) {
ans.push_back(b[r]);
num -= a[i] < b[r];
b.erase(b.begin() + r);
} else {
ans.push_back(b[l]);
num -= a[i] < b[l];
b.erase(b.begin() + l);
}
}
for(int i = ; i < ans.size(); i++) {
printf("%d%c", ans[i], i == ans.size() - ? '\n' : ' ');
}
return ;
}
close
2018-2019, ICPC, Asia Yokohama Regional Contest 2018 K的更多相关文章
- 【Asia Yokohama Regional Contest 2018】Arithmetic Progressions
题目大意:给定 N(1<N<=5000) 个不同元素组成的集合,求从中选出若干数字组成的等差数列最长是多少. 题解:直接暴力有 \(O(n^3)\) 的算法,即:枚举等差数列的前两个值,再 ...
- Asia Yokohama Regional Contest 2018 G题 What Goes Up Must Come Down
链接 G题 https://codeforces.com/gym/102082 使其成为单峰序列需要交换多少次相邻的数. 树状数组维护逆序对. 对于每个序列中的数,要么在单峰的左侧,要么在单峰的右侧, ...
- The 2019 ICPC Asia Shanghai Regional Contest H Tree Partition k、Color Graph
H题意: 给你一个n个节点n-1条无向边构成的树,每一个节点有一个权值wi,你需要把这棵树划分成k个子树,每一个子树的权值是这棵子树上所有节点权值之和. 你要输出这k棵子树的权值中那个最大的.你需要让 ...
- ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction hihocoder1870~1879
ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction hihocoder1870~1879 A 签到,dfs 或者 floyd 都行. #i ...
- 2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred)
2019-2020 ICPC, Asia Jakarta Regional Contest (Online Mirror, ICPC Rules, Teams Preferred) easy: ACE ...
- 2019 ICPC Asia Nanjing Regional
2019 ICPC Asia Nanjing Regional A - Hard Problem 计蒜客 - 42395 若 n = 10,可以先取:6,7,8,9,10.然后随便从1,2,3,4,5 ...
- 2018 ICPC Asia Jakarta Regional Contest
题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . Ø Ø Ø Ø . Ο Ο:当场 Ø:已补 . : 待补 A. Edit Distance Thin ...
- hihoCoder #1871 : Heshen's Account Book-字符串暴力模拟 自闭(getline()函数) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction B) 2018 ICPC 北京区域赛现场赛B
P2 : Heshen's Account Book Time Limit:1000ms Case Time Limit:1000ms Memory Limit:512MB Description H ...
- hihoCoder #1870 : Jin Yong’s Wukong Ranking List-闭包传递(递归) (ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction A) 2018 ICPC 北京区域赛现场赛A
P1 : Jin Yong’s Wukong Ranking List Time Limit:1000ms Case Time Limit:1000ms Memory Limit:512MB Desc ...
随机推荐
- CentOS7部署ELK5.2
原文发表于cu:2017-02-10 参考文档: Elasticsearchyum文档:https://www.elastic.co/guide/en/elasticsearch/reference/ ...
- winform圆角窗体实现
winform圆角窗体实现 1.窗体的FormBorderStyle设置成None,不要控制边框 2.TransparencyKey和BackColor颜色设置成相同的,这样,窗体就透明了 3.以此为 ...
- 关于Amazon.com Seller 网络以及IP地址更换 官方回答
Greetings from Amazon Seller Support, I understand your concern that there will be a change of IP ad ...
- python3【基础】-字符串 常用的方法
字符串一个最重要的特性就是不可修改. name.capitalize() 首字母大写 name.casefold() 大写全部变小写 name.center(50,"-") 输出 ...
- 4个数的和为0 51nod 1267
给出N个整数,你来判断一下是否能够选出4个数,他们的和为0,可以则输出"Yes",否则输出"No". Input 第1行,1个数N,N为数组的长度(4 < ...
- MySort试验记录
MySort试验记录 编写目标 结果代码 思路 将数组每一个项目的第三组数字抽出来并且排序成12345的顺序,并形成新数组k3. 把原数组的每一项与k3进行比较,每符合一项便输出一项,从而重新排序出新 ...
- 人生苦短,我用Python!
一.程序分析 1.读取文件到缓冲区 def process_file(): # 读文件到缓冲区 try: # 打开文件 f = open("C:\\Users\\panbo\\Desktop ...
- C++总结作业
在博客作业中学到的内容 在博客作业中,首先我学到了Markdown编辑器的排版格式,github的上传,如果没有博客作业,可能根本不会接触到这些内容.然后,就C++来讲,我在博客作业中学会了命令行参数 ...
- Alpha冲刺——第九天
Alpha第九天 听说 031502543 周龙荣(队长) 031502615 李家鹏 031502632 伍晨薇 031502637 张柽 031502639 郑秦 1.前言 任务分配是VV.ZQ. ...
- ZOJ 3946 Highway Project 贪心+最短路
题目链接: http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=3946 题解: 用dijkstra跑单元最短路径,如果对于顶点v,存 ...