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 rep(i , j , k) for(int i = j; i < (int)k; i++)
typedef vector<int> vi;
int MIN(int a, int b) {
return a < b ? a : b;
}
int MAX(int a, int b) {
return b < a ? a : b;
}
const int N = 1e6 + 10;
int n;
template<int(*f)(int , int)>
struct seg {
int arr[N << 1];
seg() {
memset(arr, f(0 , 63) ^ 63 , sizeof(arr));
}
inline void Upd(int p , int val) {
for (arr[p += n] = val; p > 1; p >>= 1)
arr[p >> 1] = f(arr[p] , arr[p ^ 1]);
}
inline int Get(int l , int r) {
int res = f(0 , (int)1e9) ^ (int)1e9;
for (l += n , r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1) res = f(res , arr[l++]);
if (r & 1) res = f(res , arr[--r]);
}
return res;
}
};
seg<MIN> mR , mC;
seg<MAX> xR , xC;
vi R , C;
/*
int solve(int me) {
// cout << " ::::" << me << endl;
if (me == n + 1) return 0;
int sz = (xR.Get(0 , me) - mR.Get(0 , me) + 1) *
(xC.Get(0 , me) - mC.Get(0 , me) + 1);
// cout << " : " << sz << endl;
if (sz == me) return solve(me + 1) + 1;
return solve(sz);
}
*/
int solve(int ptr = 0, int l1 = R[0] , int l2 = R[0] , int r1 = C[0] , int r2 = C[0]) {
if (ptr == n) return 0;
int sz = (l2 - l1 + 1) * (r2 - r1 + 1);
// cout << ptr << ' '<< l1 << ' '<< l2 << ' ' << r1 << ' ' << r2 << endl;
// int junk;
// cin >> junk;
int res = 0;
int l_ = R[ptr];
int r_ = C[ptr];
while (l_ >= l1 && l_ <= l2 && r_ >= r1 && r_ <= r2) {
ptr++;
//cout << ptr - 1 << " :: " << endl;
if (ptr == sz) return res++;
l_ = R[ptr];
r_ = C[ptr];
}
if (r_ > r2) r2++;
if (r_ < r1) r1--;
if (l_ > l2) l2++;
if (l_ < l1) l1--;
return res + solve(ptr, l1 , l2 , r1 , r2);
}
void give_initial_chart(int H, int W, vi R_, vi C_) {
R = R_, C = C_;
n = H * W;
/*
rep(i , 0 , n) {
mR.Upd(i , R[i]);
mC.Upd(i , C[i]);
xR.Upd(i , R[i]);
xC.Upd(i , C[i]);
}
*/
//cout << solve(1) << endl;
//cout << "GOOD" << endl;
return;
}
int swap_seats(int a, int b) {
swap(R[a] , R[b]);
swap(C[a] , C[b]);
/*
mR.Upd(a , R[a]);
mC.Upd(a , C[a]);
xR.Upd(a , R[a]);
xC.Upd(a , C[a]);
mR.Upd(b , R[b]);
mC.Upd(b , C[b]);
xR.Upd(b , R[b]);
xC.Upd(b , C[b]);
//cout << "DONE" << endl;
*/
// cout << "DONE" << endl;
return solve();
}
# | 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... |