답안 #476672

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476672 2021-09-28T05:28:50 Z dzdzx Addk (eJOI21_addk) C++17
0 / 100
154 ms 3636 KB
#include<bits/stdc++.h>
using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	int x[n+1];
	for (int i=1;i<=n;i++){
		cin>>x[i];
	}
	long long f1[n+1];
	long long f2[n+1];
	f1[0]=0;
	f2[0]=0;
	for (int i=1;i<=n;i++){
		f1[i]=f1[i-1]+x[i];
		f2[i]=f2[i-1]+i*x[i];
	}
	int q;
	cin>>q;
	int ans[10000];
	int r=0;
	for (int i=0;i<q;i++){
		int u;
		cin>>u;
		if (u==2){
			
			int a,b,m;
			cin>>a>>b>>m;
			
			if(b-a+1>=2*m){
				int s1 = (f2[a+m-1] - f2[a-1])-(f1[a+m-1] - f1[a-1])*(a-1);
				int s2 = (f1[b-m] - f1[a+m-1])*m;
				int s3 = (f1[b] - f1[b-m])*(b+1) - (f2[b] - f2[b-m]);	
				cout<<s1+s2+s3<<endl;
			}else{
				int s1 = (f2[b-m] - f2[a-1])-(f1[b-m] - f1[a-1])*(a-1);
				int s2 = (f1[a+m-1] - f1[b-m])*(b-a-m+2);
				int s3 = (f1[b] - f1[a+m-1])*(b+1) - (f2[b] - f2[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:21:6: warning: unused variable 'ans' [-Wunused-variable]
   21 |  int ans[10000];
      |      ^~~
Main.cpp:22:6: warning: unused variable 'r' [-Wunused-variable]
   22 |  int r=0;
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 288 KB Output is correct
3 Incorrect 6 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 154 ms 3636 KB Output isn't correct
2 Halted 0 ms 0 KB -