답안 #774820

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774820 2023-07-06T03:48:28 Z vjudge12 Addk (eJOI21_addk) C++17
0 / 100
2000 ms 1764 KB
#include<bits/stdc++.h>
using namespace std;
long long a[100001];
long long st[400001];
void build(long long no,long long l,long long r)
{
    if(l==r)
    {
        st[no]=a[l];
        return;
    }
    long long 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(long long no,long long l,long long r,long long ep,long long x)
{
    if(l>ep||r<ep)
        return;
    if(l==r)
    {
        st[no]=x;
        return;
    }
    long long 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;
}

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

long long qr[11];
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long n,q,k,qrt,l,r,m;
    cin>>n>>k;
    for(long long i=1; i<=n; ++i)
    {
        cin>>a[i];
    }
    cin>>q;
    build(1,1,n);
    for(long long i=0; i<q; ++i)
    {
        cin>>qrt;
        if(qrt==1)
        {
            for(long long j=0; j<k; ++j)
            {
                cin>>qr[j];
            }
            long long kkl=a[qr[0]];
            for(long long 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;
            long long ans=0;
            long long rr=r,ll=l;
            for(long long i=0;i<m;++i)
            {
                ans+=sum(1,1,n,ll,rr);
                ++ll;
                --rr;
                if(ll>rr||rr<l+m-1)
                {
                    break;
                }
            }
            cout<<ans<<"\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 22 ms 340 KB Output is correct
3 Correct 90 ms 388 KB Output is correct
4 Correct 206 ms 420 KB Output is correct
5 Correct 382 ms 460 KB Output is correct
6 Correct 614 ms 664 KB Output is correct
7 Correct 889 ms 672 KB Output is correct
8 Correct 1223 ms 512 KB Output is correct
9 Execution timed out 2069 ms 792 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2067 ms 1024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2065 ms 1764 KB Time limit exceeded
2 Halted 0 ms 0 KB -