답안 #640940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
640940 2022-09-15T15:13:08 Z maks007 Addk (eJOI21_addk) C++14
0 / 100
34 ms 2380 KB
#include "bits/stdc++.h"
#define int long long

#define N (int)1e6

int pref[N], up[N], down[N], n;

int Up(int l, int r) {
	if(r > l) return 0;
	return up[r] - up[l-1] - (l - 1) * (pref[r] - pref[l - 1]);
}

int Down(int l, int r) {
	if(l > r) return 0;
	return down[l] - down[r + 1] - (pref[r] - pref[l - 1]) * (n - r);
}

int Mid(int l, int r, int x) {
	if(l > r) return 0;
	return x * (pref[r] - pref[l-1]);
}

signed main () {
	int k;
	scanf("%lld%lld", &n, &k);
	int a[n+1];
	for(int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
	pref[1] = a[1];
	for(int i = 2; i <= n; i ++) pref[i] = pref[i - 1] + a[i];
	up[1] = a[1];
	for(int i = 2; i <= n; i ++) up[i] = up[i-1] + (a[i] * i);
	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[l-1]);
				continue;
			}
			int L = std::min(l+m-2,r-m), R = std::max(l+m,r-m+2);
			printf("%lld\n",Up(l, L)+Mid(L+1,R-1, L+2-l)+Down(R,r));
		}
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  scanf("%lld%lld", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:27:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |  for(int i = 1; i <= n; i ++) scanf("%lld", &a[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~
Main.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  scanf("%lld", &q);
      |  ~~~~~^~~~~~~~~~~~
Main.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%lld", &type);
      |   ~~~~~^~~~~~~~~~~~~~~
Main.cpp:41:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |    while(kk --) scanf("%lld", &x);
      |                 ~~~~~^~~~~~~~~~~~
Main.cpp:44:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |    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 11 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 34 ms 2380 KB Output isn't correct
2 Halted 0 ms 0 KB -