답안 #571808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571808 2022-06-02T18:56:13 Z Adnanboi Addk (eJOI21_addk) C++14
92 / 100
1750 ms 20068 KB
#include <bits/stdc++.h>

using namespace std;

#define N 1000000
#define ll long long

vector<ll> lista(N), prefiksalnalista(N);

ll n;

void update(int p, ll value){
    lista[p]=value;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll q,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>lista[i];
        prefiksalnalista[i]=prefiksalnalista[i-1]+lista[i];
    }
    cin>>q;
    for(int i=0;i<q;i++){
        short c;
        cin>>c;
        if(c==1){
            int a;
            cin>>a;
            int first=lista[a-1];
            int b=a;
            for(int i=0;i<k-1;i++){
                int d=b;
                cin>>b;
                update(d-1,lista[b-1]);
            }
            update(b-1,first);
        }
        else if(c==2){
            int a,b,m;
            cin>>a>>b>>m;
            ll rezultat=0;
            if(min(b-m-a+2,2*m-2)==(b-m-a+2)) 
                for(int i=a;i<=b-m+1;i++) 
                    rezultat+=prefiksalnalista[i+m-1]-prefiksalnalista[i-1];
            else{
                for(int i=a,cnt=1;i<a+m;i++,cnt++) rezultat+=cnt*lista[i];
                for(int i=b,cnt=1;i>b-m;i--,cnt++) rezultat+=cnt*lista[i];
                rezultat+=m*(prefiksalnalista[b-m]-prefiksalnalista[a+m-1]);
            }
 
            cout<<rezultat<<'\n';
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 15956 KB Output is correct
2 Correct 7 ms 15956 KB Output is correct
3 Correct 7 ms 16032 KB Output is correct
4 Correct 9 ms 15956 KB Output is correct
5 Correct 11 ms 16044 KB Output is correct
6 Correct 13 ms 16036 KB Output is correct
7 Correct 14 ms 16064 KB Output is correct
8 Correct 17 ms 16036 KB Output is correct
9 Correct 25 ms 16028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 16148 KB Output is correct
2 Correct 152 ms 16348 KB Output is correct
3 Correct 268 ms 16536 KB Output is correct
4 Correct 941 ms 17024 KB Output is correct
5 Correct 1750 ms 20068 KB Output is correct
6 Correct 1574 ms 19784 KB Output is correct
7 Correct 1312 ms 19780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 211 ms 16460 KB Output isn't correct
2 Halted 0 ms 0 KB -