BZOJ3932 任务查询系统

5 篇文章 0 订阅
3 篇文章 0 订阅

题意:懒得说了自己看吧:AC通道
题解:哎随便扯两句吧,一看就知道是主席树。先离散化,然后对于每个任务,在其左端点插入,右端点删除,每个询问只需稍微处理一下就可以了

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

const int inf=0x3f3f3f3f;

int getint()
{
    int f=1,g=0;char c=getchar();
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9')g=(g<<3)+(g<<1)+c-'0',c=getchar();
    return f*g;
}
int sgn(int x)
{
    return x>0?1:-1;
}

const int maxn=200005;
const int maxm=maxn*50;

struct node{
    int v,p;
    node(){}
    node(int v,int p):v(v),p(p){}
    bool operator < (const node &no)const
    {
        return v<no.v;
    }
};

int st[maxn];
int ed[maxn];

struct treenode{
    int v;
    ll sum;
    int lson,rson;
};

treenode T[maxm];

int n,m;

node t[maxn];
int mapping[maxn];
int cnt;
int pos[maxn];
int root[maxn];

#define mid (l+r>>1)

#define lc T[x].lson
#define rc T[x].rson

int tot=1;

void build(int x,int l,int r)
{
    if(l==r)return;
    lc=++tot;build(lc,l,mid);
    rc=++tot;build(rc,mid+1,r);
}

void modify(int x,int last,int l,int r,int p,int v)
{
    if(l==r){T[x].v=T[last].v+v;T[x].sum=T[last].sum+(ll)(mapping[p]*v);return;}
    if(p<=mid){lc=++tot;rc=T[last].rson;modify(lc,T[last].lson,l,mid,p,v);}
    else{rc=++tot;lc=T[last].lson;modify(rc,T[last].rson,mid+1,r,p,v);  }
    T[x].v=T[lc].v+T[rc].v;T[x].sum=T[lc].sum+T[rc].sum;
}

ll getans(int x,int l,int r,int k)
{
    if(l==r)return (ll)k*(ll)mapping[l];
    ll res=0;
    if(T[lc].v>=k)res+=getans(lc,l,mid,k);
    else res+=T[lc].sum+getans(rc,mid+1,r,k-T[lc].v);
    return res;
}

ll d[maxn];

ll ans=1;
ll res;

vector<int> g[maxn];

int main()
{
//  freopen("in.txt","r",stdin);

    m=getint();
    n=getint();

    for(int i=1;i<=m;i++)
    {
        st[i]=getint();
        ed[i]=getint();
        t[i].v=getint();
        t[i].p=i;
    }

    //puts("readin ok");

    sort(t+1,t+m+1);
    d[t[1].p]=++cnt;
    mapping[cnt]=t[1].v;
    for(int i=2;i<=m;i++)
    {
        if(t[i].v!=t[i-1].v)
        {
            cnt++;
        }
        d[t[i].p]=cnt;
        mapping[cnt]=t[i].v;
    }
    for(int i=1;i<=m;i++)
    {
        g[st[i]].push_back(d[i]);
        if(ed[i]!=n)g[ed[i]+1].push_back(-d[i]);
    }
    root[0]=1;
    build(root[0],1,cnt);

    for(int i=1;i<=n;i++)
    {
        for(vector<int>::iterator it=g[i].begin();it!=g[i].end();it++)
        {
            ++res;++tot;root[res]=tot;
            modify(root[res],root[res-1],1,cnt,abs(*it),sgn(*it));
        }
        pos[i]=res;
    }
    //puts("pre ok");
    int x,a,b,c;
    for(int i=1;i<=n;i++)
    {
        x=getint();
        a=getint();
        b=getint();
        c=getint();
        int k=1+(int)((((a%c)*(ans%c))%c)+(b%c))%c;
        if(T[root[pos[x]]].v<k)
        {
            printf("%lld\n",ans=getans(root[pos[x]],1,cnt,T[root[pos[x]]].v));
        }
        else
        {
            printf("%lld\n",ans=getans(root[pos[x]],1,cnt,k));
        }
    }

    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值