一、题意

我们是穿越银河的火箭队.......

给出若干个区间,之后给出若干个点,要求对每个点求出,第一个覆盖点的区间的数量,之后用当前所有点覆盖的区间的序号的乘积结合输入的Y来生成下一位点。最后输出,每个区间第一次覆盖的点的序号。

There are n trains running between Kanto and Johto region. Assuming the railway is a number line, the i-th train travels from coordinate li to coordinate ri (both inclusive).
One day, m Team Rocket members invaded the railway system successfully. The i-th Team Rocket member was going to destroy the transportation hub with coordinate xi. Once a transportation hub within the driving range of a train is destroyed, the train's itinerary will be canceled immediately.
Giovanni wants to know how many train trips will be firstly canceled after each attack.
After all the attacks finished, for each train Giovanni needs to know that in which attack its itinerary was firstly canceled, or it was unaffected at all.

二、题解

考虑区间可以被理解成二维的点对,则建立一个线段树,每个树节点挂一个vector,用来保存"所有起点在当前节点的点对"。之后要求每个节点的点按照,按照结尾大小有序排列。最后我们每次查一个点,实质上是在查所有起点小于当前给定节点,同时终点大于当前给定节点的所有点对。则,再使用一个数组或者别的什么东西记录下点的首次查询的点的编号。

#include<bits/stdc++.h>
using namespace std; #define ll long long
#define pp pair<ll,ll>
#define veci vector<int>
#define idx(x) (lower_bound(mapp,mapp+mapp_num,x)-mapp) const int MAXN = ;
const ll MOD = ; class Node{
public:
int l,r,lc,rc;
veci points;
};
Node nodes[MAXN*]; ll mapp[MAXN];
int mapp_num; int nodes_num; pp orders[MAXN];
int seq[MAXN];
int first_erased[MAXN]; int t,n,m;
int cases; int cntt; bool cmp(int a,int b)
{
return orders[a].second<orders[b].second;
} void tree_init(int a,int b)
{
int now = nodes_num++;
nodes[now].l = a;
nodes[now].r = b;
nodes[now].points.clear();
if(a == b-)return ;
int mid = (a+b)/;
nodes[now].lc = nodes_num;
tree_init(a,mid);
nodes[now].rc =nodes_num;
tree_init(mid,b);
} void tree_insert(int now,int pos,int key){
int l = nodes[now].l;
int r = nodes[now].r;
if(l == r-){
nodes[now].points.push_back(key);
// cout<<"check_tree: "<<now<<" "<<nodes[now].points.size()<<endl;
return ;
}
int mid = (l+r)/;
if(pos < mid)tree_insert(nodes[now].lc,pos,key);
else tree_insert(nodes[now].rc,pos,key);
} void tree_merge(int now)
{
int l = nodes[now].l;
int r = nodes[now].r;
if(l == r-)return ; tree_merge(nodes[now].lc);
tree_merge(nodes[now].rc);
int lc = nodes[now].lc;
int rc = nodes[now].rc;
int pl,pr;
pl = pr = ;
int lenl = nodes[lc].points.size();
int lenr = nodes[rc].points.size();
while(pl!= lenl || pr != lenr){
if(pl!= lenl && pr != lenr){
if( cmp(nodes[lc].points[pl],nodes[rc].points[pr]) )nodes[now].points.push_back(nodes[lc].points[pl++]);
else nodes[now].points.push_back(nodes[rc].points[pr++]);
}else{
while(pl!=lenl)nodes[now].points.push_back(nodes[lc].points[pl++]);
while(pr!=lenr)nodes[now].points.push_back(nodes[rc].points[pr++]);
}
}
// cout<<"check_merge: "<<nodes[now].points.size()<<endl; } ll tree_erase(int now,int a,int b,int num,ll key){
int l = nodes[now].l;
int r = nodes[now].r;
ll ret = ;
if(l == a&&r == b){
int len = nodes[now].points.size();
for(int i=len-;i>=;i--){
int tar = nodes[now].points[i];
if(orders[tar].second < key)break;
nodes[now].points.pop_back();
if(!first_erased[tar]){
cntt++;
first_erased[tar] = num;
if(!ret)ret = ;
ret *= tar;
ret %= MOD;
}
}return ret;
}
int mid = (l+r)/;
if(a < mid){
ll tmp = tree_erase(nodes[now].lc,a,min(b,mid),num,key);
if(tmp)ret = tmp;
tmp = ;
if(b>mid)tmp = tree_erase(nodes[now].rc,mid,b,num,key);
if(tmp && ret)ret *= tmp;
if(!ret && tmp)ret = tmp;
}else ret = tree_erase(nodes[now].rc,a,b,num,key);
return ret%MOD;
} void init()
{
cin>>n>>m;
nodes_num = ;
mapp_num = ;
memset(first_erased,,sizeof(int)*(n+));
mapp[mapp_num++] = LLONG_MIN;
mapp[mapp_num++] = LLONG_MAX;
for(int i=;i<=n;++i){
cin>>orders[i].first>>orders[i].second;
mapp[mapp_num++] = orders[i].first;
seq[i] = i;
}
tree_init(,mapp_num);
sort(mapp,mapp+mapp_num);
sort(seq+,seq++n,cmp); for(int i=;i<=n;++i)
{
// cout<<"check_seq: "<<idx(orders[seq[i]].first)<<endl;
tree_insert(,idx(orders[seq[i]].first),seq[i]);
}
tree_merge();
ll last = ;
printf("Case #%d:\n",cases-t);
for(int i=;i<=m;++i){
ll y;
cin>>y;
y ^= last;
cntt = ;
int index = idx(y);
if(mapp[index] == y)index++;
// cout<<"check_y "<<y<<"index: "<<index<<endl;
last = tree_erase(,,index,i,y);
printf("%d\n",cntt);
}
for(int i=;i<=n;++i){
printf("%d",first_erased[i]);
if(i == n)printf("\n");
else printf(" ");
}
} int main()
{
cin.sync_with_stdio(false);
cin>>t;cases = t;
while(t--)init();
return ;
}

树状数组版

#include<bits/stdc++.h>
using namespace std; #define ll long long
#define pp pair<ll,ll>
#define veci vector<int>
#define idx(x) (lower_bound(mapp,mapp+mapp_num,x)-mapp)
const int MAXN = ;
const ll MOD = ; int n,m,t;
int cases; pp orders[MAXN];
veci tree[MAXN];
int seq[MAXN];
int first_erased[MAXN];
int cntt; ll mapp[MAXN];
int mapp_num; bool cmp(int a,int b){
return orders[a].second < orders[b].second;
} void tree_insert(int pos,int key){
pos += ;
while(pos<mapp_num+){
tree[pos].push_back(key);
pos += pos&(-pos);
}
} ll tree_erase(int pos,int num,ll key){
pos += ;
ll ret = ;
while(pos){
int len = tree[pos].size();
for(int i=len-;i>=;i--){
int tar = tree[pos][i];
if(orders[tar].second < key)break;
tree[pos].pop_back();
if(first_erased[tar] == ){
cntt ++;
first_erased[tar] = num;
if(ret == )ret = ;
ret *= tar;
ret %=MOD;
}
}
pos -= pos&(-pos);
}
return ret;
} void init(){ mapp_num = ;
mapp[mapp_num++] = LLONG_MAX;
mapp[mapp_num++] = LLONG_MIN;
memset(first_erased,,sizeof(first_erased));
cin>>n>>m;
for(int i=;i<=n;++i){
cin>>orders[i].first>>orders[i].second;
mapp[mapp_num++] = orders[i].first;
seq[i] = i;
}
for(int i=;i<=n+;++i)tree[i].clear();
sort(mapp,mapp+mapp_num);
sort(seq+,seq++n,cmp);
for(int i=;i<=n;++i){
tree_insert(idx(orders[seq[i]].first),seq[i]);
} ll last = ;
printf("Case #%d:\n",cases-t);
for(int i=;i<=m;++i){
ll y;
cin>>y;
y ^= last;
cntt = ;
int index = idx(y);
if(mapp[index] != y)index--;
last = tree_erase(index,i,y);
printf("%d\n",cntt);
}
for(int i=;i<=n;++i){
printf("%d",first_erased[i]);
if(i == n)printf("\n");
else printf(" ");
}
} int main(){ cin.sync_with_stdio(false);
cin>>t;
cases = t;
while(t--)init(); return ;
}

牛客暑假多校第六场I-Team Rocket的更多相关文章

  1. 牛客暑假多校第六场 I Team Rocket

    题意: 现在有n条火车, 每条火车都有一个运行 [ Li, Ri ], 现在有m支火箭队, 每次火箭队都会破坏这整条铁路上的一个点, 如果一条火车的运行区间[Li, Ri] 被破坏了, 那么这条火车会 ...

  2. 2018牛客多校第六场 I.Team Rocket

    题意: 给出n个区间和m个点(点按顺序给出且强制在线).每个区间只会被第一个他包含的点摧毁.问每个点能摧毁多少个区间以及每个区间是被哪个点摧毁的. 题解: 将n个区间按照左端点排序,然后用vector ...

  3. 牛客暑假多校第五场A.gpa

    一.题意 给出你的N门课程的考试成绩和所占的机电数目.允许你放弃K门课的成绩,要求你的平均学分绩最高能达到多少. Kanade selected n courses in the university ...

  4. 牛客2018多校第六场 J Heritage of skywalkert - nth_element

    传送门 题意:提供一个随机生成函数,让你生成n个数,然后问你其中能找到的两个数的最小公倍数 最大 是多少. 思路:可以用nth_element()函数在O(n)下求出前 15 个大的数(当然,100个 ...

  5. 牛客暑假多校第五场 D inv

    题意:给你一个n, 接来下给你一个 [1,n] 中偶数的排列, 还有一个 [1, n] 中 奇数 按照递增的顺序排列, 现在求一个原数列, 使得偶数列排序 和 奇数列 都是原数列的一个子序列, 现在求 ...

  6. 牛客暑假多校第五场 I vcd

    这个题目一个队友没读懂, 然后我读错了题目, 还让他堆了半天的公式写了半天的代码, 交上去一直0.0, 另一队友问题目有没有读错, 我坚持没有读错, 然后坑了2个小时的时间,不然应该会早一点做出来. ...

  7. 2019牛客暑期多校第六场题解ABDJ

    A.Garbage Classification 传送门 题意:给你两个串,第一个串s由小写字母组成,第二个串t由dwh组成,长度为26,分别表示字母a到z代表的字符.现在要你判断: 如果字符串中‘h ...

  8. 2020牛客暑假多校训练营 第二场 H Happy Triangle set 线段树 分类讨论

    LINK:Happy Triangle 这道题很容易. 容易想到 a+b<x a<x<b x<a<b 其中等于的情况在第一个和第三个之中判一下即可. 前面两个容易想到se ...

  9. 2020牛客暑假多校训练营 第二场 G Greater and Greater bitset

    LINK:Greater and Greater 确实没能想到做法. 考虑利用bitset解决问题. 做法是:逐位判断每一位是否合法 第一位 就是 bitset上所有大于\(b_1\)的位置 置为1. ...

随机推荐

  1. Linux(Ubuntu) 常用命令

    玩儿转Linux:终端命令用法精选 最近再一次拾起了Ubuntu,为了更好的玩儿转Linux,专门到网上搜到的这些常用的终端命令,根据命令使用类别的不同分为了9个大类,都在下面一一列举了出来,个人觉得 ...

  2. 小于12px的字体大小在Chrome中不起作用

    今天遇见一个小问题,让人挺郁闷的,在Chrome浏览器中无法把字体变成12px以下.网上搜索以下,发现无论中文英文数字在网页中CSS设置小于12px后各大浏览器均支持,在谷歌chrome浏览器不支持解 ...

  3. appendChild与Transition动画

    在createElement之后,直接把这个div append到body中,是不会触发css3 transition动画的 必须要让浏览器计算div的css属性后,然后再设置div的style,才会 ...

  4. 用C++实现HTTP服务器 - Windows平台(开放源代码)

    有时间了看一下 https://blog.csdn.net/querw/article/details/6593328 libevent也实现了一下http服务

  5. echart 折线图、柱状图、饼图、环形图颜色修改

    之前在做报表的时候用过echart 用完也就完了,而这次在用的时候已经忘了,所以这里简单记录一下,好记性不如烂笔头!!! 1.折线图修改颜色: xAxis: { type: 'category', b ...

  6. python:正则模块

    1,正则表达式 正则表达式是用来做字符串的匹配的,正则有他自己的规则,和python没有关系,一种匹配字符串的规则. 2,字符组 在同一个位置可能出现的各种字符组成了一个字符组,在正则表达式中用[]表 ...

  7. 【[HAOI2016]找相同字符】

    其实这道题跟[AHOI2013]差异很像 其实这个问题的本质就是让你算所有后缀的\(lcp\)长度之和,但是得来自两个不同的字符串 先把两个字符串拼起来做一遍\(SA\),由于我们多算了来自于同一个串 ...

  8. ASP.NET SignalR 与LayIM配合,轻松实现网站客服聊天室(六)之 好友申请、同意、拒绝

    不知道距离上一篇多久没有写了,可能是因为忙(lan)的关系吧.废话不多说,今天要介绍的不算什么新知识,主要是逻辑上的一些东西.什么逻辑呢,加好友,发送好友申请,对方审批通过,拒绝.(很遗憾,对方审批通 ...

  9. 基于 UIImagePickerController 的拓展封装 - iOS

    基于 UIImagePickerController 的拓展,分别支持调用相机.相册的功能,其中相机可以设置默认调用前后摄像头; 简单对此进行了封装和实现,其中还有很多点可以继续挖掘和优化,该版本具体 ...

  10. Spring知识点小结(一)

    一.Spring的简介 1.spring是一个full-stack轻量级开源框架    2.spring的两大核心        IoC: inverse of control  控制反转:反转是对象 ...