답안 #613646

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
613646 2022-07-30T08:48:17 Z karelisp Addk (eJOI21_addk) C++14
0 / 100
31 ms 3536 KB
#include <bits/stdc++.h>
using namespace std;

int N, K, Q;
long long a[100005], pf1[100005], pf2[100005];

long long sum(int l, int r){
	if(l>r) 
		return 0;
	return pf1[r] - pf1[l-1];
}

long long mulsum(int l, int r){
	if(l>r)
		return 0;
	return pf2[r] - pf2[l-1];
}

long long answer(int l, int r, long long m){
	if(2*m <= r-l+1){
		long long S1 = mulsum(l, l+m-1) + (1-l)*sum(l, l+m-1);
		long long S2 = m * sum(l+m, r-m);
		long long S3 = (r+1) * sum(r-m+1, r) - mulsum(r-m+1, r);
		return S1 + S2 + S3;
	}
	else{
		int d = r-l+1-m;
		long long S1 = mulsum(l, l+d-1) + (1-l)*sum(l, l+d-1);
		long long S2 = d*sum(l+d, r-d);
		long long S3 = (r+1)*sum(r-d+1, r) - mulsum(r-d+1, r);
		return S1 + S2 + S3;
	}
}

int main(){
	scanf("%d%d", &N, &K);
	for(long long i=1; i<=N; i++){
		scanf("%lld", &a[i]);
		pf1[i] = pf1[i-1] + a[i];
		pf2[i] = pf2[i-1] + i*a[i];
	}
	
	scanf("%d", &Q);
	for(int l,r,m,op,q=0; q<Q; q++){
		scanf("%d", &op);
		if(op==1) continue;

		scanf("%d%d%d", &l, &r, &m);
		printf("%lld\n", answer(l,r,m));
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |  scanf("%d%d", &N, &K);
      |  ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%lld", &a[i]);
      |   ~~~~~^~~~~~~~~~~~~~~
Main.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
Main.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%d", &op);
      |   ~~~~~^~~~~~~~~~~
Main.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d%d%d", &l, &r, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 1492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 3536 KB Output isn't correct
2 Halted 0 ms 0 KB -