Submission #571796

# Submission time Handle Problem Language Result Execution time Memory
571796 2022-06-02T18:30:54 Z Adnanboi Addk (eJOI21_addk) C++14
36 / 100
2000 ms 19600 KB
#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define ll long long

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

ll n;

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

void update(int 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(int l, int 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;
}

ll sum2(int m, int begin, int end){
    ll result=0;
    ll constantres=0;
    begin+=n;
    end+=n;
    for(int i=begin-1;i<begin+m-1;i++){
        result+=tree[i];
    }
    constantres=result;
    for(int i=begin;i<end-m+1;i++){
        constantres-=tree[i-1];
        constantres+=tree[i+m-1];
        result+=constantres;
    }
    return result;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll q,k;
    cin>>n>>k;
    vector<ll> lista(n);
    for(int i=0;i<n;i++){
        cin>>lista[i];
    }
    build(lista);
    cin>>q;
    for(int i=0;i<q;i++){
        short c;
        cin>>c;
        if(c==1){
            int a;
            cin>>a;
            int first=tree[a+n-1];
            int b=a;
            for(int i=0;i<k-1;i++){
                int d=b;
                cin>>b;
                update(d-1,tree[b-1+n]);
            }
            update(b-1,first);
        }
        else if(c==2){
            int a,b,m;
            cin>>a>>b>>m;
            cout<<sum2(m,a,b)<<'\n';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15980 KB Output is correct
2 Correct 7 ms 15956 KB Output is correct
3 Correct 9 ms 15956 KB Output is correct
4 Correct 11 ms 15956 KB Output is correct
5 Correct 16 ms 16100 KB Output is correct
6 Correct 21 ms 16072 KB Output is correct
7 Correct 24 ms 16124 KB Output is correct
8 Correct 33 ms 16144 KB Output is correct
9 Correct 51 ms 16212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 16388 KB Output is correct
2 Correct 411 ms 17456 KB Output is correct
3 Correct 683 ms 17812 KB Output is correct
4 Execution timed out 2071 ms 19176 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 818 ms 18172 KB Output is correct
2 Execution timed out 2069 ms 19600 KB Time limit exceeded
3 Halted 0 ms 0 KB -