一、题意

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

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

    acct 中文man页面(1) 2011-08-18 13:57 佚名 博客转载 我要评论(0) 字号:T | T 如果在内核编译时开启了进程记账选项(CONFIG_BSD_PROCESS_ACCT) ...

  2. 一个程序猿试用有道云笔记VIP功能体验

    熟悉我的朋友应该知道,我有一个微信公众号,叫做"汪子熙", 我会定期在上面推送技术文章. 而我绝大多数技术文章都是在每天上下班的地铁上用手机写的,然后到家后同步到电脑上,进行发表. ...

  3. LA 4043 最优匹配

    题目链接:https://vjudge.net/contest/161820#problem/A 题意: n 个 白点,n 个黑点,给出了坐标,求完美匹配后,各点不相交,输出白点对于的黑点编号:(输出 ...

  4. 布局方式-flex布局

    .弹性盒子 .盒子本来就是并列的 .指定宽度即可 <style> .container { width: 800px; height: 200px; display: flex; bord ...

  5. springboot(服务端接口)获取URL请求参数的几种方法

    原文地址:http://www.cnblogs.com/xiaoxi/p/5695783.html 一.下面为7种服务端获取前端传过来的参数的方法  常用的方法为:@RequestParam和@Req ...

  6. 【转】android ListView详解

    由于google doc 很多人都打不开,故更新了源码下载地址 [源码下载]----2011-01-18 在android开发中ListView是比较常用的组件,它以列表的形式展示具体内容,并且能够根 ...

  7. Mysql索引学习笔记

    1.btree索引与hash索引 下列范围查询适用于 btree索引和hash索引: SELECT * FROM t1 WHERE key_col = 1 OR key_col IN (15,18,2 ...

  8. C# DataSet.Designer.cs

    今天在做项目的时候,发现一个很奇葩的问题,VS 中DataSet数据集的问题Dataset数据集更新,在保存后原有的Dataset.Designer.cs不变,又增加一个新的Dataset1.Desi ...

  9. PL/SQL知识点

    1.ROW_NUMBER() OVER(PARTITION BY XXX ORDER BY XXX) SELECT STP.FLOW_INST_ID, BUU.USER_NAME, ORGG.NAME ...

  10. ProjectServer任务审批后自动发布

    我们知道ProjectServer汇报工时的顺序是这样: 1.项目成员打开自己的时间表,选择要汇报的任务,在汇报工时栏填写实际工时. 2.汇报工时后点击保存. 3.将汇报工时的任务提交给项目经理. 4 ...