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<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<ld, ld>;
#define mp make_pair
#define ff first
#define ss second
#define ar array
template<class T> using V = vector<T>;
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<ld>;
using vs = V<str>;
using vpi = V<pi>;
using vpl = V<pl>;
using vpd = V<pd>;
#define sz(x) (int)((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
#define lb lower_bound
#define ub upper_bound
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for(int i = (b) - 1; i >= (a); --i)
#define R0F(i, a) ROF(i, 0, a)
#define rep(a) F0R(_, a)
#define trav(a, x) for(auto& a : x)
template<class T> bool ckmin(T& a, const T& b) { return (b < a ? a = b, 1 : 0); }
template<class T> bool ckmax(T& a, const T& b) { return (b > a ? a = b, 1 : 0); }
int N, M;
vi R, C;
int Lf[1000000], Rf[1000000], Ls[1000000], Rs[1000000], ans;
int old_swap_seats(int A, int B) {
swap(R[A], R[B]);
swap(C[A], C[B]);
int ans = 1;
int Lf = R[0], Rf = R[0], Ls = C[0], Rs = C[0];
FOR(i, 1, N * M) {
ckmin(Lf, R[i]);
ckmax(Rf, R[i]);
ckmin(Ls, C[i]);
ckmax(Rs, C[i]);
if(i + 1 == (Rf - Lf + 1) * (Rs - Ls + 1)) ++ans;
}
return ans;
}
void give_initial_chart(int _N, int _M, vi _R, vi _C) {
swap(N, _N);
swap(M, _M);
swap(R, _R);
swap(C, _C);
ans = old_swap_seats(0, 0);
}
int swap_seats(int A, int B) {
swap(R[A], R[B]);
swap(C[A], C[B]);
if(!A) {
Lf[0] = R[0]; Rf[0] = R[0]; Ls[0] = C[0]; Rs[0] = C[0];
++A;
}
FOR(i, A, B + 1) {
if(i + 1 == (Rf[i] - Lf[i] + 1) * (Rs[i] - Ls[i] + 1)) --ans;
Lf[i] = min(Lf[i - 1], R[i]);
Rf[i] = max(Rf[i - 1], R[i]);
Ls[i] = min(Ls[i - 1], C[i]);
Rs[i] = max(Rs[i - 1], C[i]);
if(i + 1 == (Rf[i] - Lf[i] + 1) * (Rs[i] - Ls[i] + 1)) ++ans;
}
return ans;
}
# | 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... |