Submission #632273

# Submission time Handle Problem Language Result Execution time Memory
632273 2022-08-19T19:33:30 Z CyberCow Addk (eJOI21_addk) C++17
92 / 100
59 ms 7408 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <stack>
#include <deque>
using namespace std;
using ll = long long;
ll a[100005], n;
ll p[100005], s[100005];
ll pref[100005];

ll ach(int l, int r)
{
	if (l > r)
		return 0;
	return p[r] - p[l - 1] - (pref[r] - pref[l - 1]) * (l - 1);
}

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

ll mij(int l, int r, int q)
{
	if (l > r)
		return 0;
	return q * (pref[r] - pref[l - 1]);
}

void solve()
{
	int i, j, x, y, k;
	cin >> n >> k;
	for ( i = 1; i <= n; i++)
	{
		cin >> a[i];
		p[i] = p[i - 1] + a[i] * i;
		pref[i] = pref[i - 1] + a[i];
	}
	for ( i = n; i >= 1; i--)
	{
		s[i] = s[i + 1] + a[i] * (n - i + 1);
	}
	int q, l, r, m;
	cin >> q;
	for ( i = 0; i < n; i++)
	{
		cin >> k;
		if (k == 1)
		{
			cin >> k;
		}
		else
		{
			cin >> l >> r >> m;
			if (m == 1)
			{
				cout << pref[r] - pref[l - 1] << '\n';
			}
			else
			{
				int mi = min(l + m - 2, r - m), ma = max(l + m, r - m + 2);
				cout << ach(l, mi) + mij(mi + 1, ma - 1, mi + 2 - l) + nvaz(ma, r) << '\n';
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tt = 1;
	//cin >> tt;
	while (tt--)
	{
		solve();
	}
	return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:45:9: warning: unused variable 'j' [-Wunused-variable]
   45 |  int i, j, x, y, k;
      |         ^
Main.cpp:45:12: warning: unused variable 'x' [-Wunused-variable]
   45 |  int i, j, x, y, k;
      |            ^
Main.cpp:45:15: warning: unused variable 'y' [-Wunused-variable]
   45 |  int i, j, x, y, k;
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 472 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 3 ms 608 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 4 ms 724 KB Output is correct
9 Correct 5 ms 996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1212 KB Output is correct
2 Correct 14 ms 2372 KB Output is correct
3 Correct 19 ms 3024 KB Output is correct
4 Correct 31 ms 5192 KB Output is correct
5 Correct 59 ms 7408 KB Output is correct
6 Correct 44 ms 7116 KB Output is correct
7 Correct 44 ms 7104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 2516 KB Output isn't correct
2 Halted 0 ms 0 KB -