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 ...
随机推荐
- python数据可视化——matplotlib 用户手册入门:pyplot 画图
参考matplotlib官方指南: https://matplotlib.org/tutorials/introductory/pyplot.html#sphx-glr-tutorials-intro ...
- linux-sftp-指定端口号登录远程主机
sftp -oPort=60001 root@192.168.0.254 -o选项来指定端口号 -oPort=远程端口号
- Python 装饰器Decorator(二)
对于上一篇“”Python闭包“”随笔中提到的make_averager()函数的如下实现,我们把历史值保存在列表里,每次计算平均值都需要重新求和,当历史值较多时,需要占用比较多的空间并且效率也不高. ...
- Live Archive 训练题 2019/3/9
7454 Parentheses A bracket is a punctuation mark, which is used in matched pairs, usually used withi ...
- Heavy Cargo POJ 2263 (Floyd传递闭包)
Description Big Johnsson Trucks Inc. is a company specialized in manufacturing big trucks. Their lat ...
- EXT4+Struts2 JSON的问题
ERROR : Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframewor ...
- xpath的学习
xpath的作用就是两个字“定位”,运用各种方法进行快速准确的定位,推荐两个非常有用的的firefox工具:firebug和xpath checker 定位 1.依靠自己属性,文本定位 //td[ ...
- 九度-题目1026:又一版 A+B
http://ac.jobdu.com/problem.php?pid=1026 题目描述: 输入两个不超过整型定义的非负10进制整数A和B(<=231-1),输出A+B的m (1 < m ...
- 第156天:canvas(三)
一.变形 1.1 translate translate(x, y) 用来移动 canvas 的原点到指定的位置 translate方法接受两个参数.x 是左右偏移量,y 是上下偏移量,如右图 ...
- Python环境安装(Windows环境)
近半年来一直在用Python处理手头的工作.想想,Python确实是一门比较强大的语言,容易上手且功能强大, 基本上想做的工作都能找到别人提供的包. 目前主要在windows系统上办公,这里把wind ...