WA on test4 Help!!!

P3586 [POI2015] LOG

Hsj2022 @ 2024-05-14 13:48:01


#include <bits/stdc++.h>
#define int long long//已开long long
using namespace std;
const int N=1e6+10;
int n,m;
char op[N];//操作
int a[N],b[N];
int seq[N];//表示该序列
int q[N],tot;
int trc[N],trs[N];
int lowbit(int x)
{
    return x&-x;
}
void add(int tr[],int x,int v)
{
    for(int i=x;i<=n;i+=lowbit(i)) tr[i]+=v;
}
int query(int tr[],int x)
{
    int ans=0;
    for(int i=x;i;i-=lowbit(i)) ans+=tr[i];
    return ans;
}
signed main() 
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    //离线
    for(int i=1;i<=m;i++) 
    {
        cin>>op[i]>>a[i]>>b[i];
        q[++tot]=b[i];
    }
    sort(q+1,q+tot+1);
    tot=unique(q+1,q+tot+1)-(q+1);
    int len=0;//seq的实际长度
    for(int i=1;i<=m;i++)
    {
        b[i]=lower_bound(q+1,q+tot+1,b[i])-q;//lsh
        if(op[i]=='U')
        {
            int k=a[i],v=b[i];
            if(seq[k])//消除原有值
            {
                len--;
                add(trc,seq[k],-1);
                add(trs,seq[k],-q[seq[k]]);
            }
            seq[k]=0;
            if(!q[v]) continue;
            len++;
            seq[k]=v;
            add(trc,seq[k],1);
            add(trs,seq[k],q[seq[k]]);
        }
        else
        {
            int c=a[i],s=b[i];
            int cnt=len-query(trc,s-1);
            int sum=query(trs,s-1);
            if(sum>=(c-cnt)*q[s]) cout<<"TAK"<<endl;
            else cout<<"NIE"<<endl;
        }
    }
    return 0;
}

by Chancylaser @ 2024-10-29 12:05:18

@Hsj2022 你还没A,回来调题


|