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;
#define ll long long
std::vector<int> r , c , mxr, mxc, mnr, mnc;
int ans = 0 , h , w;
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
r = R; c = C; h = H; w = W;
mxr.resize( h * w + 1 );
mxc.resize( h * w + 1 );
mnr.resize( h * w + 1 );
mnc.resize( h * w + 1 );
mxr[0] = mxc[0] = INT_MIN;
mnr[0] = mnc[0] = INT_MAX;
for (int i = 1; i <= h * w; i++) {
mxr[i] = max(mxr[i - 1] , r[i - 1]);
mxc[i] = max(mxc[i - 1] , c[i - 1]);
mnr[i] = min(mnr[i - 1] , r[i - 1]);
mnc[i] = min(mnc[i - 1] , c[i - 1]);
int val = (mxr[i] - mnr[i] + 1) * (mxc[i] - mnc[i] + 1);
if ( val == i) ans++;
else
i = val - 1;
}
}
int swap_seats(int a, int b) {
a++; b++;
if (a > b) swap(a , b);
for (int i = a; i <= b; i++) {
int val = (mxr[i] - mnr[i] + 1) * (mxc[i] - mnc[i] + 1);
if ( val == i) ans--;
else
i = val - 1;
}
swap (r[a - 1] , r[b - 1]);
swap (c[a - 1] , c[b - 1]);
for (int i = a; i <= b; i++) {
mxr[i] = max(mxr[i - 1] , r[i - 1]);
mxc[i] = max(mxc[i - 1] , c[i - 1]);
mnr[i] = min(mnr[i - 1] , r[i - 1]);
mnc[i] = min(mnc[i - 1] , c[i - 1]);
int val = (mxr[i] - mnr[i] + 1) * (mxc[i] - mnc[i] + 1);
if ( val == i) ans++;
else
i = val - 1;
}
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... |