牛客暑假多校第六场I-Team Rocket
一、题意
我们是穿越银河的火箭队.......
给出若干个区间,之后给出若干个点,要求对每个点求出,第一个覆盖点的区间的数量,之后用当前所有点覆盖的区间的序号的乘积结合输入的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的更多相关文章
- 牛客暑假多校第六场 I Team Rocket
题意: 现在有n条火车, 每条火车都有一个运行 [ Li, Ri ], 现在有m支火箭队, 每次火箭队都会破坏这整条铁路上的一个点, 如果一条火车的运行区间[Li, Ri] 被破坏了, 那么这条火车会 ...
- 2018牛客多校第六场 I.Team Rocket
题意: 给出n个区间和m个点(点按顺序给出且强制在线).每个区间只会被第一个他包含的点摧毁.问每个点能摧毁多少个区间以及每个区间是被哪个点摧毁的. 题解: 将n个区间按照左端点排序,然后用vector ...
- 牛客暑假多校第五场A.gpa
一.题意 给出你的N门课程的考试成绩和所占的机电数目.允许你放弃K门课的成绩,要求你的平均学分绩最高能达到多少. Kanade selected n courses in the university ...
- 牛客2018多校第六场 J Heritage of skywalkert - nth_element
传送门 题意:提供一个随机生成函数,让你生成n个数,然后问你其中能找到的两个数的最小公倍数 最大 是多少. 思路:可以用nth_element()函数在O(n)下求出前 15 个大的数(当然,100个 ...
- 牛客暑假多校第五场 D inv
题意:给你一个n, 接来下给你一个 [1,n] 中偶数的排列, 还有一个 [1, n] 中 奇数 按照递增的顺序排列, 现在求一个原数列, 使得偶数列排序 和 奇数列 都是原数列的一个子序列, 现在求 ...
- 牛客暑假多校第五场 I vcd
这个题目一个队友没读懂, 然后我读错了题目, 还让他堆了半天的公式写了半天的代码, 交上去一直0.0, 另一队友问题目有没有读错, 我坚持没有读错, 然后坑了2个小时的时间,不然应该会早一点做出来. ...
- 2019牛客暑期多校第六场题解ABDJ
A.Garbage Classification 传送门 题意:给你两个串,第一个串s由小写字母组成,第二个串t由dwh组成,长度为26,分别表示字母a到z代表的字符.现在要你判断: 如果字符串中‘h ...
- 2020牛客暑假多校训练营 第二场 H Happy Triangle set 线段树 分类讨论
LINK:Happy Triangle 这道题很容易. 容易想到 a+b<x a<x<b x<a<b 其中等于的情况在第一个和第三个之中判一下即可. 前面两个容易想到se ...
- 2020牛客暑假多校训练营 第二场 G Greater and Greater bitset
LINK:Greater and Greater 确实没能想到做法. 考虑利用bitset解决问题. 做法是:逐位判断每一位是否合法 第一位 就是 bitset上所有大于\(b_1\)的位置 置为1. ...
随机推荐
- Perl实用中文处理步骤(修改版)
发信人: FenRagwort (泽), 信区: Perl标 题: Perl实用中文处理步骤(修改版)发信站: 水木社区 (Mon Feb 14 12:52:14 2011), 转信 (修改版 感谢 ...
- 类型系统(type system)是一门编程语言最核心也是最基础的部分---编程语言最终的目标,本质上无非是回答两个问题:如何表示信息、如何处理信息
https://www.cnblogs.com/feng9exe/p/9712059.html 类型系统(type system)是一门编程语言最核心也是最基础的部分.无论该语言基于何种编程范式,都必 ...
- HASH JION AND NESTED JION
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/sssbbbryj/article/details/27795905 关于HASH_JION的原 ...
- lua 语句学习
就如同C里的if else,while,do,repeat.就看lua里怎么用: 1.首先看if else t = {1,2,3} local i = 1 if t[i] and t[i] % 2 = ...
- LA 4987 背包
题意: 有n个施工队,给定他们的位置,有m个防空洞,给定位置,求将施工队放到m个防空洞里面,最少的总距离? n<=4000 分析: dp[i][j] 前 i 个施工队,放到前 j 个防空洞里面的 ...
- HDU 1045 Fire Net 【连通块的压缩 二分图匹配】
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit: 2000/1000 MS (Java/Others) ...
- Jmeter 登陆性能测试
1.打开Jmeter,新建一个线程组:测试计划--添加--Threads(users)---线程组 如图: 2.首先要添加一个HTTP默认请求,为什么要添加这个呢? 如果要测试的系统域名或者IP地址是 ...
- Git命令篇
前文: Git有三种状态,你的文件可能处于其中之一:已提交(committed),已修改(modiffied)和已暂存(staged) 三个工作区域概念:Git仓库.工作目录以及暂存区 Git保存信息 ...
- Unity3d Gis 坐标转换
最近在做unity3d与Gis结合的项目,最基本的就是坐标的转换问题,比如把经纬度为(166.23.9.27 , 39.55.15.74) 转换到unity里面成相应的位置点,废话不多说 上代码: u ...
- focal loss for dense object detection
温故知新 focal loss for dense object detection,知乎上一人的评论很经典.hard negative sampling, 就是只挑出来男神(还是最难追的),而foc ...