Language: C++

#include <bits/stdc++.h>
#include <omp.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;


#define int ll
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());


typedef pair<int, int> pii;
typedef pair<string, string> pst;
typedef pair<pii, pii> piii;
typedef vector<piii> vpii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<pii> vpi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef pair<pld, pld> pldd;
typedef vector<pld> vpd;
typedef complex<double> base;


#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define my_abs(a) (((a) >= 0) ? (a) : -(a))
#define mp(a, b) make_pair(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define MODIK(a) (a >= M ? a - M : a)
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cout << (#x) << " = " << x << endl;
#ifdef ART_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif


const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

istream &operator >> (istream &in, pii &a)
{
    in >> a.first >> a.second;
    return in;
}


ostream &operator << (ostream &out, pii &a)
{
    out << a.first << ' ' << a.second;
    return out;
}


istream &operator >> (istream &in, pld &a)
{
    in >> a.first >> a.second;
    return in;
}


ostream &operator << (ostream &out, pld &a)
{
    out << a.first << ' ' << a.second;
    return out;
}


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) <<
               ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void print(int a, int b, int n, vi h)
{
    ofstream cout("output.txt");
    cout << SZ(h) << ' ' << a << ' ' << b << '\n';
    for (int i = 0; i < SZ(h); ++i) {
        cout << h[i]  << ' ';
    }
    cout.close();
    exit(0);
}


inline bool break_time(ld time)
{
    return clock() > CLOCKS_PER_SEC * time;
}


ld get_rand_ld(ld l, ld r)
{
    uniform_real_distribution<double> gen(l, r);
    return gen(rng);
}


bool may(int E, ld T)
{
    if (E < 0)
        return 1;

    double eps = get_rand_ld(0, 1);
    return eps < exp(-E / T);
}


void smain();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

#ifdef ART_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef ART_HOME
    cout << "\nTOTAL EXECUTIOn TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}


const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
const int M1 = 1000000093, x1 = 27162;
const int M2 = 1000000087, x2 = 241;
const ld pi = atan2(1, 0) * 2;


int cnt[N];


void smain() {
    int n, q;
    cin >> n >> q;

    vi kek(n);
    for (int i = 0; i < n; ++i)
        cin >> kek[i];

    for (int i = 0; i < q; ++i)
    {
        fill(cnt, cnt + N, 0);
        for (int j = 1; j <= n; ++j)
            cnt[j] -= j;

        int ind, v;
        cin >> ind >> v;
        ind--;

        kek[ind] = v;
        for (int u : kek)
            cnt[u]++;

        int last = 0;
        int ans = 0;

        while (last != n)
        {
            int mx = -1;
            for (int j = last + 1; j <= n; ++j)
                mx = max(mx, cnt[j] + last);


            if (mx < 0)
            {
                ans += -(cnt[last + 1] + last);
                last++;
            }
            else {
                int ls = 0;
                for (int j = last + 1; j <= n; ++j)
                    if (cnt[j] + last >= 0)
                    {
                        ls = j;
                        break;
                    }

                last = ls;
            }
        }

        cout << ans << '\n';
    }
}#include <bits/stdc++.h>
#include <omp.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;


#define int ll
#define rand shittttty_shit
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());


typedef pair<int, int> pii;
typedef pair<string, string> pst;
typedef pair<pii, pii> piii;
typedef vector<piii> vpii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<pii> vpi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef pair<pld, pld> pldd;
typedef vector<pld> vpd;
typedef complex<double> base;


#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define my_abs(a) (((a) >= 0) ? (a) : -(a))
#define mp(a, b) make_pair(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define MODIK(a) (a >= M ? a - M : a)
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cout << (#x) << " = " << x << endl;
#ifdef ART_HOME
#define cerr cout
#else
#define cerr if (false) cerr
#endif


const double PI = 2 * acos(0.0);

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

istream &operator >> (istream &in, pii &a)
{
    in >> a.first >> a.second;
    return in;
}


ostream &operator << (ostream &out, pii &a)
{
    out << a.first << ' ' << a.second;
    return out;
}


istream &operator >> (istream &in, pld &a)
{
    in >> a.first >> a.second;
    return in;
}


ostream &operator << (ostream &out, pld &a)
{
    out << a.first << ' ' << a.second;
    return out;
}


template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) <<
               ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}


