比赛时虽然贪了心,不过后面没想到怎么处理和set的排序方法忘了- -,其实是和优先队列的仿函数一样的。。。

比赛后用set pair过了。。。

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 200005;
const ll mod = 1e9 + 7;
const double eps = 1e-12;
ll a[N];
struct node1 {
ll d, dm, pos;
}f[N];
struct node2 {
ll d, pos;
}g[N];
bool cmp1(node1 a, node1 b) {
return a.d > b.d;
}
bool cmp2(node2 a, node2 b) {
return a.d > b.d;
}
ll l[N], r[N], ans[N];
set<pair<ll, ll> >s;
int main() {
ll n, m;
cin >> n >> m;
for (ll i = 1;i <= n;i++) {
cin >> l[i] >> r[i];
if (i >= 2) {
f[i - 1].d = l[i] - r[i - 1];
f[i - 1].dm = r[i] - l[i - 1];
f[i - 1].pos = i - 1;
}
}
for (ll i = 1;i <= m;i++) {
cin >> a[i];
g[i].d = a[i];
g[i].pos = i;
}
sort(f + 1, f + n, cmp1);
sort(g + 1, g + m + 1, cmp2);
ll flag = 1, j = 1;
for (int i = 1;i <= m;i++)s.insert(make_pair(g[i].d,g[i].pos));
for (ll i = 1;i < n;i++){
auto it = s.upper_bound(make_pair(f[i].dm,1e18));
if (it != s.begin())it--;
/*while (it!=s.end()&& (!(g[it->second].d >= f[i].d&&g[it->second].d <= f[i].dm))) {
j++;
}*/
if(it!=s.end()&&it->first >= f[i].d&&it->first <= f[i].dm){
ans[f[i].pos] = it->second;
s.erase(it);
}
else {
flag = 0;
break;
}
}
if (flag == 0)puts("No");
else {
puts("Yes");
for (ll i = 1;i < n;i++)
cout << ans[i] << " ";
}
return 0;
}

然后又作死,自己脑补平衡树套平衡树用的splay过了,两个都错在过24组,set里错24组因为不知道排序内部到底会有什么鬼,splay二分查找时要保存满足条件的最大值,这里不是循环到最后的y值可能y会由一个相等的值转到一个小于或大于的值,因为没判断想等跳出,后面判断了为更大的才赋值。

其实这里本来只用写单层splay就可以了,另一个用个vector保存就可以了,不过想练练splay了。。。其实和普通平衡树差不多,只不过每一个节点又是一课平衡树,操作的时候注意第一个点建树为空删树,把操作部分变为对子树中节点操作,当然这个题没有复杂的up或者down。另外要注意要先声明一些东西,不然后面调用前面,前面又调用后面- -。。。

