Submission #613697

# Submission time Handle Problem Language Result Execution time Memory
613697 2022-07-30T09:27:26 Z karelisp Addk (eJOI21_addk) C++14
92 / 100
67 ms 6528 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(long long int l, long long 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+1)*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){
			for(int i=0; i<K; i++){
				scanf("%*d");
			}
		}
		else{
			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:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     scanf("%*d");
      |     ~~~~~^~~~~~~
Main.cpp:52:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |    scanf("%d%d%d", &l, &r, &m);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 468 KB Output is correct
5 Correct 3 ms 448 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 4 ms 576 KB Output is correct
8 Correct 4 ms 712 KB Output is correct
9 Correct 5 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 980 KB Output is correct
2 Correct 15 ms 2124 KB Output is correct
3 Correct 22 ms 2752 KB Output is correct
4 Correct 67 ms 4664 KB Output is correct
5 Correct 61 ms 6528 KB Output is correct
6 Correct 53 ms 6292 KB Output is correct
7 Correct 51 ms 6252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 1936 KB Output isn't correct
2 Halted 0 ms 0 KB -