void print(int a, int b, int n, vi h)
{
    ofstream cout("output.txt");
    cout << SZ(h) << ' ' << a << ' ' << b << '\n';
    for (int i = 0; i < SZ(h); ++i) {
        cout << h[i]  << ' ';
    }
    cout.close();
    exit(0);
}


inline bool break_time(ld time)
{
    return clock() > CLOCKS_PER_SEC * time;
}


ld get_rand_ld(ld l, ld r)
{
    uniform_real_distribution<double> gen(l, r);
    return gen(rng);
}


bool may(int E, ld T)
{
    if (E < 0)
        return 1;

    double eps = get_rand_ld(0, 1);
    return eps < exp(-E / T);
}


void smain();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

#ifdef ART_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    cout << setprecision(12) << fixed;
    smain();
#ifdef ART_HOME
    cout << "\nTOTAL EXECUTIOn TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}


const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
const int M1 = 1000000093, x1 = 27162;
const int M2 = 1000000087, x2 = 241;
const ld pi = atan2(1, 0) * 2;


int cnt[N];


void smain() {
    int n, q;
    cin >> n >> q;

    vi kek(n);
    for (int i = 0; i < n; ++i)
        cin >> kek[i];

    for (int i = 0; i < q; ++i)
    {
        fill(cnt, cnt + N, 0);
        for (int j = 1; j <= n; ++j)
            cnt[j] -= j;

        int ind, v;
        cin >> ind >> v;
        ind--;

        kek[ind] = v;
        for (int u : kek)
            cnt[u]++;

        int last = 0;
        int ans = 0;

        while (last != n)
        {
            int mx = -1;
            for (int j = last + 1; j <= n; ++j)
                mx = max(mx, cnt[j] + last);


            if (mx < 0)
            {
                ans += -(cnt[last + 1] + last);
                last++;
            }
            else {
                int ls = 0;
                for (int j = last + 1; j <= n; ++j)
                    if (cnt[j] + last >= 0)
                    {
                        ls = j;
                        break;
                    }

                last = ls;
            }
        }

        cout << ans << '\n';
    }
}

Compiler output:
a.cc:235:2: error: stray '#' in program
  235 | }#include <bits/stdc++.h>
      |  ^
a.cc:235:3: error: 'include' does not name a type
  235 | }#include <bits/stdc++.h>
      |   ^~~~~~~
a.cc:247:9: error: redefinition of 'std::mt19937 rng'
  247 | mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      |         ^~~
a.cc:13:9: note: 'std::mt19937 rng' previously declared here
   13 | mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
      |         ^~~
a.cc:248:12: error: redefinition of 'std::mt19937_64 rng_64'
  248 | mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
      |            ^~~~~~
a.cc:14:12: note: 'std::mt19937_64 rng_64' previously declared here
   14 | mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
      |            ^~~~~~
a.cc:297:14: error: redefinition of 'const double PI'
  297 | const double PI = 2 * acos(0.0);
      |              ^~
a.cc:63:14: note: 'const double PI' previously defined here
   63 | const double PI = 2 * acos(0.0);
      |              ^~
a.cc:299:14: error: redefinition of 'const std::string DIGITS'
  299 | const string DIGITS = "0123456789";
      |              ^~~~~~
a.cc:65:14: note: 'const std::string DIGITS' previously declared here
   65 | const string DIGITS = "0123456789";
      |              ^~~~~~
a.cc:300:14: error: redefinition of 'const std::string ALPH'
  300 | const string ALPH = "abcdefghijklmnopqrstuvwxyz";
      |              ^~~~
a.cc:66:14: note: 'const std::string ALPH' previously declared here
   66 | const string ALPH = "abcdefghijklmnopqrstuvwxyz";
      |              ^~~~
