题目链接:http://codeforces.com/problemset/problem/1154/E

题目大意:

  有n个队员,编号1~n,每个人的能力各自对应1~n中的一个数,每个人的能力都不相同。有1号教练和2号教练,他们轮流从剩余队伍里选人,轮到某位教练选时,它总是选剩余队员中能力最强的人和他左右各k个人。问选完的时候每个人的组号。

分析:

  什么结构能快速查找到队员呢?当然是数组啦!什么结构能频繁删改呢?当然是链表啦!所以就用承载在数组上的链表来做啦!

代码如下:

 #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std; #define INIT() std::ios::sync_with_stdio(false);std::cin.tie(0);
#define Rep(i,n) for (int i = 0; i < (n); ++i)
#define For(i,s,t) for (int i = (s); i <= (t); ++i)
#define rFor(i,t,s) for (int i = (t); i >= (s); --i)
#define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
#define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
#define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i) #define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl #define LOWBIT(x) ((x)&(-x)) #define ALL(x) x.begin(),x.end()
#define INS(x) inserter(x,x.begin()) #define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,inf,sizeof(a))
#define msM(a) memset(a,-1,sizeof(a)) #define MP make_pair
#define PB push_back
#define ft first
#define sd second template<typename T1, typename T2>
istream &operator>>(istream &in, pair<T1, T2> &p) {
in >> p.first >> p.second;
return in;
} template<typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x: v)
in >> x;
return in;
} template<typename T1, typename T2>
ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]" << "\n";
return out;
} typedef long long LL;
typedef unsigned long long uLL;
typedef pair< double, double > PDD;
typedef set< int > SI;
typedef vector< int > VI;
const double EPS = 1e-;
const int inf = 1e9 + ;
const LL mod = 1e9 + ;
const int maxN = 2e5 + ;
const LL ONE = ; struct Node{
int value, pos;
Node* prev = NULL;
Node* next = NULL;
}; int n, k, ans[maxN];
Node nodes[maxN];
int to[maxN];
int f = ; int main(){
scanf("%d%d\n", &n, &k);
For(i, , n) {
scanf("%d", &nodes[i].value);
nodes[i].pos = i;
to[nodes[i].value] = i;
} Rep(i, n + ) nodes[i].next = &nodes[i + ];
Rep(i, n + ) nodes[i + ].prev = &nodes[i]; int i = n;
while(i >= ) {
if(ans[to[i]] != ) {
--i;
continue;
} ans[to[i]] = f;
// 处理左边k个
int cnt = ;
Node *p = nodes[to[i]].prev;
while(p->prev != NULL && cnt < k) {
ans[p->pos] = f;
p = p->prev;
++cnt;
}
// 处理右边k个
cnt = ;
Node *q = nodes[to[i]].next;
while(q->next != NULL && cnt < k) {
ans[q->pos] = f;
q = q->next;
++cnt;
} // 删掉选走的
p->next = q;
q->prev = p; f = f == ? : ;
} For(i, , n) printf("%d", ans[i]);
printf("\n");
return ;
}

最新文章

  1. js面向对象学习 - 对象概念及创建对象
  2. Runtime应用防止按钮连续点击 (转)
  3. 【JAVA线程间通信技术】
  4. AttributeTargets 枚举
  5. 图解Android - Binder 和 Service
  6. android怎么换背景图片
  7. jquery常见问题
  8. Python进阶(面向对象编程基础)(一)
  9. nodejs教程:安装express及配置app.js文件
  10. Jenkins 配置 Git 错误解决:CAfile: C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
  11. 2018-2019-3 20165314《网络对抗技术》Exp2 后门原理与实践
  12. Ocelot概述
  13. 如何正确可视化RAW(ARW,DNG,raw等格式)图像?
  14. python之获取当前操作系统(平台)
  15. IntelliJ IDEA详情
  16. 【iCore4 双核心板_uC/OS-II】例程二:任务的建立与删除
  17. 添加dubbo.xsd的方法
  18. C语言定义共享全局变量
  19. Play with Floor and Ceil UVA - 10673(拓展欧几里得)
  20. Tsk4.5异步

热门文章

  1. Linux中的零拷贝技术
  2. Linux系统学习之Linux账号管理
  3. nginx+tomcat9+redisson+redis+jdk1.8简单实现session共享
  4. Windows下pip命令无法使用的解决办法
  5. 基于 Vue + Koa2 + MongoDB + Redis 实现一个完整的登录注册
  6. 通过 JS 脚本去除csdn广告
  7. tkinter python(图形开发界面)
  8. Jmeter性能与接口自动化实战
  9. NOIP2016解题报告
  10. Atcoder E - Knapsack 2 (01背包进阶版 ex )