Problem:
Color Inversion on a Huge Chessboard
You are given a set of square cells arranged in a chessboard-like pattern with n horizontal rows and n vertical columns. Rows are numbered 1 through n from top to bottom, and columns are also numbered 1 through n from left to right.
Initially, the cells are colored as in a chessboard, that is, the cell in the row $i$ and the column $j$ is colored black if $i + j$ is odd and is colored white if it is even.
Color-inversion operations, each of which is one of the following two, are made one after another.
Invert colors of a row:
Given a row number, invert colors of all the cells in the specified row.
The white cells in the row become black and the black ones become white.
Invert colors of a column:
Given a column number, invert colors of all the cells in the specified column. The white cells in the column become black and the black ones become white.
The number of distinct areas after each of the operations should be counted. Here, an area means a group of directly or indirectly connected cells of the same color. Two cells are said to be directly connected when they share an edge.
Input
The input consists of a single test case of the following format.
$n$ $q$
$operation_1$
.
.
.
$operation_q$
The integer $n$ is the number of rows and columns ($1 \leq n \leq 5 \times 10^5$). The integer $q$ is the number of operations ($1 \leq q \leq 5 \times 10^5$). The following $q$ lines represent operations to be made in this order. Each of them is given in either of the following forms.
ROW
$i$: the operation “invert colors of a row” applied to the row $i$ ($1 \leq i \leq n$).
COLUMN
$j$: the operation “invert colors of a column” applied to the column $j$ ($1 \leq j \leq n$).
Output
Output $q$ lines. The $k$-th line should contain an integer denoting the number of areas after the $k$-th operation is made.
Sample Input 1
3 3
ROW 2
COLUMN 3
ROW 2
Sample Output 1
3
2
6
Sample Input 2
200000 2
ROW 1
ROW 1
Sample Output 2
39999800000
40000000000
Figure F.1. Illustration of Sample Input 1

Submitted solutions:

code_snippet: #include  <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(ll i=0;i<n;i++)
using VLL = vector<ll>;

int main() {
    ll n, q;
    cin >> n >> q;
    if (n == 1) {
        rep(i, q) {
            string key;
            ll p;
            cin >> key >> p;
            cout << 1 << endl;
        }
        return 0;
    }

    vector<bool> row(n - 1, true);
    vector<bool> col(n - 1, true);

    ll rowN = n;
    ll colN = n;
    ll ans = n * n;
    while (q--) {
        string key;
        ll p;
        cin >> key >> p;
        ll k = 0;
        if (key == "ROW") {
            if (p == 1) {
                if (row[0]) {
                    k = -1;
                } else {
                    k = 1;
                }
                row[0] = !row[0];
            } else if (p == n) {
                if (row[n - 2]) {
                    k = -1;
                } else {
                    k = 1;
                }

                row[n - 2] = !row[n - 2];
            } else {
                if (row[p - 1]) k -= 1;
                else k += 1;
                if (row[p - 2])k -= 1;
                else k += 1;
                row[p - 1] = !row[p - 1];
                row[p - 2] = !row[p - 2];
            }
            rowN += k;
            ans += k * colN;
        } else {
            // key == col
            if (p == 1) {
                if (col[0]) {
                    k = -1;
                } else {
                    k = 1;
                }
                col[0] = !col[0];
            } else if (p == n) {
                if (col[n - 2]) {
                    k = -1;
                } else {
                    k = 1;
                }

                col[n - 2] = !col[n - 2];
            } else {
                if (col[p - 1]) k -= 1;
                else k += 1;
                if (col[p - 2])k -= 1;
                else k += 1;
                col[p - 2] = !col[p - 2];
                col[p - 1] = !col[p - 1];
            }
            colN += k;
            ans += k * rowN;
        }
        cout << ans << endl;
    }
}
accuracy: 1
time_ms: 520
memory_kb: 3568
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using a2 = array<ll, 2>;
using a3 = array<ll, 3>;

bool chmin(auto& a, const auto& b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, const auto& b) { return a < b ? a = b, 1 : 0; }

ll mod = 998244353;

ifstream in;
ofstream out;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    if(argc > 2) {
        in.open(argv[1]);
        cin.rdbuf(in.rdbuf());
        out.open(argv[2]);
        cout.rdbuf(out.rdbuf());
    }

    ll n, q;
    cin >> n >> q;
    vector<ll> row(n, 0), col(n, 0);
    for(int i = 1; i < n; i += 2) {
        row[i]++;
        col[i]++;
    }
    ll cntr = n, cntc = n;

    for(int i = 0; i < q; i++) {
        string s;
        ll a;
        cin >> s >> a;
        a--;
        if(s == "ROW") {
            if(a != 0) {
                cntc -= (col[a - 1] != col[a]);
            }
            if(a != n - 1) {
                cntc -= (col[a + 1] != col[a]);
            }
            col[a] ^= 1;
            if(a != 0) {
                cntc += (col[a - 1] != col[a]);
            }
            if(a != n - 1) {
                cntc += (col[a + 1] != col[a]);
            }
        } else {
            if(a != 0) {
                cntr -= (row[a - 1] != row[a]);
            }
            if(a != n - 1) {
                cntr -= (row[a + 1] != row[a]);
            }
            row[a] ^= 1;
            if(a != 0) {
                cntr += (row[a - 1] != row[a]);
            }
            if(a != n - 1) {
                cntr += (row[a + 1] != row[a]);
            }
        }
        cout << cntc * cntr << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 240
memory_kb: 11184
final_rank: 11

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef vector<int> vi;
template <class T>
inline bool chmin(T& a, T b) {
  return ((a > b) ? (a = b, 1) : (0));
}
template <class T>
inline bool chmax(T& a, T b) {
  return ((a < b) ? (a = b, 1) : (0));
}
#define YesNo(f) cout << (f ? "Yes" : "No") << endl

void solve();
int main() {
  int T = 1;
  // cin >> T;
  while (T--) solve();
  return 0;
}

void solve() {  // solver
  int N, Q;
  cin >> N >> Q;
  vi r(N), c(N);
  rep(i, 0, N) r[i] = c[i] = i % 2;
  ll ans = ll(N) * ll(N);
  int rm = N, cm = N;
  while (Q--) {
    string op;
    cin >> op;
    int i;
    cin >> i;
    i--;
    if (op == "ROW") {
      rep(dd, -1, 2) {
        int ni = i + dd;
        if (ni < 0 || ni >= N || i == ni) continue;
        int a = 1;
        if (r[i] != r[ni]) a = -1;
        ans += a * rm;
        cm += a;
      }
      r[i] = 1 - r[i];
    } else {
      rep(dd, -1, 2) {
        int ni = i + dd;
        if (ni < 0 || ni >= N || i == ni) continue;
        int a = 1;
        if (c[i] != c[ni]) a = -1;
        ans += a * cm;
        rm += a;
      }
      c[i] = 1 - c[i];
    }
    cout << ans << endl;
  }
  return;
}
/*
icpc-r-2023-f
行と列は別々に考えてよさそう
その行単体で見た時の連結成分数mを保持 このmは全部の行で同じ
指定行の隣行をみて反転具合が同じだったら連結成分数をm増やす　違うならm減らす
列が反転したときmも変わるので調整
列も同様
*/
accuracy: 1
time_ms: 340
memory_kb: 7296
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;

bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; }
bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N, Q;
    cin >> N >> Q;

    vector<ll> r(N), c(N);
    for(int i = 0; i < N; i++) {
        r[i] = c[i] = i & 1;
    }

    ll p = N, q = N;
    while(Q--) {
        string s; int i;
        cin >> s >> i;
        i--;
        if(N == 1) {
            // do nothing
        }else if(s == "ROW") {
            if(i == 0) {
                p += (r[0] == r[1] ? 1 : -1);
            }else if(i == N - 1) {
                p += (r[N - 1] == r[N - 2] ? 1 : -1);
            }else if(r[i - 1] == r[i + 1]) {
                p += (r[i] == r[i + 1] ? 2 : -2);
            }
            r[i] ^= 1;
        }else if(s == "COLUMN") {
            if(i == 0) {
                q += (c[0] == c[1] ? 1 : -1);
            }else if(i == N - 1) {
                q += (c[N - 1] == c[N - 2] ? 1 : -1);
            }else if(c[i - 1] == c[i + 1]) {
                q += (c[i] == c[i + 1] ? 2 : -2);
            }
            c[i] ^= 1;
        }
        cout << p * q << "\n";
    }
}
accuracy: 1
time_ms: 60
memory_kb: 11184
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

using ll = long long;

bool chmin(auto &a, auto b) { return a > b ? a = b, true : false; }
bool chmax(auto &a, auto b) { return a < b ? a = b, true : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, Q;
    cin >> N >> Q;
    vector<bool> dr(N - 1), dc(N - 1);
    ll R = N, C = N;
    while (Q--) {
        string S;
        int k;
        cin >> S >> k;
        k--;
        if (S[0] == 'R') {
            if (k > 0) {
                C += (dr[k - 1] ? 1 : -1);
                dr[k - 1] = !dr[k - 1];
            }
            if (k < N - 1) {
                C += (dr[k] ? 1 : -1);
                dr[k] = !dr[k];
            }
        } else {
            if (k > 0) {
                R += (dc[k - 1] ? 1 : -1);
                dc[k - 1] = !dc[k - 1];
            }
            if (k < N - 1) {
                R += (dc[k] ? 1 : -1);
                dc[k] = !dc[k];
            }
        }
        cout << R * C << '\n';
    }
}
accuracy: 1
time_ms: 60
memory_kb: 3712
final_rank: 1

code_snippet: /*
 *   author : cellul4r
 */
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
#define all(x) x.begin(), x.end()
const char nl = '\n';
const int N =5e5+1;
const int INF = 1e9+7;
const ll LINF = 1e18+7;

void setIO(string);
int n,q;
int row[N], col[N];
void solve(){

    cin>>n>>q;


    auto f = [&](int x, int y) {
        return x ^ y;
    };
    ll ans;
    ll rEdge = 0, cEdge = 0;
    // edge 0...n-1
    for(int i = 0; i < q; i++) {
        string op;
        int x; cin>>op>>x;
        x--;
        if(op == "ROW") {
            if(x > 0) rEdge -= f(row[x-1], row[x]);
            if(x < n-1) rEdge -= f(row[x], row[x+1]);
            row[x] ^= 1;

            if(x > 0) rEdge += f(row[x-1], row[x]);
            if(x < n-1) rEdge += f(row[x], row[x+1]);
        } else {
            if(x > 0) cEdge -= f(col[x-1], col[x]);
            if(x < n-1) cEdge -= f(col[x], col[x+1]);
            col[x] ^= 1;

            if(x > 0) cEdge += f(col[x-1], col[x]);
            if(x < n-1) cEdge += f(col[x], col[x+1]);

        }
        ans = (1ll * n - rEdge) * (1ll * n - cEdge);
        cout << ans << nl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;

    //setIO("");
    //cin>>t;
    while(t--)solve();

    return 0;
}

void setIO(string s) {
    (void)!freopen((s + ".in").c_str(), "r", stdin);
    (void)!freopen((s + ".out").c_str(), "w", stdout);
}
accuracy: 1
time_ms: 80
memory_kb: 7368
final_rank: 5

code_snippet: /*
 *   author : cellul4r
 */
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
#define all(x) x.begin(), x.end()
const char nl = '\n';
const int N =1e3+1;
const int INF = 1e9+7;
const ll LINF = 1e18+7;

void setIO(string);
int n,q;
int row[N], col[N];
void solve(){

    cin>>n>>q;


    auto f = [&](int x, int y) {
        return x ^ y;
    };
    ll ans;
    ll rEdge = 0, cEdge = 0;
    // edge 0...n-1
    for(int i = 0; i < q; i++) {
        string op;
        int x; cin>>op>>x;
        x--;
        if(op == "ROW") {
            if(x > 0) rEdge -= f(row[x-1], row[x]);
            if(x < n-1) rEdge -= f(row[x], row[x+1]);
            row[x] ^= 1;

            if(x > 0) rEdge += f(row[x-1], row[x]);
            if(x < n-1) rEdge += f(row[x], row[x+1]);
        } else {
            if(x > 0) cEdge -= f(col[x-1], col[x]);
            if(x < n-1) cEdge -= f(col[x], col[x+1]);
            col[x] ^= 1;

            if(x > 0) cEdge += f(col[x-1], col[x]);
            if(x < n-1) cEdge += f(col[x], col[x+1]);

        }
        ans = (1ll * n - rEdge) * (1ll * n - cEdge);
        cout << ans << nl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;

    //setIO("");
    //cin>>t;
    while(t--)solve();

    return 0;
}

void setIO(string s) {
    (void)!freopen((s + ".in").c_str(), "r", stdin);
    (void)!freopen((s + ".out").c_str(), "w", stdout);
}
accuracy: 0.13333333333333333
time_ms: 60
memory_kb: 3400
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) begin(v), end(v)
#define len(x) ((int)size(x))
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = V<V<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, q;
    cin >> n >> q;
    vector<bool> a(n), b(n);
    rep(i, n) a[i] = b[i] = (i % 2 == 0);
    ll A = n, B = n;
    while (q--) {
        string s;
        int i;
        cin >> s >> i;
        i--;

        if (s == "ROW") {
            if (i && a[i] != a[i - 1]) A--;
            if (i + 1 < n && a[i] != a[i + 1]) A--;
            a[i] = !a[i];
            if (i && a[i] != a[i - 1]) A++;
            if (i + 1 < n && a[i] != a[i + 1]) A++;
        } else {
            if (i && b[i] != b[i - 1]) B--;
            if (i + 1 < n && b[i] != b[i + 1]) B--;
            b[i] = !b[i];
            if (i && b[i] != b[i - 1]) B++;
            if (i + 1 < n && b[i] != b[i + 1]) B++;
        }
        cout << A * B << "\n";
    }
}
accuracy: 1
time_ms: 80
memory_kb: 3600
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep2(i, n) for(int i = 0; i < (n); i++)
#define rep3(i, a, b) for(int i = a; i < (b); i++)
#define overload(a, b, c, d, ...) d
#define rep(...) overload(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(a) begin(a), end(a)
#define sz(a) ssize(a)
bool chmin(auto& a, auto b) { return a > b ? a = b, 1 : 0; }
bool chmax(auto& a, auto b) { return a < b ? a = b, 1 : 0; }

void solve() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n), b(n);
    rep(i, n) a[i] = b[i] = i % 2;
    ll numA = n - 1;
    ll numB = n - 1;
    while (q--) {
        int i;
        string t;
        cin >> t >> i;
        i--;
        if (t == "ROW") {
            if (i > 0) numA += (a[i - 1] == a[i] ? 1 : -1);
            if (i + 1 < n) numA += (a[i + 1] == a[i] ? 1 : -1);
            a[i] ^= 1;
        } else {
            if (i > 0) numB += (b[i - 1] == b[i] ? 1 : -1);
            if (i + 1 < n) numB += (b[i + 1] == b[i] ? 1 : -1);
            b[i] ^= 1;
        }
        cout << (numA + 1) * (numB + 1) << '\n';
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
}
accuracy: 1
time_ms: 50
memory_kb: 7296
final_rank: 4