a.cc:302:10: error: redefinition of 'std::istream& operator>>(std::istream&, pii&)'
  302 | istream &operator >> (istream &in, pii &a)
      |          ^~~~~~~~
a.cc:68:10: note: 'std::istream& operator>>(std::istream&, pii&)' previously defined here
   68 | istream &operator >> (istream &in, pii &a)
      |          ^~~~~~~~
a.cc:309:10: error: redefinition of 'std::ostream& operator<<(std::ostream&, pii&)'
  309 | ostream &operator << (ostream &out, pii &a)
      |          ^~~~~~~~
a.cc:75:10: note: 'std::ostream& operator<<(std::ostream&, pii&)' previously defined here
   75 | ostream &operator << (ostream &out, pii &a)
      |          ^~~~~~~~
a.cc:316:10: error: redefinition of 'std::istream& operator>>(std::istream&, pld&)'
  316 | istream &operator >> (istream &in, pld &a)
      |          ^~~~~~~~
a.cc:82:10: note: 'std::istream& operator>>(std::istream&, pld&)' previously defined here
   82 | istream &operator >> (istream &in, pld &a)
      |          ^~~~~~~~
a.cc:323:10: error: redefinition of 'std::ostream& operator<<(std::ostream&, pld&)'
  323 | ostream &operator << (ostream &out, pld &a)
      |          ^~~~~~~~
a.cc:89:10: note: 'std::ostream& operator<<(std::ostream&, pld&)' previously defined here
   89 | ostream &operator << (ostream &out, pld &a)
      |          ^~~~~~~~
a.cc:331:18: error: redefinition of 'template<class T0, class T1> std::ostream& operator<<(std::ostream&, std::pair<_T1, _T2>&)'
  331 | inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
      |                  ^~~~~~~~
a.cc:97:18: note: 'template<class T0, class T1> std::ostream& operator<<(std::ostream&, std::pair<_T1, _T2>&)' previously declared here
   97 | inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
      |                  ^~~~~~~~
a.cc:336:18: error: redefinition of 'template<class T0, class T1, class T2> std::ostream& operator<<(std::ostream&, std::tuple<T0, T1, T2>&)'
  336 | inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
      |                  ^~~~~~~~
a.cc:102:18: note: 'template<class T0, class T1, class T2> std::ostream& operator<<(std::ostream&, std::tuple<T0, T1, T2>&)' previously declared here
  102 | inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
      |                  ^~~~~~~~
a.cc:341:18: error: redefinition of 'template<class T0, class T1, class T2, class T3> std::ostream& operator<<(std::ostream&, std::tuple<T0, T1, T2, T3>&)'
  341 | inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
      |                  ^~~~~~~~
a.cc:107:18: note: 'template<class T0, class T1, class T2, class T3> std::ostream& operator<<(std::ostream&, std::tuple<T0, T1, T2, T3>&)' previously declared here
  107 | inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
      |                  ^~~~~~~~
