一、题意

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

给出若干个区间,之后给出若干个点,要求对每个点求出,第一个覆盖点的区间的数量,之后用当前所有点覆盖的区间的序号的乘积结合输入的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. yjh_study_command

    1.show current user in oralce ansower:show user 2.search  name of table  in current user model. answ ...

  2. vue-cli run dev 和 run build 出现的问题(运行项目、打包项目)

    前些天做项目,过程中遇到了一个比较奇怪的问题:npm run dev 和 npm run build 的时候,出现了错误,导致项目无法启动.打包无法成功.报了一堆错误: 错误展示: 找了一下解决方案, ...

  3. CentOS 7.3 下 Mysql(mariadb)的安装

    LNMP的安装中 Nginx的安装很简单,我一般去Nginx官方网站上下载对应版本的rpm包后,上传到终端rpm安装.再此不多赘述. 但是在CentOS7中安装最新的mysql(mariadb)却经常 ...

  4. June 07th 2017 Week 23rd Wednesday

    Failure is the condiment that gives success its flavor. 失败是让成功变美味的调味料. There are kinds of flavors in ...

  5. echarts固定柱子宽度(barWidth)

    series: [            {                name: '',                yAxisIndex: 0,                type: ' ...

  6. hdu-1452 Happy 2004---因子和+逆元

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1452 题目大意: 求2004^x次方的因子和mod29的值 解题思路: 首先2004 = 2 * 2 ...

  7. bzoj2111 [ZJOI2010]排列计数

    Description 称一个1,2,...,N的排列P1,P2...,Pn是Magic的,当且仅当2<=i<=N时,Pi>Pi/2. 计算1,2,...N的排列中有多少是Magic ...

  8. c#主窗体以及副窗体弹出

    在program.cs中,Form1的位置就是主窗体的位置(主窗体特征:关闭窗体应用程序结束) 弹出副窗口(点击按钮弹出窗口) Close为关闭窗口(关闭对应对象,需要先自己new一个) this.C ...

  9. WPF学习笔记(7):DataGrid中数字自定义格式显示

    DataGrid中数据显示如下图,数据格式比较杂乱.希望达到以下要求:(1)所有数据保留两位小数:(2)超过1000的数字显示千分位:(3)如果数据为0,不显示. 首先想到用StringFormat进 ...

  10. 微软.net framework 源码学习

    1. 直接下载.NET Framework源代码(下载地址),然后用Visual Studio打开查看. 2. 在线查看,网址:http://referencesource.microsoft.com ...