QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#361151#8229. 栈XY_Eleven0 153ms31000kbC++235.8kb2024-03-22 20:46:082024-03-22 20:46:11

Judging History

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

  • [2024-03-22 20:46:11]
  • 评测
  • 测评结果:0
  • 用时:153ms
  • 内存:31000kb
  • [2024-03-22 20:46:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(3)
#define DB double
#define LL long long
#define ULL unsigned long long
#define in128 __int128
#define cint const int
#define cLL const LL
#define For(z,e1,e2) for(int z=(e1);z<=(e2);z++)
#define Rof(z,e1,e2) for(int z=(e2);z>=(e1);z--)
#define For_(z,e1,e2) for(int z=(e1);z<(e2);z++)
#define Rof_(z,e1,e2) for(int z=(e2);z>(e1);z--)
#define inint(e) scanf("%d",&e)
#define inll(e) scanf("%lld",&e)
#define inpr(e1,e2) scanf("%d%d",&e1,&e2)
#define in3(e1,e2,e3) scanf("%d%d%d",&e1,&e2,&e3)
#define outint(e) printf("%d\n",e)
#define outint_(e) printf("%d%c",e," \n"[i==n])
#define outint2_(e,e1,e2) printf("%d%c",e," \n"[(e1)==(e2)])
#define outll(e) printf("%lld\n",e)
#define outll_(e) printf("%lld%c",e," \n"[i==n])
#define outll2_(e,e1,e2) printf("%lld%c",e," \n"[(e1)==(e2)])
#define exc(e) if(e) continue
#define stop(e) if(e) break
#define ret(e) if(e) return
#define ll(e) (1ll*(e))
#define pb push_back
#define ft first
#define sc second
#define clean(e) while(!e.empty()) e.pop()
#define all(ev) ev.begin(),ev.end()
#define sz(ev) ((int)ev.size())
#define debug(x) printf("%s=%d\n",#x,x)
#define x0 _x0_
#define y1 _y1_
#define ffo fflush(stdout)
cLL mod=998244353,G=404;
template <typename Type> void get_min(Type &w1,const Type w2) { if(w2<w1) w1=w2; }
template <typename Type> void get_max(Type &w1,const Type w2) { if(w2>w1) w1=w2; }
template <typename Type> Type up_div(Type w1,Type w2) { return (w1/w2+(w1%w2?1:0)); }
template <typename Type> Type gcd(Type X_,Type Y_) { Type R_=X_%Y_; while(R_) { X_=Y_; Y_=R_; R_=X_%Y_; } return Y_; }
template <typename Type> Type lcm(Type X_,Type Y_) { return (X_/gcd(X_,Y_)*Y_); }
template <typename Type> Type md(Type w1,const Type w2=mod) { w1%=w2; if(w1<0) w1+=w2; return w1; }
template <typename Type> Type md_(Type w1,const Type w2=mod) { w1%=w2; if(w1<=0) w1+=w2; return w1; }
void ex_gcd(LL &X_,LL &Y_,LL A_,LL B_)
{ if(!B_) { X_=1ll; Y_=0ll; return ; } ex_gcd(Y_,X_,B_,A_%B_); X_=md(X_,B_); Y_=(1ll-X_*A_)/B_; }
LL inv(LL A_,LL B_=mod) { LL X_=0ll,Y_=0ll; ex_gcd(X_,Y_,A_,B_); return X_; }
template <typename Type> void add(Type &w1,const Type w2,const Type M_=mod) { w1=md(w1+w2,M_); }
void mul(LL &w1,cLL w2,cLL M_=mod) { w1=md(w1*md(w2,M_),M_); }
template <typename Type> Type pw(Type X_,Type Y_,Type M_=mod) { Type S_=1; while(Y_) { if(Y_&1) mul(S_,X_,M_); Y_>>=1; mul(X_,X_,M_); } return S_; }
mt19937 gen(time(NULL)); int rd() { return abs((int)gen()); }
cint N=1.02e5;
int n,Q;
vector <pair<int,pair<LL,LL> > > q[N];
vector <int> v[N];
array <LL,2> a[N];
struct Node
{
    int l,r,mid;
    LL ls,rs,sum,sum2,lcnt;
}t[N<<2|1];
void bld(int p,int l,int r)
{
    int mid=l+r>>1;
    t[p]={l,r,mid,0ll,0ll,0ll,0ll,0ll};
    ret(l>=r);
    bld(p<<1,l,mid),bld(p<<1|1,mid+1,r);
}
LL ans[N];
bool vis[N],b[N];
int K;
void setf(int p,int k)
{
    if(vis[k])
        t[p].ls=t[p].rs=t[p].sum=0ll;
    else
    {
        if(b[k]) t[p].rs=a[k][0],t[p].sum=a[k][0]*a[k][1];
        else t[p].ls=a[k][0];
    }
    vis[k]=!vis[k];
}
LL work(int p,LL c)
{
    if(t[p].l>=t[p].r) return c*a[t[p].l][0];
    if(c<=t[p].lcnt) return work(p<<1,c);
    else return (work(p<<1|1,c-t[p].lcnt)+t[p].sum2);
}
pair <array <LL,2>,LL> sum(int p1,int p2)
{
    if(t[p2].ls>=t[p1].rs) return {{t[p1].ls+(t[p2].ls-t[p1].rs)},t[p2].sum};
    return {{t[p1].ls,t[p2].rs+(t[p1].rs-t[p2].ls)},t[p2].sum+work(p1,t[p1].rs-t[p2].ls)};
}
void pup(int p)
{
    t[p].sum2=work(p<<1,t[p].lcnt=max(t[p<<1].ls-t[p<<1|1].rs,0ll));
    auto w=sum(p<<1,p<<1|1);
    t[p].ls=w.ft[0],t[p].rs=w.ft[1],t[p].sum=w.sc;
}
void change(int p)
{
    if(t[p].l>=t[p].r)
    {
        setf(p,K);
        return ;
    }
    change(p<<1|(K>t[p].mid));
    pup(p);
}
void Change(int k)
{
    K=k;
    change(1);
}
int L,R;
vector <int> g;
void qry(int p)
{
    if(L<=t[p].l&&t[p].r<=R)
    {
        g.pb(p);
        return ;
    }
    if(L<=t[p].mid) qry(p<<1);
    if(R>t[p].mid) qry(p<<1|1);
}
stack <pair<int,LL> > st;
LL Qry(int k,LL c)
{
    // printf("query %d,%lld\n",k,c);
    L=1,R=k,g.clear();
    qry(1);
    clean(st);
    LL sum=0ll;
    for(auto i:g)
    {
        LL w=t[i].ls;
        while(!st.empty()&&w>=st.top().sc)
            w-=st.top().sc,st.pop();
        if(!st.empty()) st.top().sc-=w;
        st.push({i,t[i].rs});
    }
    while(!st.empty())
    {
        int p=st.top().ft; LL c2=st.top().sc;
        get_min(c2,c); c-=c2;
        st.pop();
        // printf("[%d,%d]:%lld\n",t[p].l,t[p].r,c2);
        sum+=work(p,c2);
    }
    return sum;
}
void main_solve()
{
    inpr(n,Q);
    int opt;
    For(i,1,Q)
    {
        inint(opt);
        if(opt==3)
        {
            int k; LL l,r;
            scanf("%d%lld%lld",&k,&l,&r);
            q[k].pb({i,{l,r}});
        }
        else
        {
            int l,r; inpr(l,r);
            v[l].pb(i),v[r+1].pb(i);
            if(opt==1)
            {
                LL c,w; scanf("%lld%lld",&c,&w);
                a[i]={c,w};
            }
            else
            {
                LL c; scanf("%lld",&c);
                a[i]={c,0ll};
            }
            b[i]=(i==1);
        }
    }
    bld(1,1,n);
    memset(ans,0xff,(Q+1)*sizeof(LL));
    For(i,1,n)
    {
        for(auto j:v[i]) Change(j);
        for(auto [id,c]:q[i])
            ans[id]=Qry(id,c.sc)-Qry(id,c.ft-1ll);
    }
    For(i,1,Q) if(ans[i]!=-1ll)
        outll(ans[i]);
}
int main()
{
    // ios::sync_with_stdio(0); cin.tie(0);
    // freopen("in.txt","r",stdin);
    // freopen("out1.txt","w",stdout);
    // rsand(time(NULL));
    // main_init();
    // int _; inint(_); For(__,1,_) // T>1 ?
        // printf("\n------------\n\n"),
        main_solve();
    return 0;
}
/*
2 2 2 1 1
*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 8408kb

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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 2nd numbers differ - expected: '3032090730', found: '0'

Subtask #2:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 141ms
memory: 30912kb

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:

0
0
1174713000
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

wrong answer 3rd numbers differ - expected: '1254619125', found: '1174713000'

Subtask #3:

score: 0
Wrong Answer

Test #12:

score: 0
Wrong Answer
time: 153ms
memory: 30680kb

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:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 2nd numbers differ - expected: '43794', found: '0'

Subtask #4:

score: 0
Wrong Answer

Test #17:

score: 0
Wrong Answer
time: 153ms
memory: 31000kb

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:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 2nd numbers differ - expected: '34602584', found: '0'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%