답안 #541330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541330 2022-03-23T06:24:52 Z Fidan Addk (eJOI21_addk) C++17
0 / 100
87 ms 1784 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N = 1000'010;

void upd(ll id, ll val, vector<ll> &v){
	while(id<=v.size()){
		v[id]+=val;
		id+=id&(-id);
	}
}

ll que(ll id, vector<ll> &v){
	if(id==0) return 0;
	ll s=0;
	while(id>0){
		s+=v[id];
		id-=id&(-id);
	}
	return s;
}

ll sum(ll x, ll y, vector<ll> &v){
	return que(y, v)-que(x-1, v);
}	

ll prefix(ll x, ll y, vector<ll> &pre, vector<ll> &v){
	return que(y, pre)-que(x-1, pre)-(x-1)*sum(x, y, v);
}

ll suffix(ll x, ll y, vector<ll> &pre, vector<ll> &v){
	return (y-x+2)*sum(x, y, v)-prefix(x, y, pre, v);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	ll n, k, i;
	cin>>n>>k;
	
	vector<ll> a(n+1, 0);
	for(i=1; i<=n; i++){
		cin>>a[i];
	}
	
	vector<ll> pre(n+1, 0);
	
	for(i=1; i<=n; i++){
		pre[i]=i*a[i];
	}
	
	ll q;
	cin>>q;
	while(q--){
		ll t;
		cin>>t;
		
		if(t==1){
			vector<ll> x(k);
			vector<ll> val(k);
			for(i=0; i<k; i++){
				cin>>x[i];
				val[i]=a[x[i]];
			}
			x.push_back(x[0]);
			val.push_back(val[0]);
			for(i=0; i<k; i++){
				upd(x[i], x[i]*(val[i+1]-val[i]), pre);
				upd(x[i], val[i+1]-val[i], a);
			}
		}
		
		else {
			ll l, r, m, k, s=0, b;
			cin>>l>>r>>m;
			k=r-l+1;
			if(k>=2*m){
				s=prefix(l, l+m-1, pre, a)+m*sum(l+m, r-m, a)+suffix(r-m+1, r, pre, a);
			}
			else {
				b=k-m+1;
				s=prefix(l, l+b-1, pre, a)+b*sum(l+b, r-b, a)+suffix(r-b+1, r, pre, a);
			}
			cout<<s<<endl;
		}
		
	}
	return 0;
}

Compilation message

Main.cpp: In function 'void upd(ll, ll, std::vector<long long int>&)':
Main.cpp:8:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  while(id<=v.size()){
      |        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 87 ms 1784 KB Output isn't correct
2 Halted 0 ms 0 KB -