답안 #541214

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541214 2022-03-22T18:47:39 Z Fidan Addk (eJOI21_addk) C++17
0 / 100
70 ms 2332 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N = 1000'010;
ll sum(ll x, ll y, vector<ll> &pre, vector<ll> &dp){
	return pre[y]-pre[x-1]-(x-1)*(dp[y]-dp[x-1]);
}
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);
	vector<ll> dp(n+1, 0);
	
	for(i=1; i<=n; i++){
		pre[i]=pre[i-1]+i*a[i];
		dp[i]=dp[i-1]+a[i];
	}
	
	ll q;
	cin>>q;
	while(q--){
		ll t;
		cin>>t;
		if(t==1){
			for(i=0; i<k; i++){
				ll x1;
				cin>>x1;
			}
		}
		else {
			ll l, r, m, k, s=0, a;
			cin>>l>>r>>m;
			k=r-l+1;
			if(k>=2*m){
				s=sum(l, l+m-1, pre, dp)+m*(dp[r]-dp[l+m-1])-sum(r-m+2, r, pre, dp);
			}
			else {
				if(k%2==0){
					s=sum(l, l+k/2-1, pre, dp)+(k/2)*(dp[r]-dp[l+k/2-1])-sum(l+k/2+1, r, pre, dp);
				}
				else {
					s=sum(l, l+k/2-1, pre, dp)+(k/2+1)*(dp[r]-dp[l+k/2-1])-sum(l+k/2+1, r, pre, dp);
				}
			}
			cout<<s<<endl;
		}
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:41:24: warning: unused variable 'a' [-Wunused-variable]
   41 |    ll l, r, m, k, s=0, a;
      |                        ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 1484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 70 ms 2332 KB Output isn't correct
2 Halted 0 ms 0 KB -