답안 #641095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
641095 2022-09-16T01:40:46 Z kith14 Addk (eJOI21_addk) C++17
64 / 100
449 ms 8772 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define db double
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>

#define repp(i,a,b) for (ll i = a; i <= b; i++)
#define repz(i,a,b) for (ll i = a; i < b; i++)
#define repm(i,a,b) for (ll i = a; i >= b; i--)
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

const ll N = 1e5+5, MOD = 1e9+7;
ll tc = 1, n, m, ar[N], br[N], tree[N*4][3];
ll x, y, k;
string s, s1, s2, ye = "YES", no = "NO";

void build(ll l, ll r, ll idx, ll cr){
  if (l == r){
    if (cr == 0) tree[idx][cr] = ar[l];
    else if (cr == 1) tree[idx][cr] = ar[l]*l;
    else tree[idx][cr] = ar[l]*(n-l+1);
    return;
  }
  ll md = (l+r)/2;
  build(l,md,idx*2,cr);
  build(md+1,r,idx*2+1,cr);
  tree[idx][cr] = tree[idx*2][cr]+tree[idx*2+1][cr];
}

ll que(ll l, ll r, ll idx, ll x, ll y, ll cr){
  if (l > r || l > y || r < x) return 0;
  if (x <= l && r <= y) return tree[idx][cr];
  ll md = (l+r)/2;
  return que(l,md,idx*2,x,y,cr)+que(md+1,r,idx*2+1,x,y,cr); 
}

void upd(ll l, ll r, ll idx, ll pos, ll val, ll cr){
  if (l == r){
    if (cr == 0) tree[idx][cr] = val;
    else if (cr == 1) tree[idx][cr] = val*l;
    else tree[idx][cr] = val*(n-l+1);
    return;
  }
  ll md = (l+r)/2;
  if (pos <= md) upd(l,md,idx*2,pos,val,cr);
  else upd(md+1,r,idx*2+1,pos,val,cr);
  tree[idx][cr] = tree[idx*2][cr]+tree[idx*2+1][cr];
}

void input(){
  cin >> n >> k;
  repp(i,1,n) cin >> ar[i];
}

void solve(){
  build(1,n,1,0);
  build(1,n,1,1);
  build(1,n,1,2);
  cin >> m;
  while(m--){
    ll a, b, c, d;
    cin >> a;
    if (a == 1){
      vector<ll> idx, val;
      ll lst;
      repp(i,1,k){
        cin >> b;
        idx.pb(b);
        if (i != 1) val.pb(ar[b]);
        else lst = ar[b];
      }
      val.pb(lst);
      repz(i,0,k){
        upd (1,n,1,idx[i],val[i],0);
        upd (1,n,1,idx[i],val[i],1);
        upd (1,n,1,idx[i],val[i],2);
        ar[idx[i]] = val[i];
      }
      continue;
    }
    cin >> b >> c >> d;
    if (b == c){
      cout << que(1,n,1,b,b,0) << endl;
      continue;
    }
    ll len = c-b+1;
    if (d > (len+1)/2) d = len-d+1;
    //cout << "d = " << d << endl;
    ll ten = que(1,n,1,b+d,c-d,0)*d;
    ll kir= que(1,n,1,b,b+d-1,1)-que(1,n,1,b,b+d-1,0)*(b-1);
    ll kan = que(1,n,1,c-d+1,c,2)-que(1,n,1,c-d+1,c,0)*(n-c);
    ll tot = kir+kan+ten;
    //if (d == 1) tot /= 2;
    cout << tot << endl;
    //cout << kir << " " << ten << " " << kan << endl;
  }
  // while(m--){
  //   ll a, b, c;
  //   cin >> c;
  //   cout << tree[1][c] << endl;
  // }
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  //cin >> tc;
  while(tc--){
    input();
    solve();
  }
}

/*

*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 2256 KB Output is correct
2 Correct 92 ms 2428 KB Output is correct
3 Correct 111 ms 4204 KB Output is correct
4 Correct 208 ms 8144 KB Output is correct
5 Correct 322 ms 8772 KB Output is correct
6 Correct 292 ms 8668 KB Output is correct
7 Correct 276 ms 8632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 203 ms 4196 KB Output is correct
2 Correct 281 ms 8080 KB Output is correct
3 Correct 449 ms 7988 KB Output is correct
4 Correct 339 ms 8652 KB Output is correct