Submission #476194

# Submission time Handle Problem Language Result Execution time Memory
476194 2021-09-25T09:51:39 Z dzdzx Addk (eJOI21_addk) C++17
0 / 100
2000 ms 262324 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];
				cout<<s3<<endl;
				
				s3-=(n-b-1)*(f1[b]-f1[a+m-1]);
				
				cout<<f3[a+m]<<" "<<f3[b+1]<<endl;;
				for (int i=0;i<n;i++)cout<<f3[i]<<" ";cout<<endl;
				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:59:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   59 |     for (int i=0;i<n;i++)cout<<f3[i]<<" ";cout<<endl;
      |     ^~~
Main.cpp:59:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   59 |     for (int i=0;i<n;i++)cout<<f3[i]<<" ";cout<<endl;
      |                                           ^~~~
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 Execution timed out 2070 ms 262324 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2081 ms 253796 KB Time limit exceeded
2 Halted 0 ms 0 KB -