#include "bits/stdc++.h"
#include "seats.h"
using namespace std;
struct node
{
int mx, mn;
node()
{
mx = 0;
mn = 1e9;
}
};
struct segTree
{
vector<node> t;
void init(int N)
{
t.resize(4 * N);
}
node merge(node a, node b)
{
node c;
c.mn = min(a.mn, b.mn);
c.mx = max(a.mx, b.mx);
return c;
}
void upd(int pos, int x, int l, int r, int i = 1)
{
if (l == r)
t[i].mn = t[i].mx = x;
else
{
int m = (l + r) / 2;
if (pos <= m)
upd(pos, x, l, m, i * 2);
else
upd(pos, x, m + 1, r, i * 2 + 1);
t[i] = merge(t[i * 2], t[i * 2 + 1]);
}
}
node get(int l, int r, int tl, int tr, int i = 1)
{
if (l > tr || tl > r)
return t[0];
if (l <= tl && tr <= r)
return t[i];
int m = (tl + tr) / 2;
return merge(get(l, r, tl, m, i * 2), get(l, r, m + 1, tr, i * 2 + 1));
}
};
segTree x, y;
vector<pair<int, int>> X;
int n, m;
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C)
{
x.init(H * W);
y.init(H * W);
for (int i = 0; i < H * W; i++)
x.upd(i, R[i], 0, H * W - 1), y.upd(i, C[i], 0, H * W - 1);
}
int swap_seats(int a, int b)
{
swap(X[a], X[b]);
x.upd(a, X[a].first, 0, n * m - 1);
y.upd(a, X[a].second, 0, n * m - 1);
x.upd(b, X[b].first, 0, n * m - 1);
y.upd(b, X[b].second, 0, n * m - 1);
int ans = 0;
int cur = 0;
while (cur < n * m)
{
node h = x.get(0, cur, 0, n * m - 1);
node w = y.get(0, cur, 0, n * m - 1);
if (cur == (h.mx - h.mn) * (w.mx - w.mn) - 1)
ans++;
cur++;
}
cout << ans;
}
Compilation message (stderr)
seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:84:1: warning: no return statement in function returning non-void [-Wreturn-type]
84 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |