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>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;
const int N = (int)(1e6 + 5);
const int LOG = (int)(20);
const int inf = (int)(1e9);
int n, h, w, r[N], c[N], maxr[N], minr[N], maxc[N], minc[N], ans;
int area(int x, int y, int xx, int yy) {
return (xx - x + 1) * (yy - y + 1);
}
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
n = H * W;
w = W;
h = H;
for(int i = 1; i <= n; i++)
r[i] = R[i - 1];
for(int i = 1; i <= n; i++)
c[i] = C[i - 1];
minr[0] = inf;
minc[0] = inf;
for(int i = 1; i <= n; i++) {
maxr[i] = max(maxr[i - 1], r[i]);
minr[i] = min(minr[i - 1], r[i]);
}
for(int i = 1; i <= n; i++) {
maxc[i] = max(maxc[i - 1], c[i]);
minc[i] = min(minc[i - 1], c[i]);
}
for(int i = 1; i <= n; i++)
if(area(minr[i], minc[i], maxr[i], maxc[i]) == i)
ans++;
}
int swap_seats(int a, int b) {
a++,b++;
if(a > b)
swap(a, b);
for(int i = a; i < b; i++)
if(area(minr[i], minc[i], maxr[i], maxc[i]) == i)
ans--;
swap(r[a], r[b]);
swap(c[a], c[b]);
for(int i = a; i < b; i++) {
maxr[i] = max(maxr[i - 1], r[i]);
minr[i] = min(minr[i - 1], r[i]);
}
for(int i = a; i < b; i++) {
maxc[i] = max(maxc[i - 1], c[i]);
minc[i] = min(minc[i - 1], c[i]);
}
for(int i = a; i < b; i++)
if(area(minr[i], minc[i], maxr[i], maxc[i]) == i)
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... |