Submission #640932

# Submission time Handle Problem Language Result Execution time Memory
640932 2022-09-15T14:57:16 Z maks007 Addk (eJOI21_addk) C++14
0 / 100
35 ms 2696 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 L = std::min(l+m-2,r-m), R = std::max(l+m,r-m+2);
			int S1, S2, S3;
			if(l > L) S1 = 0;
			else {
				S1 = up[L] - up[l-1] - (l-1)*(pref[L] - pref[l-1]);
			}
			if(R > r) {
				S2 = 0;
			}else {
				S2 = down[R] - down[r+1] - (n-r)*(suff[R] - suff[r+1]);
			}
			if(L+1 > R-1) S3 = 0;
			else {
				S3 = (L+2-l)*(pref[R-1] - pref[L]);
			}
			printf("%lld\n",S1 + S3 + S2);
		}
	}
	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);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 1300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 2696 KB Output isn't correct
2 Halted 0 ms 0 KB -