code_snippet: #include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 500010;
typedef long long LL;
int n, m;
LL r[N], c[N];
int main()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)r[i] = c[i] = i & 1;
    LL nr = n, nc = n;
    string op;
    LL x;
    for(int i = 1; i <= m; i ++)
    {
        cin >> op >> x;
        if(n == 1)
        {
            cout << 1 << endl;
            continue;
        }
        if(op == "ROW")
        {
            r[x] ^= 1;
            if(x == 1)
            {
                if(r[x] != r[x + 1])nr ++;
                else nr --;
            }
            else if(x == n)
            {
                if(r[x] != r[x - 1])nr ++;
                else nr --;
            }
            else
            {
                if(r[x] != r[x + 1] && r[x] != r[x - 1])nr += 2;
                else if(r[x] == r[x + 1] && r[x] == r[x - 1])nr -= 2;
            }
        }
        else
        {
            c[x] ^= 1;
            if(x == 1)
            {
                if(c[x] != c[x + 1])nc ++;
                else nc --;
            }
            else if(x == n)
            {
                if(c[x] != c[x - 1])nc ++;
                else nc --;
            }
            else
            {
                if(c[x] != c[x + 1] && c[x] != c[x - 1])nc += 2;
                else if(c[x] == c[x + 1] && c[x] == c[x - 1])nc -= 2;
            }
        }
        cout << (LL)nr * nc << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 520
memory_kb: 11260
final_rank: 16

code_snippet: #include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = r-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
// #define MOD 1000000007
#define MOD 998244353
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}


int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  ll n,q;cin >> n >> q;
  string s1 = string(n,'W');
  string s2 = string(n,'W');
  ll C1 = n,C2 = n;
  for(int i = 1;i < n;i += 2)s1[i] = 'B';
  for(int i = 1;i < n;i += 2)s2[i] = 'B';
  rep(_,0,q){
    string op;ll x;cin >> op >> x;
    x--;
    auto f = [&](string &s,ll &C,int x)->void{
      if(sz(s) == 1)return;
      int cnt = 0;
      if(x == 0){
        cnt += (s[x+1] == s[x]);
        if(cnt)C++;
        else C--;
      }else if(x == n-1){
        cnt += (s[x-1] == s[x]);
        if(cnt)C++;
        else C--;
      }else{
        cnt += (s[x-1] == s[x]);
        cnt += (s[x+1] == s[x]);
        if(cnt == 2)C += 2;
        else if(cnt == 0)C -= 2;
      }
      s[x] = 'B' + 'W' - s[x];
    };
    if(op[0] == 'R')f(s1,C1,x);
    else f(s2,C2,x);
    cout << C1*C2 << "\n";
  }
  

  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 4132
final_rank: 3

code_snippet: #include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")

using namespace std;
using ll = long long;
#define rep(i, n) for (ll i=0; i<(n); i++)
#define all(a) (a).begin(), (a).end()
template<typename S, typename T> bool chmin(S &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename S, typename T> bool chmax(S &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename Container> ll sz(const Container &c) {return (ll)((c).size());}
struct FastIo {FastIo() {cin.tie(nullptr); ios::sync_with_stdio(false);}} fast_io;
const ll INF = (1LL << 61);

int main() {
    ll n,q; cin >> n >> q;
    ll r(n), c(n);
    vector<ll> rv(n), cv(n);
    rep(i, n) {rv[i] = i & 1; cv[i] = i & 1;}
    rep(i, q) {
        string s; cin >> s;
        auto f = [&] (vector<ll> &rv, ll & r, ll i) {
            if (i > 0) r -= (rv[i] != rv[i-1]);
            if (i < n-1) r -= (rv[i] != rv[i+1]);
            rv[i] ^= 1;
            if (i > 0) r += (rv[i] != rv[i-1]);
            if (i < n-1) r += (rv[i] != rv[i+1]);
        };
        if (s == "ROW") {
            ll x; cin >> x; x--;
            f(rv, r, x);
        } else {
            ll x; cin >> x; x--;
            f(cv, c, x);
        }
        cout << (r * c) << '\n';
    }
}
accuracy: 1
time_ms: 80
memory_kb: 10904
final_rank: 8

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n); i >= 0; i--)
#define range(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
using ll = long long;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i == (v.size() - 1) ? "" : ", ");
    }
    os << "]";
    return os;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2> p) {
    os << "{" << p.first << ", " << p.second << "}";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T> s) {
    if (s.empty()) {
        os << "{}";
        return os;
    }
    os << "{";
    auto it = s.begin();
    while (it != s.end()) {
        cout << *it << (++it == s.end() ? "}" : ", ");
    }
    return os;
}

int main() {
    ll n, q;
    cin >> n >> q;
    ll cnt_row = n, cnt_col = n;
    ll ans = n * n;
    vector<int> row(n), col(n);
    rep(i, n) {
        row[i] = i & 1;
        col[i] = i & 1;
    }
    rep(_, q) {
        string s;
        int i;
        cin >> s >> i;
        i--;
        if (s[0] == 'R') {
            for (int di : {1, -1}) {
                if (i + di < 0 || i + di >= n) continue;
                if (row[i + di] != row[i]) {
                    ans -= cnt_col;
                    cnt_row--;
                } else {
                    ans += cnt_col;
                    cnt_row++;
                }
            }
            row[i] ^= 1;
        } else {
            for (int di : {1, -1}) {
                if (i + di < 0 || i + di >= n) continue;
                if (col[i + di] != col[i]) {
                    ans -= cnt_row;
                    cnt_col--;
                } else {
                    ans += cnt_row;
                    cnt_col++;
                }
            }
            col[i] ^= 1;
        }
        cout << ans << "\n";
    }
}
accuracy: 1
time_ms: 340
memory_kb: 7296
final_rank: 12

code_snippet: // AOJ 1449 - Color Inversion on a Huge Chessboard
// ICPC Asia Japan Regional Contest 2023 - Problem F

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int n, q; cin >> n >> q;
    set<int> r, c;
    for(int i=0; i<n-1; ++i) {
        r.insert(i);
        c.insert(i);
    }
    ll area = (ll)n * n;
    for(int i=0; i<q; ++i) {
        string op; int k; cin >> op >> k; --k;
        if(op == "ROW") {
            if(k > 0) {
                if(r.count(k-1)) {
                    area -= c.size() + 1;
                    r.erase(k-1);
                } else {
                    area += c.size() + 1;
                    r.insert(k-1);
                }
            }
            if(k < n-1) {
                if(r.count(k)) {
                    area -= c.size() + 1;
                    r.erase(k);
                } else {
                    area += c.size() + 1;
                    r.insert(k);
                }
            }
        } else {
            if(k > 0) {
                if(c.count(k-1)) {
                    area -= r.size() + 1;
                    c.erase(k-1);
                } else {
                    area += r.size() + 1;
                    c.insert(k-1);
                }
            }
            if(k < n-1) {
                if(c.count(k)) {
                    area -= r.size() + 1;
                    c.erase(k);
                } else {
                    area += r.size() + 1;
                    c.insert(k);
                }
            }
        }
        cout << area << endl;
    }
}
accuracy: 1
time_ms: 1030
memory_kb: 50432
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define vl vector<ll>
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, a, b) for (ll i = a; i <= (ll)b; ++i)

int dx[] = {1, 0, 0, -1};
int dy[] = {0, 1, -1, 0};

int main(){
	ll n,q;
	cin>>n>>q;
	ll yoko=n,tate=n;
	vl row(n,0),col(n,0);
	while(q--){
		string rc;
		ll i;
		cin>>rc>>i;
		i--;
		if(rc=="ROW"){
			if(i!=0){
				if(row[i]^row[i-1]==0)yoko--;
				else yoko++;	
			}
			if(i!=n-1){
				if(row[i]^row[i+1]==0)yoko--;
				else yoko++;
			}
			row[i]^=1;
		}else{
			if(i!=0){
				if(col[i]^col[i-1]==0)tate--;
				else tate++;
			}
			if(i!=n-1){
				if(col[i]^col[i+1]==0)tate--;
				else tate++;
			}
			col[i]^=1;
		}
		cout<<yoko*tate<<endl;
	}
}
accuracy: 1
time_ms: 330
memory_kb: 11160
final_rank: 14

code_snippet: #include<iostream>
#include<string>
#include<utility>
#include<algorithm>
#include<vector>
using namespace std;
using ll= long long;
#define rep(i,n) for(ll i=0; i<ll(n); i++)
#define repr(i,n) for(ll i=(n)-1; i>=0; i--)
template<class T> void chmin(T& l, T r){ if(r < l) l = r; }
template<class T> void chmax(T& l, T r){ if(l < r) l = r; }

void testcase(){
    ll n, q; cin >> n >> q;
    ll x = n, y = n;
    vector<ll> cx(n), cy(n);
    rep(i,n) cx[i] = cy[i] = i%2;
    auto fl = [&](vector<ll>& c, ll& q, ll a) -> void {
        if(a != 0) q -= (c[a] ^ c[a-1]);
        if(a != n-1) q -= (c[a] ^ c[a+1]);
        c[a] ^= 1;
        if(a != 0) q += (c[a] ^ c[a-1]);
        if(a != n-1) q += (c[a] ^ c[a+1]);
    };
    rep(qi,q){
        string s; cin >> s;
        ll a; cin >> a; a--;
        if(s == "ROW"){
            fl(cx, x, a);
        } else {
            fl(cy, y, a);
        }
        cout << (x * y) << "\n";
    }
}


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    testcase();
    return 0;
}
accuracy: 1
time_ms: 80
memory_kb: 10924
final_rank: 9

code_snippet: #include<iostream>
#include<string>
#include<utility>
#include<algorithm>
#include<vector>
using namespace std;
using ll= long long;
#define rep(i,n) for(ll i=0; i<ll(n); i++)
#define repr(i,n) for(ll i=(n)-1; i>=0; i--)
template<class T> void chmin(T& l, T r){ if(r < l) l = r; }
template<class T> void chmax(T& l, T r){ if(l < r) l = r; }

void testcase(){
    ll n, q; cin >> n >> q;
    ll x = n, y = n;
    vector<ll> cx(n), cy(n);
    rep(i,n) cx[i] = cy[i] = i%2;
    auto fl = [&](vector<ll>& c, ll& q, ll a) -> void {
        if(a != 0) q -= (c[a] ^ c[a-1]);
        if(a != n-1) q -= (c[a] ^ c[a+1]);
        c[a] ^= 1;
        if(a != 0) q += (c[a] ^ c[a-1]);
        if(a != n-1) q += (c[a] ^ c[a+1]);
    };
    rep(qi,q){
        string s; cin >> s;
        ll a; cin >> a; a--;
        if(s == "ROW"){
            fl(cx, x, a);
        } else {
            fl(cy, y, a);
        }
        cout << (x * y) << "\n";
    }
}


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    testcase();
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 10896
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,l,r) for(ll i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define sz(A) ((ll)(A.size()))
struct segtree{
    ll op(ll a,ll b){return min(a,b);}
    ll e(){return 1e18;}
    vector<ll>seg;
    ll n;
    segtree(ll N){
        n=1;
        while(n<N)n<<=1;
        seg.assign(2*n,e());
    }
    void set(ll i,ll x){
        i+=n;
        seg[i]=x;
        while(i>1){
            i>>=1;
            seg[i]=op(seg[2*i],seg[2*i+1]);
        }
    }
    ll prod(ll l,ll r){
        l+=n;r+=n;
        ll L=e(),R=e();
        while(r>l){
            if(l%2)L=op(L,seg[l]),l++;
            if(r%2)r--,R=op(seg[r],R);
            l>>=1;r>>=1;
        }
        return op(L,R);
    }
};
int main(){
    ll N,Q;cin>>N>>Q;
    set<ll>X,Y;
    REP(i,N-1)X.insert(i),Y.insert(i);
    while(Q--){
        string S;cin>>S;
        ll x;cin>>x;x--;
        if(S[0]=='C'){
            if(x){
                if(X.count(x-1))X.erase(x-1);
                else X.insert(x-1);
            }
            if(x<N-1){
                if(X.count(x))X.erase(x);
                else X.insert(x);
            }
        }
        else{
            if(x){
                if(Y.count(x-1))Y.erase(x-1);
                else Y.insert(x-1);
            }
            if(x<N-1){
                if(Y.count(x))Y.erase(x);
                else Y.insert(x);
            }
        }
        cout<<(sz(X)+1)*(sz(Y)+1)<<endl;
    }
    return 0;
}
accuracy: 1
time_ms: 1160
memory_kb: 50320
final_rank: 19

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
#define rep(i, n) for(int i=0;i<n;i++)
#define foa(e, v) for(auto&& e : v)
using ll = long long;
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (1LL << 60);
#define dout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, q;
    cin >> n >> q;
    set<int> x, y;
    for(int i = 2; i <= n; i ++) {
        x.insert(i);
        y.insert(i);
    }
    rep(i, q) {
        string s; ll v;
        cin >> s >> v;
        if(s == "ROW") {
            if(v != 1) {
                if(x.count(v)) {
                    x.erase(v);
                } else {
                    x.insert(v);
                }
            }
            if(v != n) {
                if(x.count(v + 1)) {
                    x.erase(v + 1);
                } else {
                    x.insert(v + 1);
                }
            }
        } else {
            if(v != 1) {
                if(y.count(v)) {
                    y.erase(v);
                } else {
                    y.insert(v);
                }
            }
            if(v != n) {
                if(y.count(v + 1)) {
                    y.erase(v + 1);
                } else {
                    y.insert(v + 1);
                }
            }
        }
        cout << ll(x.size() + 1) * ll(y.size() + 1) << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 1050
memory_kb: 50340
final_rank: 18

code_snippet: #include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n, q;
  cin >> n >> q;

  vector<bool> rows(n), cols(n);
  ll R = n, C = n;
  rep(i, 0, n) {
    if (n % 1) {
      rows[i] = true;
      cols[i] = true;
    }
  }

  while (q--) {
    string s;
    int x;
    cin >> s >> x;
    x--;
    int cntDiff = 0;
    if (s == "ROW") {
      if (x > 0) cntDiff -= int(rows[x] != rows[x - 1]);
      if (x < n - 1) cntDiff -= int(rows[x] != rows[x + 1]);
      rows[x] = !rows[x];
      if (x > 0) cntDiff += int(rows[x] != rows[x - 1]);
      if (x < n - 1) cntDiff += int(rows[x] != rows[x + 1]);
      R -= cntDiff;
    } else {
      if (x > 0) cntDiff -= int(cols[x] != cols[x - 1]);
      if (x < n - 1) cntDiff -= int(cols[x] != cols[x + 1]);
      cols[x] = !cols[x];
      if (x > 0) cntDiff += int(cols[x] != cols[x - 1]);
      if (x < n - 1) cntDiff += int(cols[x] != cols[x + 1]);
      C -= cntDiff;
    }
    cout << R * C << endl;
  }
}
accuracy: 1
time_ms: 410
memory_kb: 3592
final_rank: 10