Submission #774812

# Submission time Handle Problem Language Result Execution time Memory
774812 2023-07-06T03:44:28 Z vjudge12 Addk (eJOI21_addk) C++17
0 / 100
2000 ms 1088 KB
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int st[400001];
void build(int no,int l,int r)
{
    if(l==r)
    {
        st[no]=a[l];
        return;
    }
    int mid=(l+r)/2;
    build(no*2,l,mid);
    build(no*2+1,mid+1,r);
    st[no]=st[no*2+1]+st[no*2];
    return;
}

void pointupd(int no,int l,int r,int ep,int x)
{
    if(l>ep||r<ep)
        return;
    if(l==r)
    {
        st[no]=x;
        return;
    }
    int mid=(l+r)/2;
    pointupd(no*2,l,mid,ep,x);
    pointupd(no*2+1,mid+1,r,ep,x);
    st[no]=st[no*2+1]+st[no*2];
    return;
}

int sum(int no,int l,int r,int el,int er)
{
    if(l>er||r<el)
        return 0;
    if(l>=el&&r<=er)
        return st[no];
    int mid=(l+r)/2;
    return sum(no*2+1,mid+1,r,el,er)+sum(no*2,l,mid,el,er);
}

int qr[11];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,q,k,qrt,l,r,m;
    cin>>n>>k;
    for(int i=1; i<=n; ++i)
    {
        cin>>a[i];
    }
    cin>>q;
    build(1,1,n);
    for(int i=0; i<q; ++i)
    {
        cin>>qrt;
        if(qrt==1)
        {
            for(int j=0; j<k; ++j)
            {
                cin>>qr[j];
            }
            int kkl=a[qr[0]];
            for(int j=0; j<k-1; ++j)
            {
                a[qr[j]]=a[qr[j+1]];
                pointupd(1,1,n,qr[j],a[qr[j]]);
            }
            a[qr[k-1]]=kkl;
            pointupd(1,1,n,qr[k-1],a[qr[k-1]]);
        }
        if(qrt==2)
        {
            cin>>l>>r>>m;
            int ans=0;
            int rr=r,ll=l;
            for(int i=0;i<m;++i)
            {
                ans+=sum(1,1,n,ll,rr);
                ++ll;
                --rr;
                if(l>r||(rr-l+1<m)||(r-ll+1<m))
                {
                    break;
                }
            }
            cout<<ans<<"\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 23 ms 348 KB Output is correct
3 Incorrect 96 ms 356 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2084 ms 664 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2069 ms 1088 KB Time limit exceeded
2 Halted 0 ms 0 KB -