답안 #475600

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
475600 2021-09-23T09:25:38 Z nickmet2004 Addk (eJOI21_addk) C++11
92 / 100
2000 ms 5728 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;

const int N = 1e6 + 5;
int n , k , q,a[N] , Y[11] ,H[11];
pair<int, int> F[2*N];
void upd(int i , int d1 , int d2){
    while(i <= n) {
        F[i].f += d1 , F[i].s += d2;
        i += i & -i;
    }
}
pair<int , int>  get(int i){
    pair<int , int> sum = {0,0};
    while(i) {
        sum.f += F[i].f , sum.s += F[i].s;
        i -= i & -i;
    }
    return sum;
}

 main (){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)cin >> a[i];
    for(int i = 1; i<= n; ++i) upd(i , a[i] , a[i]*i);
    cin >> q;

    while(q--){
        int tp;
        cin >> tp;
        if(tp==1){
            for(int i = 0; i < k; ++i)cin >> Y[i];
            sort(Y , Y + k);
            for(int i = 0; i < k; ++i) H[Y[i]] = a[Y[i]];
            for(int i = 1; i < k; ++i) swap(a[Y[i]] , a[Y[i - 1]]);
            for(int i = 0; i < k; ++i) upd(Y[i] , a[Y[i]] - H[Y[i]] , (a[Y[i]] - H[Y[i]])*Y[i]);

        }else {
            int l , r , m;
            cin >> l >> r >> m;
            m = min(m , r - l - m + 2);
            int ans = 0;
            pair<int,int> gR = get(l + m - 1);
            pair<int,int> gL = get(l - 1);
            ans += (gR.s - gL.s - (l - 1) * (gR.f - gL.f));
            ans += (get(r - m).f - get(l + m - 1).f)*m;
            gL = get(r-m);
            gR = get(r);
            ans += (r+1)*(gR.f-gL.f)-(gR.s-gL.s);
            cout << ans << endl;
        }
    }
}

Compilation message

Main.cpp:25:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   25 |  main (){
      |  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Correct 7 ms 460 KB Output is correct
5 Correct 9 ms 460 KB Output is correct
6 Correct 10 ms 564 KB Output is correct
7 Correct 12 ms 656 KB Output is correct
8 Correct 13 ms 660 KB Output is correct
9 Correct 19 ms 944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 1296 KB Output is correct
2 Correct 57 ms 1848 KB Output is correct
3 Correct 73 ms 2652 KB Output is correct
4 Correct 137 ms 4032 KB Output is correct
5 Correct 203 ms 5728 KB Output is correct
6 Correct 169 ms 5568 KB Output is correct
7 Correct 179 ms 5624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2082 ms 3144 KB Time limit exceeded
2 Halted 0 ms 0 KB -