#include "seats.h"
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
const ll N = 1e6+5 , inf = 2e9 + 7 , block = 1000;
const ll INF = 1e18 , mod = 1e9+7;
vector<int> a[N];
int n , m , mnx[N] , mny[N] , mxx[N] , mxy[N] , cnt[N] , cnt2[N];
pair<int,int> pos[N];
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
for(int i = 0; i <= H+1; i++){
a[i].resize(W+9);
}
n = H , m = W;
for(int i = 0; i < n*m; i++){
R[i]++;
C[i]++;
pos[i+1] = {R[i],C[i]};
}
mnx[0] = n , mny[0] = m , mxx[0] = 1 , mxy[0] = 1;
for(int i = 1; i <= n*m; i++){
mnx[i] = min(mnx[i-1] , pos[i].F);
mny[i] = min(mny[i-1] , pos[i].S);
mxx[i] = max(mxx[i-1] , pos[i].F);
mxy[i] = max(mxy[i-1] , pos[i].S);
if(i == (mxx[i]-mnx[i]+1) * (mxy[i]-mny[i]+1)){
cnt[i]++;
cnt2[i/block]++;
}
}
}
int get(int l , int r){
l--; r--;
if(l > r) return 0;
int ans = 0;
if(l / block == r / block){
for(int i = l; i <= r; i++){
ans += cnt[i];
}
} else {
while(l <= r && l%block != 0){
ans += cnt[l];
l++;
}
while(l <= r && (r+1) % block != 0){
ans += cnt[r];
r--;
}
for(int i = l/block; i <= r/block; i++){
ans += cnt2[i];
}
}
return ans;
}
int swap_seats(int a, int b) {
a++;
b++;
for(int i = min(a,b); i <= max(a,b); i++){
mnx[i] = min(mnx[i-1] , pos[i].F);
mny[i] = min(mny[i-1] , pos[i].S);
mxx[i] = max(mxx[i-1] , pos[i].F);
mxy[i] = max(mxy[i-1] , pos[i].S);
if(i == (mxx[i]-mnx[i]+1) * (mxy[i]-mny[i]+1)){
cnt[i-1]--;
cnt2[(i-1)/block]--;
}
}
swap(pos[a],pos[b]);
for(int i = min(a,b); i <= max(a,b); i++){
mnx[i] = min(mnx[i-1] , pos[i].F);
mny[i] = min(mny[i-1] , pos[i].S);
mxx[i] = max(mxx[i-1] , pos[i].F);
mxy[i] = max(mxy[i-1] , pos[i].S);
if(i == (mxx[i]-mnx[i]+1) * (mxy[i]-mny[i]+1)){
cnt[i-1]++;
cnt2[(i-1)/block]++;
}
}
return get(1,min(a,b)-1) + get(min(a,b),max(a,b)) + get(max(a,b) , n*m);
}
# | 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... |