답안 #553022

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553022 2022-04-24T13:03:11 Z Fidan Addk (eJOI21_addk) C++17
92 / 100
275 ms 6724 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll inf=(1e18);
const ll N=1'000'010;

ll n, k, i;
vector<ll> v;
vector<ll> sum;
vector<ll> pre;

ll prefix(ll l, ll r){
	ll s=0;
	s=pre[r]-pre[l-1]-(l-1)*(sum[r]-sum[l-1]);
	return s;
}

ll suffix(ll l, ll r){
	ll s=0;
	s=(r-l+2)*(sum[r]-sum[l-1])-prefix(l, r);
	return s;
}

void solve(ll l, ll r, ll m){
	ll s=0, k=r-l+1;
	if(2*m>k) m=k-m+1;
	s=prefix(l, l+m-1)+m*(sum[r-m]-sum[l+m-1])+suffix(r-m+1, r);
	cout<<s<<endl;
}

int main(){
	
	cin>>n>>k;
	v.push_back(0);
	pre.push_back(0);
	sum.push_back(0);
	
	for(i=1; i<=n; i++){
		ll a;
		cin>>a;
		v.push_back(a);
		pre.push_back(0);
		sum.push_back(0);
	}
	
	for(i=1; i<=n; i++){
		sum[i]=sum[i-1]+v[i];
		pre[i]=pre[i-1]+v[i]*i;
	}
	
	ll qu;
	cin>>qu;
	while(qu--){
		ll asdf;
		cin>>asdf;
		if(asdf==1){
			for(i=0; i<k; i++){
				ll asdf1;
				cin>>asdf1;
			}
		}
		else {
			ll l, r, m;
			cin>>l>>r>>m;
			solve(l, r, m);
		}
	}
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 5 ms 340 KB Output is correct
4 Correct 8 ms 416 KB Output is correct
5 Correct 12 ms 556 KB Output is correct
6 Correct 15 ms 664 KB Output is correct
7 Correct 21 ms 700 KB Output is correct
8 Correct 20 ms 700 KB Output is correct
9 Correct 31 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 1352 KB Output is correct
2 Correct 89 ms 2196 KB Output is correct
3 Correct 125 ms 2912 KB Output is correct
4 Correct 219 ms 4808 KB Output is correct
5 Correct 275 ms 6724 KB Output is correct
6 Correct 262 ms 6500 KB Output is correct
7 Correct 258 ms 6456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 142 ms 2232 KB Output isn't correct
2 Halted 0 ms 0 KB -