Submission #419295

#TimeUsernameProblemLanguageResultExecution timeMemory
419295AntekbSeats (IOI18_seats)C++14
0 / 100
379 ms83640 KiB
#include "seats.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> R, C;
int h, w;
const int N=(1<<20);
int mini[2*N], ile[2*N], lazy[2*N];
void prop(int v){
	if(v>=N || !lazy[v])return;
	int l=v+v, r=l+1;
	lazy[l]+=lazy[v];
	lazy[r]+=lazy[v];
	mini[l]+=lazy[v];
	mini[r]+=lazy[v];
}
void upd(int v){
	if(v>=N)return;
	assert(!lazy[v]);
	int l=v+v, r=l+1;
	mini[v]=min(mini[l], mini[r]);
	ile[v]=0;
	if(mini[l]<=mini[r])ile[v]=ile[l];
	if(mini[r]<=mini[l])ile[v]+=ile[r];
}
void add(int v, int L, int R, int l, int r, int c){
	if(l==L && r==R){
		lazy[v]++;
		mini[v]++;
		return;
	}
	int M=(L+R)>>1;
	prop(v);
	if(M>=l)add(2*v, L, M, l, min(M, r), c);
	if(r>M)add(2*v+1, M+1, R, max(M+1, l), r, c);
	upd(v);
	return;
}
vector<vector<int> > co;
int val(int x, int y){
	if(x>=0 && x<h && y>=0 && y<w)return co[x][y];
	return w*h;
}
void Set(int x, int y, int c){
	int tab[4]={val(x, y), val(x+1, y), val(x, y+1), val(x+2, y+2)};
	sort(tab, tab+4);
	add(1, 0, N-1, tab[0], tab[3]-1, c);
	add(1, 0, N-1, tab[1], tab[2]-1, -1);
}
void give_initial_chart(int H, int W, std::vector<int> R2, std::vector<int> C2) {
	R=R2;
	C=C2;
	h=H;
	w=W;
	co.resize(h, vector<int>(w));
	for(int i=0; i<h*w; i++){
		co[R[i]][C[i]]=i;
		ile[N+i]=1;
	}
	for(int i=h*w; i<N; i++){
		ile[N+i]=1;
		mini[N+i]=2*N;
	}
	for(int i=N-1; i>0; i--)upd(i);
	for(int i=-1; i<h; i++){
		for(int j=-1; j<w; j++){
			Set(i, j, 1);
		}
	}
}
void Setall(int x, int y, int c){
	Set(x, y, c);
	Set(x-1, y, c);
	Set(x, y-1, c);
	Set(x-1, y-1, c);
}
int swap_seats(int a, int b) {
	Setall(R[a], C[a], -1);
	Setall(R[b], C[b], -1);
	swap(R[a], R[b]);
	swap(C[a], C[b]);
	swap(co[R[a]][C[a]], co[R[b]][C[b]]);
	Setall(R[a], C[a], 1);
	Setall(R[b], C[b], 1);
	return ile[1];
}
#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...