Submission #1147387

#TimeUsernameProblemLanguageResultExecution timeMemory
1147387Kaztaev_Alisher자리 배치 (IOI18_seats)C++20
17 / 100
4098 ms109816 KiB
#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], ans = 0;
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)){
			ans++;
		}
	}
}
int swap_seats(int a, int b) {
	a++;
	b++;
	for(int i = min(a,b); i <= max(a,b); i++){
		if(i == (mxx[i]-mnx[i]+1) * (mxy[i]-mny[i]+1)){
			ans--;
		}
	}
	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)){
			ans++;
		}
	}
	return ans;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...