QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#403747#70. Bitaro, who Leaps through TimeRafi220 1ms3756kbC++144.0kb2024-05-02 18:22:072024-05-02 18:22:07

Judging History

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

  • [2024-05-02 18:22:07]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3756kb
  • [2024-05-02 18:22:07]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;
int inf=1000000000000000007;
int mod=1000000007;
int mod1=998244353;

const int N=300007,pot=1<<10;

struct S
{
    int l=-inf,r=inf,x=-1,y=-1,sum=0;
};

int l1[N],r1[N];
int l2[N],r2[N];

S Merge(S L,S R)
{
    if(L.x!=-1)
    {
        if(R.x!=-1) return {0,0,L.x,R.y,L.sum+R.sum+max(0LL,L.y-R.x)};
        else
        {
            if(L.y<R.l) return {0,0,L.x,R.l,L.sum+R.sum};
            else if(L.y>R.r) return {0,0,L.x,R.r,L.sum+R.sum+L.y-R.r};
            else return {0,0,L.x,L.y,L.sum+R.sum};
        }
    }
    else
    {
        if(R.x!=-1)
        {
            if(R.x<L.l) return {0,0,L.l,R.y,L.sum+R.sum+L.l-R.x};
            else if(R.x>L.r) return {0,0,L.r,R.y,L.sum+R.sum};
            else return {0,0,R.x,R.y,L.sum+R.sum};
        }
        else
        {
            if(L.r<R.l) return {0,0,L.r,R.l,0};
            else if(L.l>R.r) return {0,0,L.l,R.r,L.l-R.r};
            else return {max(L.l,R.l),min(L.r,R.r),-1,-1,0};
        }
    }
}



struct T
{
    S seg[2*pot+7];
    T()
    {
        for(int j=1;j<2*pot;j++) seg[j]={-inf,inf,-1,-1,0};
    }
    void upd(int v)
    {
        seg[v+pot-1]= {l1[v],r1[v],-1,-1,0};
        v+=pot-1;
        while(v>1)
        {
            v/=2;
            seg[v]=Merge(seg[2*v],seg[2*v+1]);
        }
    }
    S que(int v,int a,int b,int l,int r)
    {
        if(a<=l&&b>=r) return seg[v];
        if(r<a||l>b) return {-inf,inf,-1,-1,0};
        return Merge(que(2*v,a,b,l,(l+r)/2),que(2*v+1,a,b,(l+r)/2+1,r));
    }
};



signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,q,l,r;
    cin>>n>>q;
    T T1,T2;
    for(int i=1;i<n;i++)
    {
        cin>>l>>r;
        r--;
        l1[i]=l+n-i;
        r1[i]=r+n-i;
        T1.seg[i+pot-1]={l1[i],r1[i],-1,-1,0};
        l2[i]=l+i+1;
        r2[i]=r+i+1;
        T2.seg[n-i+pot-1]={l2[i],r2[i],-1,-1,0};
    }
    for(int i=pot-1;i>0;i--)
    {
        T1.seg[i]=Merge(T1.seg[2*i],T1.seg[2*i+1]);
        T2.seg[i]=Merge(T2.seg[2*i],T2.seg[2*i+1]);
    }
    while(q--)
    {
        int t;
        cin>>t;
        if(t==1)
        {
            int i;
            cin>>i;
            cin>>l>>r;
            r--;
            l1[i]=l+n-i;
            r1[i]=r+n-i;
            T1.upd(i);
            l2[i]=l+i+1;
            r2[i]=r+i+1;
            T2.upd(n-i);
        }
        else
        {
            int a,b,c,d,ans=0;
            cin>>a>>b>>c>>d;
            if(a<=c)
            {
                b+=n-a;
                d+=n-c;
                S p=T1.que(1,a,c-1,1,pot);
                ans+=p.sum;
                if(p.x!=-1)
                {
                    ans+=max(0LL,b-p.x);
                    ans+=max(0LL,p.y-d);
                }
                else
                {
                    if(b>p.r)
                    {
                        ans+=b-p.r;
                        b=p.r;
                    }
                    else if(b<p.l) b=p.l;
                    ans+=max(0LL,b-d);
                }
            }
            else
            {
                b+=a;
                d+=c;
                a=n-a+1;
                c=n-c+1;
                S p=T2.que(1,a,c-1,1,pot);
                ans+=p.sum;
                if(p.x!=-1)
                {
                    ans+=max(0LL,b-p.x);
                    ans+=max(0LL,p.y-d);
                }
                else
                {
                    if(b>p.r)
                    {
                        ans+=b-p.r;
                        b=p.r;
                    }
                    else if(b<p.l) b=p.l;
                    ans+=max(0LL,b-d);
                }
            }
            cout<<ans<<endl;
        }
    }



    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3756kb

input:

20 18
115497790 671208773
326245299 528973482
100582193 437996818
89058008 771100620
768935396 842907844
187943946 997369106
455078418 542835554
536691525 970171971
564540350 570234421
657178750 753833933
386375484 979995375
389681484 772601117
634873482 897954663
87193815 139420775
259946990 394597...

output:

1155445816
286505553
517757980
236944355
561949186
106582836
0
262581028
191096499

result:

wrong answer 8th lines differ - expected: '304461403', found: '262581028'

Subtask #2:

score: 0
Runtime Error

Test #42:

score: 0
Runtime Error

input:

274318 300000
489215489 676617321
780126019 788585486
556851007 580284394
233372413 595198772
519202713 898223077
502895565 696411826
206200999 769856900
270143414 346344669
729812429 901771242
663771137 938786194
472985796 990513077
846601694 992055636
178982840 919444964
27052680 316046043
8183731...

output:


result:


Subtask #3:

score: 0
Runtime Error

Test #56:

score: 0
Runtime Error

input:

270695 300000
513123795 772355425
210106247 394028231
276162603 911454418
105669187 977348162
173662950 272706156
152814457 669922258
344843731 523572913
316675910 752220119
109044474 322732409
555169512 652867118
622530606 779759913
153668285 339269709
150911093 937002300
186921016 855255616
118867...

output:


result: