답안 #632256

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
632256 2022-08-19T19:11:19 Z CyberCow Addk (eJOI21_addk) C++17
0 / 100
25 ms 3816 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;
int 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;
			int mi = min(l + m - 1, r - m), ma = max(l + m, r - m + 1);
			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;
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 1624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 3816 KB Output isn't correct
2 Halted 0 ms 0 KB -