牛客网暑期ACM多校训练营(第六场)I Team Rocket

链接:https://www.nowcoder.com/acm/contest/144/I
来源:牛客网
 

题目描述

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.

输入描述:

The input starts with one line containing exactly one integer T, which is the number of test cases.

For each test case, the first line contains two integers n and m, indicating the number of trains and the number of Team Rocket members.

Each of the next n lines contains 2 integers li and ri, indicating the driving range of the i-th train.

Each of the next m lines contains exactly one integer yi. , where xi is the transportation hub that Team Rocket members would destroy in the i-th attack, resi-1 is the product of the indexes of trips cancelled by the (i-1)-th attack and  means exclusive or. 

If no such trip exists, resi-1 is considered to be 0.

- 1 ≤ T ≤ 5.
- 1 ≤ n,m ≤ 2 x 105.
- -109 ≤ li ≤ ri ≤ 109.
- -109 ≤ xi ≤ 109.

输出描述:

For each test case, output one line "Case #x:" first, where x is the test case number (starting from 1).

Then output m lines, each line of which contains exactly one integer, indicating the number of train trips firstly canceled after the i-th attack.

Finally output one line, containing n integers, where the i-th integer is the time when the i-th train trip is firstly canceled or 0 if it is not affected.

示例1

输入

复制

1
3 4
1 3
2 6
-999 1000000000
-1000
1
5
2

输出

复制

Case #1:
0
2
1
0
2 3 2

题意:给n个线段m次破坏,每次破坏那一点,问每次会破坏多少条线段

解法:sort左端点,然后右端点建树,sort之后从当前1到当前位置的线段有可能被破坏,这取决于右端点的位置。

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
const int MOD=998244353;
int ora[maxn],ans[maxn],cnt,clk;
long long res;
struct node{int l,r,num;}tree[maxn<<2];
struct node1{int l,r,id;}zdy[maxn];
bool cmp(node1 a,node1 b){return a.l<b.l;}
void pushup(int rt)
{
    tree[rt].num=max(tree[rt<<1].num,tree[rt<<1|1].num);
}
void build(int l,int r,int rt)
{
    tree[rt].l=l,tree[rt].r=r;
    if(l==r){tree[rt].num=zdy[l].r;return;}
    int mid=(l+r)>>1;
    build(l,mid,rt<<1);
    build(mid+1,r,rt<<1|1);
    pushup(rt);
}
void update(int x,int y,int rt,int v)
{
    if(tree[rt].l>y||tree[rt].r<x)return;
    if(x<=tree[rt].l&&tree[rt].r<=y&&tree[rt].num<v)return;
    if(tree[rt].l==tree[rt].r)
    {
        cnt++;
        res=res*zdy[tree[rt].l].id%MOD;
        tree[rt].num=-1e9-7;
        ans[zdy[tree[rt].l].id]=clk;
        return;
    }
    update(x,y,rt<<1,v);
    update(x,y,rt<<1|1,v);
    pushup(rt);
}
int main()
{
    int T,n,m,t=1;
    scanf("%d",&T);
    while(T--)
    {
        memset(ans,0,sizeof(ans));
        scanf("%d%d",&n,&m);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d",&zdy[i].l,&zdy[i].r);
            ora[i]=zdy[i].l;
            zdy[i].id=i;
        }
        sort(zdy+1,zdy+n+1,cmp);
        sort(ora+1,ora+n+1);
        build(1,n,1);
        printf("Case #%d:\n",t++);
        res=0,clk=0;
        for(int i=0;i<m;i++)
        {
            int t1;
            scanf("%d",&t1);
            t1^=res;
            int pos=upper_bound(ora+1,ora+n+1,t1)-ora-1;
            res=1;
            cnt=0;
            clk++;
            update(1,pos,1,t1);
            if(cnt==0)res=0;
            printf("%d\n",cnt);
        }
        for(int i=1;i<=n;i++)printf("%d%c",ans[i],i==n?'\n':' ');
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/ljq199926/article/details/81448984