QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#369762#8286. StacksSolitaryDream#WA 8ms7000kbC++173.2kb2024-03-28 17:40:162024-03-28 17:40:19

Judging History

你现在查看的是最新测评结果

  • [2024-03-28 17:40:19]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:7000kb
  • [2024-03-28 17:40:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long

const int N=1e5+1e3+7;

int n,m;

int cnt;

struct T{
    int l,r,ls,rs;
    int cnt,rem,pmn,rsum;
    int v;
}t[N*2+1];

int qry(int x,int k)
{
    if(t[x].l==t[x].r)
        return t[x].v*k;
    if(k<t[t[x].ls].rem+t[t[x].rs].pmn)
        return qry(t[x].ls,k);
    else
    {
        if(t[t[x].ls].rem+t[t[x].rs].pmn>0ll)
            k-=t[t[x].ls].rem+t[t[x].rs].pmn;
        return qry(t[x].rs,k)+t[x].rsum;
    }
}

void update(int x)
{
    t[x].cnt=t[t[x].ls].cnt+t[t[x].rs].cnt;
    t[x].pmn=min(t[t[x].ls].pmn,t[t[x].rs].pmn+t[t[x].ls].cnt);
    t[x].rem=max(t[t[x].ls].rem+t[t[x].rs].pmn,0ll)+t[t[x].rs].rem;
    t[x].rsum=qry(t[x].ls,max(t[t[x].ls].rem+t[t[x].rs].pmn,0ll));
}

int build(int l,int r)
{
    int x=++cnt;
    t[x].l=l,t[x].r=r;
    int mid=(l+r)>>1;
    if(l==r)
        return x;
    t[x].ls=build(l,mid);
    t[x].rs=build(mid+1,r);
    return x;
}

void change(int x,int p,int s,int v)
{
    if(t[x].l==t[x].r)
    {
        t[x].v=v;
        t[x].cnt=s;
        t[x].pmn=min(0ll,s);
        t[x].rem=max(0ll,s);
        t[x].rsum=0ll;
        return;
    }
    int mid=(t[x].l+t[x].r)>>1;
    if(p<=mid)
        change(t[x].ls,p,s,v);
    else
        change(t[x].rs,p,s,v);
    update(x);
}

vector<int> V;

void getp(int x,int p)
{
    if(t[x].r<=p)
    {
        V.push_back(x);
        return;
    }
    int mid=(t[x].l+t[x].r)>>1;
    getp(t[x].ls,p);
    if(p>mid)
        getp(t[x].rs,p);
}

int solve(int p,int k)
{
    V.clear();
    getp(1,p);
    vector<int> e;
    int pmn=0ll;
    for(int i=V.size()-1;i>=0ll;i--)
    {
        e.push_back(pmn);
        int x=V[i];
        pmn=min(t[x].cnt+pmn,t[x].pmn);
    }
    reverse(e.begin(),e.end());
    int ret=0ll;
    for(int i=0ll;i<V.size();i++)
    {
        int x=V[i];
        int w=e[i];
        ret+=qry(x,min(k,max(t[x].rem-w,0ll)));
        k-=min(k,max(t[x].rem-w,0ll));
    }
    return ret;
}

vector<tuple<int,int,int> >o[N];

int ans[N];

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0ll);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int op;
        cin>>op;
        if(op==1)
        {
            int l,r,x,y;
            cin>>l>>r>>x>>y;
            o[l].push_back({i,x,y});
            o[r+1].push_back({i,0ll,0ll});
        }
        else if(op==2)
        {
            int l,r,w;
            cin>>l>>r>>w;
            o[l].push_back({i,-w,0ll});
            o[r+1].push_back({i,0ll,0ll});
        }
        else
        {
            int k,p,q;
            cin>>k>>p>>q;
            o[k].push_back({-i,p-1,-1});
            o[k].push_back({-i,q,1});
        }
        ans[i]=op==3?0ll:-114514;
    }
    build(1,m);
    for(int i=1;i<=n;i++)
    {
        for(auto [t,s,v]:o[i])
        {
            if(t<0ll)
                continue;
            change(1,t,s,v);   
        }
        for(auto [p,k,c]:o[i])
        {
            if(p>0ll)
                continue;
            ans[-p]+=c*solve(-p,k);
        }
    }
    for(int i=1;i<=m;i++)
    {
        if(ans[i]>=0ll)
            cout<<ans[i]<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 7000kb

input:

4907 4910
2 763 3330 1
3 307 1 1
1 2262 3430 22699 89397
1 1915 4000 51541 67587
2 212 2990 9763
2 1086 2162 1
2 1813 4496 16760
1 51 2796 68005 99390
1 1267 1519 74236 66178
3 1768 23808 54314
2 900 4122 27758
3 3287 17350 28989
2 3277 4024 3633
2 444 4866 1
2 353 4219 1061
1 987 3141 99906 17320
2...

output:

0
3032090730
903396180
471569175
200648623
1065522843
2242691487
1340955
50793012
129501640
67587
0
0
762429740
321140700
849873092
938761666
9269857392
0
1792521566
6640518748
2415375780
1392164758
225987900
5250788038
1145132507
140071334
76086
118545795
3086405469
5646099271
178747954
1232466642
...

result:

wrong answer 6th numbers differ - expected: '98486697', found: '1065522843'