Submission #571783

# Submission time Handle Problem Language Result Execution time Memory
571783 2022-06-02T17:46:45 Z Adnanboi Addk (eJOI21_addk) C++14
36 / 100
1648 ms 2772 KB
#include <bits/stdc++.h>

using namespace std;

#define N 10000
#define ll long long

vector<ll> tree(2*N,0);

ll n;

void build(vector<ll> lista){
    for(ll i=0;i<n;i++){
        tree[n+i]=lista[i];
    }
    for (ll i=n-1;i>0;i--){ 
        tree[i]=tree[i<<1]+tree[i<<1 | 1];
    }
}

void update(ll p, ll value){
    p+=n;
    tree[p]=value;
    for(p/=2;p>0;p/=2){
        tree[p]=tree[2*p]+tree[p*2+1];
    }
}

ll sum(ll l, ll r){
    ll res = 0;
    for (l+=n,r+=n;l<r;l>>=1,r>>=1)
    {
        if (l&1)
            res += tree[l++];
     
        if (r&1)
            res += tree[--r];
    }
    return res;
}

int main(){
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    ll q,k;
    cin>>n>>k;
    vector<ll> lista(n);
    for(ll i=0;i<n;i++){
        cin>>lista[i];
    }
    build(lista);
    cin>>q;
    for(ll i=0;i<q;i++){
        ll c;
        cin>>c;
        if(c==1){
            ll a;
            cin>>a;
            ll first=tree[a+n-1];
            ll b=a;
            for(ll i=0;i<k-1;i++){
                ll d=b;
                cin>>b;
                update(d-1,tree[b-1+n]);
            }
            update(b-1,first);
        }
        else if(c==2){
            ll a,b,m;
            cin>>a>>b>>m;
            ll f=0;
            for(ll j=a;j<=b-m+1;j++){
                f+=sum(j-1,j+m-1);
            }
            cout<<f<<'\n';
        }
    }

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 16 ms 528 KB Output is correct
3 Correct 71 ms 568 KB Output is correct
4 Correct 147 ms 608 KB Output is correct
5 Correct 247 ms 672 KB Output is correct
6 Correct 406 ms 844 KB Output is correct
7 Correct 577 ms 704 KB Output is correct
8 Correct 756 ms 780 KB Output is correct
9 Correct 1648 ms 1284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1748 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 2772 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -