#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/priority_queue.hpp>
#ifdef LOCAL
#include "stdafx.h"
#else
#include <bits/stdc++.h>
#define IL inline
#define LL long long
#define eb emplace_back
#define sz(v) ((int) (v).size())
#define me(f, x) memset(f, x, sizeof(f))
#define mc(f, g) memcpy(f, g, sizeof(g))
#define L(i, j, k) for (int i = (j); i <= (k); ++i)
#define R(i, j, k) for (int i = (j); i >= (k); --i)
#define FIO(FILE) freopen(FILE".in", "r", stdin), freopen(FILE".out", "w", stdout)
using namespace std;
using vi = vector<int>;
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
using ull = unsigned long long;
constexpr int N = 2e5 + 9;
int n, m, typ;
struct mat {
int x1, x2, y1, y2;
} a[N];
vi lis[N];
int p[N], q[N];
namespace F1 {
ull sum[N];
#define m ((l + r) >> 1)
#define ls(p) t[p].ch[0]
#define rs(p) t[p].ch[1]
struct info {
ull a, b;
info (ull _a = 0, ull _b = 0) : a(_a), b(_b) {}
info operator + (const info &rhs) const {
return info(a + rhs.a, b + rhs.b);
}
};
int tot;
struct nd {
info x;
bool lz;
int ch[2], L, R;
} t[N << 6];
int R, rt[N];
void up (int p) {
int L = t[p].L, R = t[p].R;
int M = (L + R) >> 1;
t[p].x = (ls(p) ? t[ls(p)].x : info(0, sum[M] - sum[L - 1]))
+ (rs(p) ? t[rs(p)].x : info(0, sum[R] - sum[M]));
}
void pp (int p) {
t[p].lz ^= 1;
swap(t[p].x.a, t[p].x.b);
}
int New (int L, int R) {
++tot;
t[tot].x = info(0, sum[R] - sum[L - 1]);
t[tot].L = L;
t[tot].R = R;
return tot;
}
int cp (int p) {
t[++tot] = t[p];
return tot;
}
void down (int &p) {
if (t[p].lz) {
int L = t[p].L, R = t[p].R;
int M = (L + R) >> 1;
p = cp(p);
ls(p) = ls(p) ? cp(ls(p)) : New(L, M);
rs(p) = rs(p) ? cp(rs(p)) : New(M + 1, R);
pp(ls(p));
pp(rs(p));
t[p].lz = false;
}
}
void flp (int ql, int qr, int l, int r, int &p) {
p = p ? cp(p) : New(l, r);
if (ql <= l && r <= qr) {
pp(p);
return;
}
down(p);
if (ql <= m) {
flp(ql, qr, l, m, ls(p));
}
if (m < qr) {
flp(ql, qr, m + 1, r, rs(p));
}
up(p);
}
bool cmp (int l, int r, int p, int q) {
if (l == r) {
return t[p].x.a > t[q].x.a;
}
down(p);
down(q);
info x = ls(p) ? t[ls(p)].x : info(0, sum[m] - sum[l - 1]);
info y = ls(q) ? t[ls(q)].x : info(0, sum[m] - sum[l - 1]);
if (x.a == y.a) {
return cmp(m + 1, r, rs(p), rs(q));
} else {
return cmp(l, m, ls(p), ls(q));
}
}
#undef m
#undef ls
#undef rs
void main () {
L (i, 1, n) {
sum[i] = sum[i - 1] + rng();
}
L (i, 1, m) {
lis[a[i].x1].eb(i);
lis[a[i].x2 + 1].eb(i);
}
L (i, 1, n) {
for (int k : lis[i]) {
flp(a[k].y1, a[k].y2, 1, n, R);
}
rt[i] = R;
}
L (i, 1, n) {
p[i] = i;
}
sort(p + 1, p + n + 1, [] (int x, int y) {
return cmp(1, n, rt[x], rt[y]);
});
L (i, 1, n) {
q[p[i]] = i;
}
}
}
namespace F2 {
LL cur;
__gnu_pbds::priority_queue<int, greater<int>> Q[N];
struct DSU {
int p[N], sz[N], L[N], R[N], c[N];
void init () {
L (i, 1, n) {
p[i] = i, sz[i] = 1;
L[i] = i, R[i] = i;
}
}
int gf (int x) {
return x == p[x] ? x : p[x] = gf(p[x]);
}
void mdy (int x, int y) {
cur += y * max(0LL, (LL)sz[x] * c[x] - 1);
}
int unite (int x, int y) {
x = gf(x), y = gf(y);
if (sz[x] > sz[y]) {
swap(x, y);
}
mdy(x, -1);
mdy(y, -1);
sz[y] += sz[x];
c[y] += c[x];
mdy(y, 1);
p[x] = y;
L[y] = min(L[y], L[x]);
R[y] = max(R[y], R[x]);
Q[y].join(Q[x]);
return y;
}
void add (int x) {
mdy(x, -1);
++c[x];
mdy(x, 1);
}
} S;
#define ls p << 1
#define rs p << 1 | 1
#define m ((l + r) >> 1)
struct inter {
int l, r;
inter (int a = N, int b = 0) : l(a), r(b) {}
inter operator + (const inter &rhs) const {
return inter(min(l, rhs.l), max(r, rhs.r));
}
};
struct info {
inter a, b;
info () = default;
info operator + (const info &rhs) const {
return {a + rhs.a, b + rhs.b};
}
} t[N << 2];
bool lz[N << 2];
void up (int p) {
t[p] = t[ls] + t[rs];
}
void pp (int p) {
lz[p] ^= 1;
swap(t[p].a, t[p].b);
}
void down (int p) {
if (lz[p]) {
pp(ls);
pp(rs);
lz[p] = false;
}
}
void bld (int l, int r, int p) {
if (l == r) {
t[p].a = inter(q[l], q[l]);
return;
}
bld(l, m, ls);
bld(m + 1, r, rs);
up(p);
}
void flp (int ql, int qr, int l, int r, int p) {
if (ql <= l && r <= qr) {
pp(p);
return;
}
down(p);
if (ql <= m) {
flp(ql, qr, l, m, ls);
}
if (m < qr) {
flp(ql, qr, m + 1, r, rs);
}
up(p);
}
#undef m
#undef ls
#undef rs
void main () {
S.init();
bld(1, n, 1);
L (i, 1, m) {
lis[a[i].y1].eb(i);
lis[a[i].y2 + 1].eb(i);
}
L (i, 1, n) {
for (int k : lis[i]) {
flp(a[k].x1, a[k].x2, 1, n, 1);
}
int l = t[1].a.l, r = t[1].b.r;
if (l < r) {
int u = S.gf(l);
while (S.R[u] < r) {
u = S.unite(u, S.R[u] + 1);
}
S.add(u);
while (!Q[u].empty() && S.R[u] >= Q[u].top()) {
S.add(u);
Q[u].pop();
}
} else {
r = S.gf(r), l = S.gf(l);
if (l == r) {
S.add(l);
} else {
Q[r].push(l);
}
}
if (i < n && !typ) {
continue;
}
cout << (LL)i * n - cur << " \n"[i == n];
}
}
}
int main () {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m >> typ;
L (i, 1, m) {
cin >> a[i].x1 >> a[i].x2 >> a[i].y1 >> a[i].y2;
}
F1::main();
L (i, 1, n + 1) {
lis[i].clear();
}
F2::main();
}
// I love WHQ!