Submission #476195

# Submission time Handle Problem Language Result Execution time Memory
476195 2021-09-25T09:55:43 Z dzdzx Addk (eJOI21_addk) C++17
0 / 100
151 ms 2040 KB
#include<bits/stdc++.h>
using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	int x[n];
	for (int i=0;i<n;i++){
		cin>>x[i];
	}
	long long f1[n];
	long long f2[n];
	long long f3[n];
	f1[0]=x[0];
	f2[0]=x[0];
	for (int i=1;i<n;i++){
		f1[i]=f1[i-1]+x[i];
		f2[i]=f2[i-1]+(i+1)*x[i];
	}
	f3[n-1]=x[n-1];
	for (int i=n-2;i>=0;i--){
		f3[i]=f3[i+1]+(n-i)*x[i];
	}
	int q;
	cin>>q;
	for (int i=0;i<q;i++){
		int u;
		cin>>u;
		if (u==2){
			
			int a,b,m;
			cin>>a>>b>>m;a--;b--;
			if (b-a+1>=(m-1)*2){
				int sum=0;
				int s1=0;
				int s2=0;
				int s3=0;
				s1=f2[m+a-2]-f2[a-1];
				s1-=a*(f1[m+a-2]-f1[a-1]);
				s2=m*(f1[b-m+1]-f1[m+a-2]);
				s3=f3[b-m+2]-f3[b+1];
				s3-=(n-b-1)*(f1[b]-f1[b-m+1]);
				cout<<s1+s2+s3<<endl;;
			}else{
				int sum=0;
				int s1=0;
				int s2=0;
				int s3=0;
				int num=(b-a+1)-m;
				s1=f2[b-m]-f2[a-1];
				s1-=a*(f1[b-m]-f1[a-1]);
				s2=(num+1)*(f1[a+m-1]-f1[b-m]);
				s3=f3[a+m]-f3[b+1];
				s3-=(n-b-1)*(f1[b]-f1[a+m-1]);
				cout<<s1+s2+s3<<endl;;				
			}
		}else{
			for (int j=0;j<k;j++){
				int z;
				cin>>z;
			}
		}
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:34:9: warning: unused variable 'sum' [-Wunused-variable]
   34 |     int sum=0;
      |         ^~~
Main.cpp:45:9: warning: unused variable 'sum' [-Wunused-variable]
   45 |     int sum=0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 1000 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 151 ms 2040 KB Output isn't correct
2 Halted 0 ms 0 KB -