#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
main()
{
freopen("river.in", "r", stdin);
freopen("river.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int n, p;
cin >> n >> p;
ordered_set points;
points.insert(0);
int64_t ans = 0;
while(n--)
{
int x;
cin >> x;
ans += x * x;
points.insert(*--points.end() + x);
}
points.insert(2e9);
cout << ans << "\n";
cin >> n;
while(n--)
{
int t, x;
cin >> t >> x;
auto it = points.find_by_order(x);
auto it1 = it, it2 = it;
int64_t v = *it;
int64_t l = *--it1;
int64_t ll = 0;
if(l != 0)
ll = *--it1;
int64_t r = *++it2;
ans -= (v - l) * (v - l);
int m = (v + l) / 2;
points.insert(m);
if(t == 1)
{
points.erase(v);
points.erase(l);
if(l == 0)
{
points.erase(m);
points.insert(l);
ans -= (r - v) * (r - v);
ans += r * r;
}
else if(r == 2e9)
{
points.erase(m);
points.insert(v);
ans -= (l - ll) * (l - ll);
ans += (v - ll) * (v - ll);
}
else
{
ans -= (r - v) * (r - v);
ans -= (l - ll) * (l - ll);
ans += (r - m) * (r - m);
ans += (m - ll) * (m - ll);
}
}
else
{
ans += (m - v) * (m - v);
ans += (m - l) * (m - l);
}
cout << ans << "\n";
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KI2luY2x1ZGUgPGV4dC9wYl9kcy90cmVlX3BvbGljeS5ocHA+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp1c2luZyBuYW1lc3BhY2UgX19nbnVfcGJkczsKCnR5cGVkZWYgdHJlZTwKaW50LApudWxsX3R5cGUsCmxlc3M8aW50PiwKcmJfdHJlZV90YWcsCnRyZWVfb3JkZXJfc3RhdGlzdGljc19ub2RlX3VwZGF0ZT4gb3JkZXJlZF9zZXQ7CgptYWluKCkKewogICAgZnJlb3Blbigicml2ZXIuaW4iLCAiciIsIHN0ZGluKTsKICAgIGZyZW9wZW4oInJpdmVyLm91dCIsICJ3Iiwgc3Rkb3V0KTsKICAgIGlvczo6c3luY193aXRoX3N0ZGlvKDApOwogICAgY2luLnRpZSgwKTsKICAgIGludCBuLCBwOwogICAgY2luID4+IG4gPj4gcDsKICAgIG9yZGVyZWRfc2V0IHBvaW50czsKICAgIHBvaW50cy5pbnNlcnQoMCk7CiAgICBpbnQ2NF90IGFucyA9IDA7CiAgICB3aGlsZShuLS0pCiAgICB7CiAgICAgICAgaW50IHg7CiAgICAgICAgY2luID4+IHg7CiAgICAgICAgYW5zICs9IHggKiB4OwogICAgICAgIHBvaW50cy5pbnNlcnQoKi0tcG9pbnRzLmVuZCgpICsgeCk7CiAgICB9CiAgICBwb2ludHMuaW5zZXJ0KDJlOSk7CiAgICBjb3V0IDw8IGFucyA8PCAiXG4iOwogICAgY2luID4+IG47CiAgICB3aGlsZShuLS0pCiAgICB7CiAgICAgICAgaW50IHQsIHg7CiAgICAgICAgY2luID4+IHQgPj4geDsKICAgICAgICBhdXRvIGl0ID0gcG9pbnRzLmZpbmRfYnlfb3JkZXIoeCk7CiAgICAgICAgYXV0byBpdDEgPSBpdCwgaXQyID0gaXQ7CiAgICAgICAgaW50NjRfdCB2ID0gKml0OwogICAgICAgIGludDY0X3QgbCA9ICotLWl0MTsKICAgICAgICBpbnQ2NF90IGxsID0gMDsKICAgICAgICBpZihsICE9IDApCiAgICAgICAgICAgIGxsID0gKi0taXQxOwogICAgICAgIGludDY0X3QgciA9ICorK2l0MjsKICAgICAgICBhbnMgLT0gKHYgLSBsKSAqICh2IC0gbCk7CiAgICAgICAgaW50IG0gPSAodiArIGwpIC8gMjsKICAgICAgICBwb2ludHMuaW5zZXJ0KG0pOwogICAgICAgIGlmKHQgPT0gMSkKICAgICAgICB7CiAgICAgICAgICAgIHBvaW50cy5lcmFzZSh2KTsKICAgICAgICAgICAgcG9pbnRzLmVyYXNlKGwpOwogICAgICAgICAgICBpZihsID09IDApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHBvaW50cy5lcmFzZShtKTsKICAgICAgICAgICAgICAgIHBvaW50cy5pbnNlcnQobCk7CiAgICAgICAgICAgICAgICBhbnMgLT0gKHIgLSB2KSAqIChyIC0gdik7CiAgICAgICAgICAgICAgICBhbnMgKz0gciAqIHI7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBpZihyID09IDJlOSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcG9pbnRzLmVyYXNlKG0pOwogICAgICAgICAgICAgICAgcG9pbnRzLmluc2VydCh2KTsKICAgICAgICAgICAgICAgIGFucyAtPSAobCAtIGxsKSAqIChsIC0gbGwpOwogICAgICAgICAgICAgICAgYW5zICs9ICh2IC0gbGwpICogKHYgLSBsbCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBhbnMgLT0gKHIgLSB2KSAqIChyIC0gdik7CiAgICAgICAgICAgICAgICBhbnMgLT0gKGwgLSBsbCkgKiAobCAtIGxsKTsKICAgICAgICAgICAgICAgIGFucyArPSAociAtIG0pICogKHIgLSBtKTsKICAgICAgICAgICAgICAgIGFucyArPSAobSAtIGxsKSAqIChtIC0gbGwpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGFucyArPSAobSAtIHYpICogKG0gLSB2KTsKICAgICAgICAgICAgYW5zICs9IChtIC0gbCkgKiAobSAtIGwpOwogICAgICAgIH0KICAgICAgICBjb3V0IDw8IGFucyA8PCAiXG4iOwogICAgfQp9