Submission #774797

# Submission time Handle Problem Language Result Execution time Memory
774797 2023-07-06T03:33:07 Z vjudge1 Addk (eJOI21_addk) C++17
0 / 100
2000 ms 596 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()
{
    freopen("stdin","r",stdin);
    freopen("stdout","w",stdout);
    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 q=(r-l+1)%m+(r-l+1)/m+1;
            int ans=0;
            for(int i=0;i<q;++i)
            {
                ans+=sum(1,1,n,l,r);
                ++l;
                --r;
                if(l>r)
                {
                    break;
                }
            }
            cout<<ans<<"\n";
        }
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:48:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     freopen("stdin","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:49:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     freopen("stdout","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 596 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2039 ms 596 KB Time limit exceeded
2 Halted 0 ms 0 KB -