Codeforces 420D Cup Trick 平衡树
平衡树维护一下位置。
#include<bits/stdc++.h>
#include <bits/extc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std;
using namespace __gnu_pbds; const int N = 1e6 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ;
const double eps = 1e-;
const double PI = acos(-); template <class T>
using Tree = tree<T, null_type, std::less<T>, rb_tree_tag,tree_order_statistics_node_update>; Tree<PII> T; int n, m, ans[N];
bool vis[N]; int main() {
scanf("%d%d", &n, &m);
int mn = m;
for(int i = ; i <= n; i++)
T.insert(mk(i + m, i));
while(m--) {
int x, y; scanf("%d%d", &x, &y);
PII p = *T.find_by_order(y - );
T.erase(p);
p.fi = mn--;
T.insert(p);
if(ans[p.se]) {
if(x != ans[p.se]) return puts("-1"), ;
} else {
if(vis[x]) return puts("-1"), ;
ans[p.se] = x;
vis[x] = true;
}
}
for(int i = , j = ; i <= n; i++) {
if(!ans[i]) {
while(vis[j]) j++;
vis[j] = true;
ans[i] = j;
}
printf("%d ", ans[i]);
}
puts("");
return ;
} /*
find_by_order(k - 1) 求第k小的值
order_of_key(k) 求有多少个数 <= k
*/
Codeforces 420D Cup Trick 平衡树的更多相关文章
- codeforces 420D Cup Trick
codeforces 420D Cup Trick 题意 题解 官方做法需要用到线段树+平衡树(? 如果数据小的话似乎可以用莫队).然后代码好长好长.我补了一个只要用到树状数组的做法. 代码 #inc ...
- Codeforces VK Cup 2015 A.And Yet Another Bracket Sequence(后缀数组+平衡树+字符串)
这题做得比较复杂..应该有更好的做法 题目大意: 有一个括号序列,可以对其进行两种操作: · 向里面加一个括号,可以在开头,在结尾,在两个括号之间加. · 对当前括号序列进 ...
- Codeforces VK CUP 2015 D. Closest Equals(线段树+扫描线)
题目链接:http://codeforces.com/contest/522/problem/D 题目大意: 给你一个长度为n的序列,然后有m次查询,每次查询输入一个区间[li,lj],对于每一个查 ...
- Codeforces VK Cup 2012 Round 3 A. Variable, or There and Back Again(dfs)
题目链接:http://codeforces.com/problemset/problem/164/A 思路:用vector分别保留原图和发图,然后分别从val值为1的点正向遍历,va值为2的点反向遍 ...
- Codeforces Bubble Cup 8 - Finals [Online Mirror] B. Bribes lca
题目链接: http://codeforces.com/contest/575/problem/B 题解: 把链u,v拆成u,lca(u,v)和v,lca(u,v)(v,lca(u,v)是倒过来的). ...
- Codeforces Bubble Cup 8 - Finals [Online Mirror]H. Bots 数学
H. Bots Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/H Desc ...
- Codeforces Bubble Cup 8 - Finals [Online Mirror] D. Tablecity 数学题
D. Tablecity Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/D ...
- Codeforces Bubble Cup 8 - Finals [Online Mirror] F. Bulbo DP
F. Bulbo Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/F Des ...
- codeforces VK Cup 2015 - Qualification Round 1 B. Photo to Remember 水题
B. Photo to Remember Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/522/ ...
随机推荐
- 用Go的风格实现素数筛选
package main import ( "fmt" "time" ) func source(ch chan<- int) { ; i < En ...
- mac 上如何安装非app store上的下载的软件-------打开未知来源
打开了 Terminal 终端后 ,在命令提示后输入 sudo spctl --master-disable 并按下回车执行,如下图所示. 随后再输入当前 Mac 用户的密码,如下图所示. 如 ...
- pip的常用命令
前言 pip作为Python的御用包管理工具有着强大的功能,但是许多命令需要我们使用的时候借助搜索引擎查找(尤其是我), 于是我想将我使用到的命令整合下来,以后不用麻烦去找了,也希望能给你带来帮助.文 ...
- bzoj3730 震波 [动态点分治,树状数组]
传送门 思路 如果没有强制在线的话可以离线之后CDQ分治随便搞. 有了强制在线之后--可能可以二维线段树?然而我不会算空间. 然后我们莫名其妙地想到了动态点分治,然后这题就差不多做完了. 点分树有一个 ...
- Vue中的render函数随笔
使用vue-cli创建项目后,再main.js里面有这样一段代码: new Vue({ render:h => h(App) }).$mount('#app') render函数是渲染一个视图, ...
- tp5学习
tp5的表单验证 tp5验证码的使用: tp5分页后页面跳转:少参数的处理方法: tp5绑定根目录为: public目录下的index.php 隐藏index.php .htaccess文件修改 控制 ...
- Confluence 6 配置服务器基础地址示例
如果 Confluence 的安装是没有安装在非根目录路径(这个是上下文路径),然后服务器基础 URL 地址应该包括上下文地址.例如,你的 Confluence 正在运行在下面的地址: http:// ...
- Confluence 6 PostgreSQL 创建数据库和数据库用户
一旦你成功的安装了 PostgreSQL 数据库: 创建一个数据库用户,例如 confluenceuser. 你的新用户必须能够 创建数据库对象(create database objects) 和 ...
- web的分页方法
web分页的三种方式,闲来无事总结一下. 1.使用前端表格插件进行分页 例如用bootstrap的拓展table组件,注意设置其分页属性时设置为"client", 即是 sideP ...
- Let the Balloon Rise <map>的应用
Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the ...