Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- int n;
- vector<ll> a;
- map<ll, int> cnt;
- set<ll> b, c;
- ll get() {
- ll ans = 0;
- if (c.size() > 0) {
- ll x = -(*c.begin());
- ans = x * x;
- }
- if (b.size() > 1) {
- ll x = -(*b.begin());
- b.erase(-x);
- ll y = -(*b.begin());
- ans = max(ans, x * y);
- b.insert(-x);
- }
- return ans;
- }
- void update(int k, ll x) {
- if (k >= n) {
- return;
- }
- if (cnt[a[k]] == 2) {
- b.erase(-a[k]);
- } else if (cnt[a[k]] == 4) {
- c.erase(-a[k]);
- }
- cnt[a[k]]--;
- if (cnt[a[k]] == 0) {
- cnt.erase(a[k]);
- }
- a[k] = x;
- cnt[a[k]]++;
- if (cnt[a[k]] == 2) {
- b.insert(-a[k]);
- } else if (cnt[a[k]] == 4) {
- c.insert(-a[k]);
- }
- }
- int main() {
- cin >> n;
- a.resize(n);
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- cnt[a[i]]++;
- }
- for (auto e : cnt) {
- ll key = e.first;
- int value = e.second;
- if (value >= 2) {
- b.insert(-key);
- }
- if (value >= 4) {
- c.insert(-key);
- }
- }
- cout << get() << endl;
- int q;
- cin >> q;
- while (q--) {
- int k;
- ll x;
- cin >> k >> x;
- update(k - 1, x);
- cout << get() << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement