답안 #640916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640916 2022-09-15T14:14:39 Z maks007 Addk (eJOI21_addk) C++14
0 / 100
36 ms 2636 KB
#include "bits/stdc++.h"
#define int long long
signed main () {
	int n, k;
	scanf("%lld%lld", &n, &k);
	int a[n+1];
	for(int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
	int pref[n+1];
	pref[1] = a[1];
	for(int i = 2; i <= n; i ++) pref[i] = pref[i - 1] + a[i];
	int up[n+1];
	up[1] = a[1];
	for(int i = 2; i <= n; i ++) up[i] = up[i - 1] + a[i]  * i;
	int suff[n+2];
	memset(suff, 0, sizeof(suff));
	suff[n] = a[n];
	for(int i = n - 1; i >= 1; i --) suff[i] = suff[i + 1] + a[i];
	int down[n+2];
	memset(down, 0, sizeof(down));
	down[n] = a[n];
	for(int i = n - 1; i >= 1; i --) down[i] = down[i + 1] + a[i] * (n-i+1);
	int q;
	scanf("%lld", &q);
	while(q --) {
		int type;
		scanf("%lld", &type);
		if(type == 1) {
			int kk = k, x;
			while(kk --) scanf("%lld", &x);
		}else {
			int l, r, m;
			scanf("%lld%lld%lld", &l, &r, &m);
			if(m == 1) {
				printf("%lld\n", pref[r] - pref[r-1]);
				continue;
			}
			int S1 = up[l+m-2] - up[l-1] - (l-1)*(pref[l+m-2] - pref[l-1]);
			int S2 = m * (pref[r-m+1] - pref[l+m-2]);
			if(2*(m-1)+2>r-l+1) {
				S2 = 0;
			}
			int S3 = down[r-m+2] - down[r+1] - (n - r) * (suff[r-m+2] - suff[r+1]);
			printf("%lld\n", S1+ S2+ S3);
		}
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:5:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 |  scanf("%lld%lld", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:7:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  for(int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~
Main.cpp:23:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |  scanf("%lld", &q);
      |  ~~~~~^~~~~~~~~~~~
Main.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   scanf("%lld", &type);
      |   ~~~~~^~~~~~~~~~~~~~~
Main.cpp:29:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |    while(kk --) scanf("%lld", &x);
      |                 ~~~~~^~~~~~~~~~~~
Main.cpp:32:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |    scanf("%lld%lld%lld", &l, &r, &m);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 1364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -