Submission #541217

# Submission time Handle Problem Language Result Execution time Memory
541217 2022-03-22T18:57:52 Z Fidan Addk (eJOI21_addk) C++17
0 / 100
67 ms 1940 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N = 1000'010;
ll sumpre(ll x, ll y, vector<ll> &pre, vector<ll> &dp){
	return pre[y]-pre[x-1]-(x-1)*(dp[y]-dp[x-1]);
}
ll sumsuf(ll x, ll y, vector<ll> &pre, vector<ll> &dp){
	return (y-x+2)*(dp[y]-dp[x-1])-sumpre(x, y, pre, dp);
}
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=sumpre(l, l+m-1, pre, dp)+m*(dp[r-m]-dp[l+m-1])+sumsuf(r-m+1, r, pre, dp);
			}
			else {
				s=sumpre(l, l+k/2-1, pre, dp)+sumsuf(l+k/2, r, pre, dp);
			}
			cout<<s<<endl;
		}
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:44:24: warning: unused variable 'a' [-Wunused-variable]
   44 |    ll l, r, m, k, s=0, a;
      |                        ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 1004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 67 ms 1940 KB Output isn't correct
2 Halted 0 ms 0 KB -