Submission #1071999

# Submission time Handle Problem Language Result Execution time Memory
1071999 2024-08-23T13:11:00 Z vjudge1 Addk (eJOI21_addk) C++17
0 / 100
330 ms 3152 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define sz(x) x.size()
#define nl '\n'
#define F first
#define S second

const int N = 1e5 + 1;
int t[4 * N], a[N];

void upd( int v, int tl, int tr, int pos )
{
    if( tl == tr )
    {
        t[v] = a[tl];
        return;
    }
    int m = (tl + tr) / 2;
    if( pos <= m )
        upd(v + v, tl, m, pos);
    else
        upd(v + v + 1, m + 1, tr, pos);
    t[v] = t[v + v] + t[v + v + 1];
}

int get( int v, int tl, int tr, int l, int r )
{
    if( l > tr || tl > r )
        return 0;
    if( l <= tl && tr <= r )
        return t[v];
    int m = (tl + tr) / 2;
    return get(v + v, tl, m, l, r) + get(v + v + 1, m + 1, tr, l, r);
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, k, q;
    cin >>n >>k;
    for( int i = 1; i <= n; ++i )
    {
        cin >>a[i];
        upd(1, 1, n, i);
    }
    cin >>q;
    while( q-- )
    {
        int type, l, r, m;
        cin >>type;
        if( type == 1 )
        {
            vector< int >v, vv;
            v.pb( 0 );
            vv.pb( 0 );
            for( int i = 1, x; i <= k; ++i )
            {
                cin >>x;
                v.pb( x );
                vv.pb( a[x] );
            }
            for( int i = 1; i <= k; ++i )
            {
                if( i == k )
                    a[v[i]] = vv[0];
                else
                    a[v[i]] = vv[i + 1];
                upd(1, 1, n, v[i]);
            }
        }
        else
        {
            cin >>l >>r >>m;
            int ans = get(1, 1, n, l, r) * m;
            for( int i = l, x = m - 1; x > 0; ++i, --x )
                ans -= a[i] * x;
            for( int i = r, x = m - 1; x > 0; --i, --x )
                ans -= a[i] * x;
            cout <<ans <<nl;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 129 ms 2700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 330 ms 3152 KB Output isn't correct
2 Halted 0 ms 0 KB -