a.cc:347:18: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, std::vector<_Tp>&)'
  347 | inline ostream & operator << (ostream &out, vector<T> &a) {
      |                  ^~~~~~~~
a.cc:113:18: note: 'template<class T> std::ostream& operator<<(std::ostream&, std::vector<_Tp>&)' previously declared here
  113 | inline ostream & operator << (ostream &out, vector<T> &a) {
      |                  ^~~~~~~~
a.cc:355:6: error: redefinition of 'void print(ll, ll, ll, vi)'
  355 | void print(int a, int b, int n, vi h)
      |      ^~~~~
a.cc:121:6: note: 'void print(ll, ll, ll, vi)' previously defined here
  121 | void print(int a, int b, int n, vi h)
      |      ^~~~~
a.cc:367:13: error: redefinition of 'bool break_time(ld)'
  367 | inline bool break_time(ld time)
      |             ^~~~~~~~~~
a.cc:133:13: note: 'bool break_time(ld)' previously defined here
  133 | inline bool break_time(ld time)
      |             ^~~~~~~~~~
a.cc:373:4: error: redefinition of 'ld get_rand_ld(ld, ld)'
  373 | ld get_rand_ld(ld l, ld r)
      |    ^~~~~~~~~~~
a.cc:139:4: note: 'ld get_rand_ld(ld, ld)' previously defined here
  139 | ld get_rand_ld(ld l, ld r)
      |    ^~~~~~~~~~~
a.cc:380:6: error: redefinition of 'bool may(ll, ld)'
  380 | bool may(int E, ld T)
      |      ^~~
a.cc:146:6: note: 'bool may(ll, ld)' previously defined here
  146 | bool may(int E, ld T)
      |      ^~~
a.cc:392:8: error: redefinition of 'int main()'
  392 | signed main() {
      |        ^~~~
a.cc:158:8: note: 'int main()' previously defined here
  158 | signed main() {
      |        ^~~~
a.cc:408:11: error: redefinition of 'const ll N'
  408 | const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
      |           ^
a.cc:174:11: note: 'const ll N' previously defined here
  174 | const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
      |           ^
a.cc:408:25: error: redefinition of 'const ll K'
  408 | const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
      |                         ^
a.cc:174:25: note: 'const ll K' previously defined here
  174 | const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
      |                         ^
a.cc:408:39: error: redefinition of 'const ll B'
  408 | const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
      |                                       ^
a.cc:174:39: note: 'const ll B' previously defined here
  174 | const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
      |                                       ^
a.cc:408:48: error: redefinition of 'const ll oo'
  408 | const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
      |                                                ^~
a.cc:174:48: note: 'const ll oo' previously defined here
  174 | const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
      |                                                ^~
a.cc:408:64: error: redefinition of 'const ll M'
  408 | const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
      |                                                                ^
a.cc:174:64: note: 'const ll M' previously defined here
  174 | const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
      |                                                                ^
a.cc:408:77: error: redefinition of 'const ll LOG'
  408 | const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
      |                                                                             ^~~
a.cc:174:77: note: 'const ll LOG' previously defined here
  174 | const int N = 2e2 + 10, K = 1e2 + 10, B = 400, oo = 1e9 + 100, M = 1e9 + 7, LOG = 20;
      |                                                                             ^~~
a.cc:409:11: error: redefinition of 'const ll M1'
  409 | const int M1 = 1000000093, x1 = 27162;
      |           ^~
a.cc:175:11: note: 'const ll M1' previously defined here
  175 | const int M1 = 1000000093, x1 = 27162;
      |           ^~
a.cc:409:28: error: redefinition of 'const ll x1'
  409 | const int M1 = 1000000093, x1 = 27162;
      |                            ^~
a.cc:175:28: note: 'const ll x1' previously defined here
  175 | const int M1 = 1000000093, x1 = 27162;
      |                            ^~
a.cc:410:11: error: redefinition of 'const ll M2'
  410 | const int M2 = 1000000087, x2 = 241;
      |           ^~
a.cc:176:11: note: 'const ll M2' previously defined here
  176 | const int M2 = 1000000087, x2 = 241;
      |           ^~
a.cc:410:28: error: redefinition of 'const ll x2'
  410 | const int M2 = 1000000087, x2 = 241;
      |                            ^~
a.cc:176:28: note: 'const ll x2' previously defined here
  176 | const int M2 = 1000000087, x2 = 241;
      |                            ^~
a.cc:411:10: error: redefinition of 'const ld pi'
  411 | const ld pi = atan2(1, 0) * 2;
      |          ^~
a.cc:177:10: note: 'const ld pi' previously defined here
  177 | const ld pi = atan2(1, 0) * 2;
      |          ^~
a.cc:414:5: error: redefinition of 'll cnt [210]'
  414 | int cnt[N];
      |     ^~~
a.cc:180:5: note: 'll cnt [210]' previously declared here
  180 | int cnt[N];
      |     ^~~
a.cc:417:6: error: redefinition of 'void smain()'
  417 | void smain() {
      |      ^~~~~
a.cc:183:6: note: 'void smain()' previously defined here
  183 | void smain() {
      |      ^~~~~