求助 Last Point

P3586 [POI2015] LOG

Lucifero @ 2021-03-13 10:48:41

#include <bits/stdc++.h>
#define int long long
#define tls tree[p].ls
#define trs tree[p].rs
using namespace std;
const int S=1e9;
class SegmentTree
{
public:
    int ls,rs;
    int cnt,v;
}tree[8000001];
char opt[2];
int a[200001],n,cnt(1),t1,t2;
void open(int p,int l,int r,int k,int d)
{
    if (l==r)
    {
        tree[p].v+=d*k;
        tree[p].cnt+=d;
        return;
    }
    int mid=(l+r)>>1;
    if (mid>=k)
    {
        if (tls==0) tls=++cnt;
        open(tls,l,mid,k,d);
    }
    else
    {
        if (trs==0) trs=++cnt;
        open(trs,mid+1,r,k,d);
    }
    tree[p].v=tree[tls].v+tree[trs].v;
    tree[p].cnt=tree[tls].cnt+tree[trs].cnt;
}
int times(int p,int l,int r,int x,int y)
{
    if (l>=x && r<=y)
        return tree[p].cnt;
    int mid=(l+r)>>1;
    if (mid<x)
        return times(trs,mid+1,r,x,y);
    if (mid>=y)
        return times(tls,l,mid,x,y);
    return times(tls,l,mid,x,y)+times(trs,mid+1,r,x,y);
}
int sum(int p,int l,int r,int x,int y)
{
    if (l>=x && r<=y)
        return tree[p].v;
    int mid=(l+r)>>1;
    if (mid<x)
        return sum(trs,mid+1,r,x,y);
    if (mid>=y)
        return sum(tls,l,mid,x,y);
    return sum(tls,l,mid,x,y)+sum(trs,mid+1,r,x,y);
}
signed main()
{
    //工资管理
    int m,x,y;
    scanf("%lld%lld",&n,&m);
    while(m--)
    {
        scanf("%s%lld%lld",opt,&x,&y);
        if (opt[0]=='U')
        {
            if (a[x]!=0)
                open(1,1,S,a[x],-1);
            a[x]=y;
            if (a[x]!=0)
                open(1,1,S,a[x],1);
        }
        else if (opt[0]=='Z')
        {
            t1=times(1,1,S,y+1,S);
            t1=x-t1,t1*=y;
            t2=sum(1,1,S,1,y);
            printf((t2>=t1)?"TAK":"NIE");
            printf("\n");
        }
    }
}

by Leasier @ 2021-03-14 16:02:46

@Gray_White orz


|