This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "seats.h"
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order(), order_of_key()
typedef long long ll;
typedef long double dd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<dd, dd> pdd;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<dd> vdd;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<vii> vvii;
typedef vector<vll> vvll;
typedef vector<vdd> vvdd;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
typedef vector<vpdd> vvpdd;
typedef vector<bool> vb;
const int inf = 1 << 30;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define ffor(i, a, b) for(ll i = a; i < b; i++)
#define forin(x, a) for (auto &x: a)
#define all(x) x.begin(), x.end()
#ifdef TEST
#define dbg(x) cout << #x << ": " << x << '\n';
#define dbgc(x) cout << #x << ":"; forin(a, x) { cout << " " << a; } cout << endl;
#define tassert(x) assert(x);
#else
#define dbg(x)
#define dbgc(x)
#define tassert(x)
#endif
std::vector<int> r, c, mir, mar, mic, mac;
bool tc4 = false;
int curr = 1;
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
r = move(R);
c = move(C);
if (H * W > 10000) {
tc4 = true;
mir[0] = r[0]; mic[0] = c[0]; mar[0] = r[0]; mac[0] = c[0];
ffor(i, 1, r.size()) {
mir[i] = min(mir[i - 1], r[i]);
mar[i] = max(mar[i - 1], r[i]);
mic[i] = min(mic[i - 1], c[i]);
mac[i] = max(mac[i - 1], c[i]);
if ((mar[i] - mir[i] + 1) * (mac[i] - mic[i] + 1) == i + 1) {
curr++;
}
}
}
}
int swap_seats(int a, int b) {
if (tc4) {
if (a > b) swap(a, b);
ffor(i, a, b + 1) {
if ((mar[i] - mir[i] + 1) * (mac[i] - mic[i] + 1) == i + 1) {
curr--;
}
}
swap(r[a], r[b]);
swap(c[a], c[b]);
if (a == 0) {
curr++;
a++;
}
ffor(i, a, b + 1) {
mir[i] = min(mir[i - 1], r[i]);
mar[i] = max(mar[i - 1], r[i]);
mic[i] = min(mic[i - 1], c[i]);
mac[i] = max(mac[i - 1], c[i]);
if ((mar[i] - mir[i] + 1) * (mac[i] - mic[i] + 1) == i + 1) {
curr++;
}
}
return curr;
}
swap(r[a], r[b]);
swap(c[a], c[b]);
int minr = r[0], minc = c[0], maxr = r[0], maxc = c[0];
int res = 1;
ffor(i, 1, r.size()) {
minr = min(minr, r[i]);
maxr = max(maxr, r[i]);
minc = min(minc, c[i]);
maxc = max(maxc, c[i]);
if ((maxr - minr + 1) * (maxc - minc + 1) == i + 1) {
res++;
}
}
return res;
}
Compilation message (stderr)
seats.cpp: In function 'void give_initial_chart(int, int, std::vector<int>, std::vector<int>)':
seats.cpp:34:39: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | #define ffor(i, a, b) for(ll i = a; i < b; i++)
......
58 | ffor(i, 1, r.size()) {
| ~~~~~~~~~~~~~~
seats.cpp:58:5: note: in expansion of macro 'ffor'
58 | ffor(i, 1, r.size()) {
| ^~~~
seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:34:39: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | #define ffor(i, a, b) for(ll i = a; i < b; i++)
......
101 | ffor(i, 1, r.size()) {
| ~~~~~~~~~~~~~~
seats.cpp:101:3: note: in expansion of macro 'ffor'
101 | ffor(i, 1, r.size()) {
| ^~~~
# | 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... |