传送门: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的更多相关文章

  1. 【Asia Yokohama Regional Contest 2018】Arithmetic Progressions

    题目大意:给定 N(1<N<=5000) 个不同元素组成的集合,求从中选出若干数字组成的等差数列最长是多少. 题解:直接暴力有 \(O(n^3)\) 的算法,即:枚举等差数列的前两个值,再 ...

  2. Asia Yokohama Regional Contest 2018 G题 What Goes Up Must Come Down

    链接 G题 https://codeforces.com/gym/102082 使其成为单峰序列需要交换多少次相邻的数. 树状数组维护逆序对. 对于每个序列中的数,要么在单峰的左侧,要么在单峰的右侧, ...

  3. The 2019 ICPC Asia Shanghai Regional Contest H Tree Partition k、Color Graph

    H题意: 给你一个n个节点n-1条无向边构成的树,每一个节点有一个权值wi,你需要把这棵树划分成k个子树,每一个子树的权值是这棵子树上所有节点权值之和. 你要输出这k棵子树的权值中那个最大的.你需要让 ...

  4. ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction hihocoder1870~1879

    ACM-ICPC Asia Beijing Regional Contest 2018 Reproduction hihocoder1870~1879 A 签到,dfs 或者 floyd 都行. #i ...

  5. 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 ...

  6. 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 ...

  7. 2018 ICPC Asia Jakarta Regional Contest

    题目传送门 题号 A B C D E F G H I J K L 状态 Ο . . Ο . . Ø Ø Ø Ø . Ο Ο:当场 Ø:已补 .  :  待补 A. Edit Distance Thin ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. boot,rebuild,resize,migrate有关的scheduler流程

    代码调用流程: 1. nova.scheduler.client.query.SchedulerQueryClient#select_destinations 2. nova.scheduler.rp ...

  2. Selenium WebDriver 下 plugin container for firefox has stopped working

    用selenium 的webdriver 和 firefox 浏览器做自动化测试,经常会出现 plugin container for firefox has stopped working 如下图所 ...

  3. asp.net mvc 使用Ajax调用Action 返回数据【转】

      使用asp.net mvc 调用Action方法很简单. 一.无参数方法. 1.首先,引入jquery-1.5.1.min.js 脚本,根据版本不同大家自行选择. <script src=& ...

  4. node.js常用方法

    1.获取真实地址 function getClientIp(req) { return req.headers['x-forwarded-for'] || req.connection.remoteA ...

  5. 20135313_exp5

    课程:Java程序与设计     班级:1353 姓 名:吴子怡  学号:20135313 小组成员: 20135113肖昱 成绩:             指导教师:娄嘉鹏       实验日期:2 ...

  6. "群英队"电梯演讲

    视频如下: https://imgcache.qq.com/tencentvideo_v1/playerv3/TPout.swf?max_age=86400&v=20161117&vi ...

  7. rsa加密算法,前后端实现。

    前端js: 下载地址:http://travistidwell.com/jsencrypt/ js第一版本: // 对数据加密 function encrypt(enStr){ //没有加载jsenc ...

  8. MDL详解

    以下的虚拟内存可以理解成逻辑内存,因为我觉得只有这样才能讲通下面所有的东西.以下的“未分页”指没有为页进行编码. 以下为MDL结构体(我很郁闷,我在MSDN上没有找到这个结构体) typedef st ...

  9. Windows下IntelliJ IDEA中调试Spark Standalone

    参考:http://dataknocker.github.io/2014/11/12/idea%E4%B8%8Adebug-spark-standalone/ 转载请注明来自:http://www.c ...

  10. python 将base64字符串还原为图片

    今天弄验证码的时候发现,验证码的图片的src竟然是下面的这么一个一串字符串,吓到,好像不可以http请求的,第一次见,就好尴尬,去网上搜索了一下,说是: 这是Data URI scheme. data ...