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;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef double ld;
typedef complex<ld> point;
void debug_out(){cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T){
cerr << H << ' ';
debug_out(T...);
}
#define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define MP(x, y) make_pair(x, y)
const int maxn = 1e6 + 10;
const int inf = 1e9;
int n, r[maxn], c[maxn], val[maxn][4];
bool mark[maxn];
int ans = 0;
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
n = H*W;
for (int i = 1; i <= n; i++){
r[i] = R[i-1];
c[i] = C[i-1];
}
val[0][0] = val[0][2] = inf;
val[0][1] = val[0][3] = 0;
for (int i = 1; i <= n; i++){
val[i][0] = min(val[i-1][0], r[i]);
val[i][1] = max(val[i-1][1], r[i]);
val[i][2] = min(val[i-1][2], c[i]);
val[i][3] = max(val[i-1][3], c[i]);
//debug(i, val[i][0], val[i][1], val[i][2], val[i][3]);
if (1ll * (val[i][1] - val[i][0] + 1) * (val[i][3] - val[i][2] + 1) == i){
ans++;
mark[i] = true;
}
}
}
int swap_seats(int a, int b) {
a++, b++;
if (a > b) swap(a, b);
swap(r[a], r[b]);
swap(c[a], c[b]);
for (int i = a; i <= b; i++){
if (mark[i]) ans--;
mark[i] = false;
val[i][0] = min(val[i-1][0], r[i]);
val[i][1] = max(val[i-1][1], r[i]);
val[i][2] = min(val[i-1][2], c[i]);
val[i][3] = max(val[i-1][3], c[i]);
if (1ll * (val[i][1] - val[i][0] + 1) * (val[i][3] - val[i][2] + 1) == i){
ans++;
mark[i] = true;
}
}
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... |