另外两种时间好似差不多- -。估计c++11中stl优化的比较好吧-w-。

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N = 800005;
const ll maxn = 800005;
const ll mod = 1e9 + 7;
const double eps = 1e-12;
ll a[N];
struct node {
ll d, dm, pos;
}f[N];
pair<ll, ll>g[N];
bool cmp(node a, node b) {
return a.d > b.d;
}
struct SplayTree;
struct SplayTree *cstm;
ll l[N], r[N], ans[N];
struct Node {
ll key;
SplayTree *st;
Node *c[2], *p;
}mem[N], *cur;
//Initialize functions without memory pool //Splay tree
struct SplayTree {
Node *root,*nil;
void Rotate(Node *x, ll f) {
if (x == nil) return;
Node *y = x->p;
y->c[f ^ 1] = x->c[f], x->p = y->p;
if (x->c[f] != nil)
x->c[f]->p = y;
if (y->p != nil)
y->p->c[y->p->c[1] == y] = x;
x->c[f] = y, y->p = x;
}
void Splay(Node *x, Node *f) {
while (x->p != f) {
Node *y = x->p;
if (y->p == f)
Rotate(x, x == y->c[0]);
else {
ll fd = y->p->c[0] == y;
if (y->c[fd] == x)
Rotate(x, fd ^ 1), Rotate(x, fd);
else
Rotate(y, fd), Rotate(x, fd);
}
}
if (f == nil)
root = x;
}
Node *newNode(ll v, Node *p, Node *nil) {
cur->c[0] = cur->c[1] = nil;
cur->p = p;
cur->key = v;
cur->st = cstm++;
return cur++;
}
void Insert(ll v) {
Node *x = root, *y = nil;
while (x != nil) {
y = x;
x = x->c[v >= x->key];
}
y->c[v >= y->key] = x = newNode(v, y, nil);
Splay(x, nil);
}
void Insert(ll v,ll pos) {
Node *x = root, *y = nil;
while (x != nil&&x->key != v) {
y = x;
x = x->c[v >= x->key];
}
if (x == nil) {
y->c[v >= y->key] = x = newNode(v, y, nil);
cur->c[0] = cur->c[1] = nullptr;
cur->p = cur;
cur->key = 0;
cur->st = cstm++;
x->st->nil = cur++;
x->st->root = x->st->nil;
}
x->st->Insert(pos);
Splay(x, nil);
}
pair<ll, ll> fun(ll v) {
Node *x = root, *y = nil;
while (x!=nil) {
if (x->key <= v&&x->key > y->key)
y = x;
x = x->c[v > x->key];
}
if(y!=nil)
return make_pair(y->key, y->st->root->key);
return make_pair(-1, -1);
}
void Del() {
Node *x = root;
if (x->c[0] == nil&&x->c[1] == nil)root = nil;
else if (x->c[0] == nil) {
x = x->c[1];
while (x->c[0] != nil)
x = x->c[0];
Splay(x, nil);//x->c[0]->p = nil;//x->c[0]->c[0] = x->c[0]->c[1] = nil;
x->c[0] = nil;
}
else if (x->c[1] == nil) {
x = x->c[0];
while (x->c[1] != nil)
x = x->c[1];
Splay(x, nil);//x->c[1]->p = nil;//x->c[1]->c[0] = x->c[1]->c[1] = nil;
x->c[1] = nil;
}
else {
x = x->c[1];
while (x->c[0] != nil)
x = x->c[0];
Node *y = root;
Splay(x, nil);
Splay(y, x);
x->c[0] = x->c[0]->c[0];
x->c[0]->p = x;
}
//Splay(x->c[0], x->c[1]);
}
void Remove(ll v) {
Node *x = root;
while (x->key != v) {
x = x->c[v >= x->key];
}
Splay(x, nil);
Del();
}
void Remove(pair<ll, ll> it) {
Node *x = root;
while (x->key != it.first) {
x = x->c[it.first >= x->key];
}
Splay(x, nil);
x->st->Remove(it.second);
if (x->st->root == x->st->nil)
Del();
}
}s,stm[N]; void Init() {
cur = mem;
cstm = stm;
} int main() {
ll n, m;
cin >> n >> m;
for (ll i = 1;i <= n;i++) {
cin >> l[i] >> r[i];
if (i >= 2) {
f[i - 1].d = l[i] - r[i - 1];
f[i - 1].dm = r[i] - l[i - 1];
f[i - 1].pos = i - 1;
}
}
for (ll i = 1;i <= m;i++) {
cin >> a[i];
g[i].first = a[i];
g[i].second = i;
}
sort(f + 1, f + n, cmp);
sort(g + 1, g + m + 1);
ll flag = 1, j = 1;
Init();cur->c[0] = cur->c[1] = nullptr;cur->key = 0;cur->p = cur;cur->st = cstm++;s.nil = cur++;s.root = s.nil;
for (ll i = m;i >= 1;i--)s.Insert(g[i].first,g[i].second);
for (ll i = 1;i < n;i++){
auto it = s.fun(f[i].dm);
if(it.first!=-1&&it.first >= f[i].d&&it.first <= f[i].dm){
ans[f[i].pos] = it.second;
s.Remove(it);
}
else {
flag = 0;
break;
}
}
if (flag == 0)puts("No");
else {
puts("Yes");
for (ll i = 1;i < n;i++)
cout << ans[i] << " ";
}
return 0;
}

http://codeforces.com/contest/555/problem/B的更多相关文章

  1. codeforces.com/contest/325/problem/B

    http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...

  2. [E. Ehab's REAL Number Theory Problem](https://codeforces.com/contest/1325/problem/E) 数论+图论 求最小环

    E. Ehab's REAL Number Theory Problem 数论+图论 求最小环 题目大意: 给你一个n大小的数列,数列里的每一个元素满足以下要求: 数据范围是:\(1<=a_i& ...

  3. http://codeforces.com/contest/610/problem/D

    D. Vika and Segments time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  4. http://codeforces.com/contest/612/problem/D

    D. The Union of k-Segments time limit per test 4 seconds memory limit per test 256 megabytes input s ...

  5. http://codeforces.com/contest/536/problem/B

    B. Tavas and Malekas time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  6. http://codeforces.com/contest/535/problem/C

    C. Tavas and Karafs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. http://codeforces.com/contest/838/problem/A

    A. Binary Blocks time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  8. http://codeforces.com/contest/402/problem/E

    E. Strictly Positive Matrix time limit per test 1 second memory limit per test 256 megabytes input s ...

  9. codeforces.com/contest/251/problem/C

    C. Number Transformation time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

随机推荐

  1. java动态联编

    JAVA中联编有两种,一种是动态联编,一种是静态联编. 动态联编:也叫多态联编或者是迟后联编,因为到底要调用哪一个函数,在编译时不能确定,而要推迟到运行中确定.也就是说,要等到程序运行时,确定了指针所 ...

  2. android导入项目出现R文件不能生成

    关于原因网上有好多,比如 1.有时候eclipse不自动编译,把project clean一下,让R.java重新生成   2.选择菜单  Project >> Clean ,前提是勾选上 ...

  3. 使用JavaScript创建我的分页

    把下面的方法放到一个js文件,页面引用他就行了 JavaScript function PageList(PageSize, PageIndex, TotalCount, ParList) { $(& ...

  4. Marshal.SecureStringToBSTR

    Marshal.StringToBSTR 方法 命名空间:System.Runtime.InteropServices程序集:mscorlib(在 mscorlib.dll 中) // 使用一个Int ...

  5. iOS获取的NSDate date时间与实际相差8个小时

    NSDate *startDate = [NSDate date];NSTimeZone *zone = [NSTimeZone systemTimeZone];NSInteger interval ...

  6. break , continue , exit

    break , continue , exit 例一:#!/bin/bash . /etc/init.d/functions `;do ];then #continue #没有数字3 break #e ...

  7. 11种dialogBox样式打包开源,逐一详解

    期待已久,APICloud官方总算把各种提示样式给封装了,再也不用苦逼的自己各种被虐着封装自定义样式了.这个分享我把 dialogBox 模块的 11 个样式分别实现个简单的效果,其中将 alert ...

  8. MOGRE学习笔记(1) - OGRE简介及在vs2010下配置

    由于工作需要,花费了一段时间研究OGRE,但是研究的目的是要在vs2010平台下用c#进行MOGRE的开发,不得已才转到MGRE,步骤是首选熟悉MOGRE的一些基础知识,做到在winform下能用MO ...

  9. Android图片压缩方法总结

    本文总结Android应用开发中三种常见的图片压缩方法,分别是:质量压缩法.比例压缩法(根据路径获取图片并压缩)和比例压缩法(根据Bitmap图片压缩).   第一:质量压缩方法:   ? 1 2 3 ...

  10. iOS网络协议 HTTP/TCP/IP浅析

    一.TCP/IP协议       话说两台电脑要通讯就必须遵守共同的规则,就好比两个人要沟通就必须使用共同的语言一样.一个只懂英语的人,和一个只懂中文的人由于没有共同的语言(规则)就没办法沟通.两台电 ...