QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#361135#8229. 栈Wuyanru0 0ms18424kbC++144.6kb2024-03-22 20:26:402024-03-22 20:26:40

Judging History

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

  • [2024-03-22 20:26:40]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:18424kb
  • [2024-03-22 20:26:40]
  • 提交

answer

#include<bits/stdc++.h>
#define inf 0x3f3f3f3f3f3f3f3fll
#define debug(x) cerr<<#x<<"="<<x<<endl
using namespace std;
using ll=long long;
using ld=long double;
using pli=pair<ll,int>;
using pi=pair<int,int>;
using pal=pair<ll,ll>;
template<typename A>
using vc=vector<A>;
inline int read()
{
    int s=0,w=1;char ch;
    while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
inline ll lread()
{
    ll s=0,w=1;char ch;
    while((ch=getchar())>'9'||ch<'0') if(ch=='-') w=-1;
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
namespace S
{
    ll rest[400001];
    ll sum[400001];
    ll lrest[400001];
    ll lsum[400001];
    ll e[400001];
    pal push_up(int p,int pl,int pr,ll re)
    {
        // printf("push_up %d %d %d %lld : %lld %lld\n",p,pl,pr,re,rest[p],sum[p]);
        assert(re>=0);
        if(rest[p]<=re) return pal(0,0);
        if(pl==pr)
        {
            int val=sum[p]/rest[p];
            return pal(rest[p]-re,(rest[p]-re)*val);
        }
        int mid=(pl+pr)>>1;
        if(sum[p*2|1])
        {
            auto val=push_up(p*2|1,mid+1,pr,re);
            return pal(val.first+lrest[p],val.second+lsum[p]);
        }
        return push_up(p*2,pl,mid,re-sum[p*2|1]+e[p*2|1]);
    }
    void add(int p,int pl,int pr,int x,int c,int v)
    {
        // printf("add %d %d %d %d %d %d\n",p,pl,pr,x,c,v);
        if(pl==pr)
        {
            if(v==-1) e[p]+=c;
            else
            {
                rest[p]+=c;
                sum[p]+=(ll)c*v;
            }
            // printf("%d : %d : %lld %lld %lld\n",p,pl,rest[p],sum[p],e[p]);
            return ;
        }
        int mid=(pl+pr)>>1;
        if(x<=mid) add(p*2,pl,mid,x,c,v);
        else add(p*2|1,mid+1,pr,x,c,v);
        assert(e[p*2|1]>=0);
        auto val=push_up(p*2,pl,mid,e[p*2|1]);
        lrest[p]=val.first,lsum[p]=val.second;
        rest[p]=lrest[p]+rest[p*2|1];
        sum[p]=lsum[p]+sum[p*2|1];
        e[p]=e[p*2]+e[p*2|1]-(rest[p*2]-lrest[p]);
        // printf("%d : %d ~ %d : %lld %lld %lld\n",p,pl,pr,rest[p],sum[p],e[p]);
    }
    pal getp(int p,int pl,int pr,int l,int r,ll re)
    {
        // printf("getp %d %d %d %d %d %lld\n",p,pl,pr,l,r,re);
        if(l<=pl&&pr<=r) return pal(max(rest[p]-re,0ll),max(re-rest[p],0ll)+e[p]);
        int mid=(pl+pr)>>1;pal ans=pal(0,re);
        if(mid<r)
        {
            auto val=getp(p*2|1,mid+1,pr,l,r,ans.second);
            ans.first+=val.first,ans.second=val.second;
        }
        if(l<=mid)
        {
            auto val=getp(p*2,pl,mid,l,r,ans.second);
            ans.first+=val.first,ans.second=val.second;
        }
        // printf("%d : %d %d %d %d %lld : %lld %lld\n",p,pl,pr,l,r,re,ans.first,ans.second);
        return ans;
    }
    ll get(int p,int pl,int pr,int lim,ll l,ll r,ll re)
    {
        // printf("get %d %d %d %d %lld %lld %lld\n",p,pl,pr,lim,l,r,re);
        assert(lim>=pl);
        if(pl==pr)
        {
            ll num=sum[p]/rest[p];
            return (r-l+1)*num;
        }
        pal v1,v2=pal(0,re);ll ans=0;
        int mid=(pl+pr)>>1;
        if(mid<lim) v2=getp(p*2|1,mid+1,pr,1,lim,re);
        v1=getp(p*2,pl,mid,1,lim,v2.second);
        r=min(r,v1.first+v2.first);
        // printf("(%lld,%lld) and (%lld,%lld) : r=%lld\n",v1.first,v1.second,v2.first,v2.second,r);

        if(v1.first>=l) ans+=get(p*2,pl,mid,lim,l,min(r,v1.first),v2.second);
        l=max(l-v1.first,1ll),r-=v1.first;
        if(l<=r) ans+=get(p*2|1,mid+1,pr,lim,l,r,v2.second);
        return ans;
    }
}
struct node
{
    int tim;
    ll x,y;
};
vc<node>ned[100002];
vc<node>nod[100002];
ll qans[100002];
int n,m;
inline void run(int w)
{
    // printf("run %d\n",w);
    for(auto i:nod[w]) S::add(1,1,m,i.tim,i.x,i.y);
    for(auto i:ned[w]) qans[i.tim]=S::get(1,1,m,i.tim,i.x,i.y,0);
}
int main()
{
    n=read(),m=read();
    for(int i=1;i<=m;i++)
    {
        int op=read();qans[i]=-1;
        if(op==1)
        {
            int l=read(),r=read(),x=read(),y=read();
            nod[l].push_back(node{i,x,y});
            nod[r+1].push_back(node{i,-x,y});
        }
        else if(op==2)
        {
            int l=read(),r=read(),x=read(),y=-1;
            nod[l].push_back(node{i,x,y});
            nod[r+1].push_back(node{i,-x,y});
        }
        else
        {
            int x=read();ll l=lread(),r=lread();
            ned[x].push_back(node{i,l,r});
        }
    }
    for(int i=1;i<=n;i++) run(i);
    for(int i=1;i<=m;i++) if(qans[i]!=-1) printf("%lld\n",qans[i]);
    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 18424kb

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
0
477111789
0
50793012
0
0
0
0
762429740
0
0
81537640
5189092517
0
1792521566
6640460369
2415375780
0
0
4740312163
0
0
0
118545795
186015621
2196193867
0
0
456696661
4292678692
3118737050
0
0
3320848040
0
0
0
1085140020
0
0
0
0
0
0
0
0
0
5723142025
0
0
0
0
...

result:

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

Subtask #2:

score: 0
Time Limit Exceeded

Test #6:

score: 0
Time Limit Exceeded

input:

99999 99998
1 5026 18575 27178 90423
3 30623 1 1
3 76936 1 1
1 77021 95683 84664 24734
1 46085 74886 40512 11266
3 5048 8594 22468
1 53318 77721 97151 70784
1 70645 91192 37556 13013
1 56752 56940 91812 62887
1 7928 34576 87339 69404
3 74875 32807 100970
3 22338 17221 25771
3 21421 20602 57957
3 717...

output:


result:


Subtask #3:

score: 0
Runtime Error

Test #12:

score: 0
Runtime Error

input:

100000 99993
1 47773 70467 16065 1
2 52349 78446 2304
3 40821 1 1
1 40216 93069 78144 1
1 41089 43671 76025 1
2 35263 68629 31066
3 79881 13534 57327
3 5556 1 1
2 21962 38192 1
1 664 58116 9417 1
3 28089 6039 7989
2 88500 90302 9946
3 63215 49410 60770
2 11069 89527 57581
2 70303 97603 12363
1 3420 ...

output:


result:


Subtask #4:

score: 0
Runtime Error

Test #17:

score: 0
Runtime Error

input:

99999 99996
3 77889 1 10000000000
1 6316 86327 89644 386
3 9260 1 10000000000
2 2603 47234 69717
2 20260 73011 19290
2 62477 81233 26127
1 50140 68508 37004 98794
2 14449 22788 16063
1 43860 84932 50375 21777
1 67345 94584 28202 66610
2 661 68654 1
1 14411 94422 82738 61196
1 16563 94416 4920 38408
...

output:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%