# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
734376 |
2023-05-02T10:45:11 Z |
borisAngelov |
Addk (eJOI21_addk) |
C++17 |
|
25 ms |
4496 KB |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, q, k;
long long a[maxn];
long long preffix_sum[maxn];
long long preffix_cyc[maxn];
long long suffix_sum[maxn];
long long suffix_cyc[maxn];
char current_symbol;
int resulting_number;
int read()
{
resulting_number = 0;
current_symbol = getchar();
while (isdigit(current_symbol) == false)
{
current_symbol = getchar();
}
while (isdigit(current_symbol) == true)
{
resulting_number *= 10;
resulting_number += (current_symbol - '0');
current_symbol = getchar();
}
return resulting_number;
}
long long calc_preffix(int from, int to, long long coeficient)
{
if (from > to)
{
return 0LL;
}
return (preffix_sum[to] - preffix_sum[from - 1]) * coeficient;
}
long long calc_suffix(int from, int to, long long coeficient)
{
if (from > to)
{
return 0LL;
}
return (suffix_sum[from] - suffix_sum[to + 1]) * coeficient;
}
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
n = read();
k = read();
for (int i = 1; i <= n; ++i)
{
a[i] = read();
preffix_sum[i] = preffix_sum[i - 1] + a[i];
preffix_cyc[i] = preffix_cyc[i - 1] + (1LL * i) * a[i];
}
for (int i = n; i >= 1; --i)
{
suffix_sum[i] = suffix_sum[i + 1] + a[i];
suffix_cyc[i] = suffix_cyc[i + 1] + (1LL * (n - i + 1)) * a[i];
}
q = read();
for (int i = 1; i <= q; ++i)
{
int type;
cin >> type;
if (type == 1)
{
int x;
cin >> x;
}
else
{
int l, r, m;
cin >> l >> r >> m;
if (m == r - l + 1)
{
cout << calc_preffix(l, r, 1) << "\n";
continue;
}
int from = l + m - 1;
int to = r - m + 1;
long long ans = calc_preffix(from, to, m);
if (from <= to)
{
int last_preffix = from - 1;
long long add_preffix = preffix_cyc[last_preffix] - preffix_cyc[l - 1] - calc_preffix(l, last_preffix, l - 1);
int last_suffix = to + 1;
long long add_suffix = suffix_cyc[last_suffix] - suffix_cyc[r + 1] - calc_suffix(last_suffix, r, n - r);
ans += add_preffix;
ans += add_suffix;
}
else
{
int coeficient = r - l + 2 - m;
from = l + coeficient - 1;
to = r - coeficient + 1;
long long add_middle_sum = calc_preffix(from, to, coeficient);
//cout << "middle test " << add_middle_sum << " [" << from << ", " << to << "] and " << coeficient << endl;
ans += add_middle_sum;
int last_preffix = from - 1;
long long add_preffix = preffix_cyc[last_preffix] - preffix_cyc[l - 1] - calc_preffix(l, last_preffix, l - 1);
int last_suffix = to + 1;
long long add_suffix = suffix_cyc[last_suffix] - suffix_cyc[r + 1] - calc_suffix(last_suffix, r, n - r);
ans += add_preffix;
ans += add_suffix;
}
cout << ans << "\n";
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1840 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
4496 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |