Submission #474724

# Submission time Handle Problem Language Result Execution time Memory
474724 2021-09-19T14:44:37 Z fuad27 Addk (eJOI21_addk) C++17
92 / 100
314 ms 6580 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
int32_t main () {
	int n, k;
	cin >> n >> k;
	int arr[n+1], prefix1[n+1] = {0}, prefix2[n+1] = {0};
	for(int i = 1;i<=n;i++) {
		cin >> arr[i];
		prefix1[i] = prefix1[i-1] + arr[i];
		prefix2[i] = prefix2[i-1] + arr[i]*i;
	}
	int q;
	cin >> q;
	while(q--) {
		int k;
		cin >> k;
		if(k == 1) {
			int d;
			cin >> d;
		}
		else {
			int ans = 0;
			int l, r, m;
			cin >> l >> r >> m;
			m = min(r-l-m + 2, m);
			int a = (prefix2[l+m-1] - prefix2[l-1])-(prefix1[l+m-1] - prefix1[l-1])*(l-1);
			int b = (prefix1[r-m] - prefix1[l+m-1])*m;
			int c = (prefix1[r] - prefix1[r-m])*(r+1) - (prefix2[r] - prefix2[r-m]);
		       cout<<a+b+c<<endl;
		}
	}
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:23:8: warning: unused variable 'ans' [-Wunused-variable]
   23 |    int ans = 0;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 9 ms 372 KB Output is correct
5 Correct 12 ms 460 KB Output is correct
6 Correct 15 ms 536 KB Output is correct
7 Correct 18 ms 572 KB Output is correct
8 Correct 21 ms 584 KB Output is correct
9 Correct 32 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 1220 KB Output is correct
2 Correct 92 ms 1836 KB Output is correct
3 Correct 122 ms 2508 KB Output is correct
4 Correct 218 ms 3908 KB Output is correct
5 Correct 314 ms 6580 KB Output is correct
6 Correct 286 ms 6336 KB Output is correct
7 Correct 283 ms 6312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 151 ms 3780 KB Output isn't correct
2 Halted 0 ms 0 KB -