답안 #633128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
633128 2022-08-21T16:28:13 Z giorgikob Addk (eJOI21_addk) C++14
0 / 100
84 ms 1416 KB
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define count1(x) __builtin_popcount(x)
#define endl '\n'
using namespace std;

const int N = 1e6+1, mod = 1e6, K = 31;

int n, k, q;
int tree[N][2], A[N];

void upd(ll val, int pos, int k){
    while(pos < N){
        tree[pos][k] += val;
        pos += (pos & -pos);
    }
}

ll get(int pos, int k){
    ll res = 0;
    while(pos){
        res += tree[pos][k];
        pos -= (pos & -pos);
    }

    return res;
}

ll range_query(int l, int r, int k){
    return get(r, k) - get(l-1, k);
}

inline void test_case(){

    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> A[i];
        upd(A[i], i, 0);
        upd(A[i]*i, i, 1);
    }

    cin >> q;
    while(q--){
        int type;
        cin >> type;
        if(type == 1){
            int ind[k];
            for(int i = 0; i < k; i++){
                cin >> ind[i];
            }
            for(int i = 0; i < k; i++){
                int a = ind[i], b = ind[(i+1)%k];
                upd(A[b] - A[a], a, 0);
                upd((A[b] - A[a])*a, a, 1);
            }
        } else {
            int l, r, m;
            cin >> l >> r >> m;
            int mid = (l+r)/2;
            int l1 = min(l+m-1, mid+1);
            int r1 = max(r-m+1, mid);
            if((r-l+1) >= m*2-1){
                l1 = l+m-1;
                r1 = r-m+1;
            } else {
                l1 = mid+1;
                r1 = mid;
            }
            ll res1 = range_query(l, l1-1, 1) - (l-1)*range_query(l, l1-1, 0);
            ll res2 = range_query(l1, r1, 0) * m;
            ll res3 = range_query(r1+1, r, 1) - (r1)*range_query(r1+1, r, 0);
            res3 = (r-r1+1)*range_query(r1+1, r, 0) - res3;

            cout << res1 + res2 + res3 << endl;
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    //cin.tie(0); cout.tie(0);

    int T = 1;
    //cin >> T;
    while(T--){
        test_case();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 84 ms 1416 KB Output isn't correct
2 Halted 0 ms 0 KB -