Submission #571785

# Submission time Handle Problem Language Result Execution time Memory
571785 2022-06-02T17:51:52 Z Adnanboi Addk (eJOI21_addk) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

#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(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(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++){
        int 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;
            ll f=0;
            for(int j=a;j<=b-m+1;j++){
                f+=sum(j-1,j+m-1);
            }
            cout<<f<<'\n';
        }
    }

}

Compilation message

Main.cpp:7:19: error: 'N' was not declared in this scope
    7 | vector<ll> tree(2*N,0);
      |                   ^