Submission #419303

#TimeUsernameProblemLanguageResultExecution timeMemory
419303AntekbSeats (IOI18_seats)C++14
70 / 100
4082 ms102876 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(!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];
	lazy[v]=0;
}
void upd(int v){
	int l=v+v, r=l+1;
	ile[v]=0;
	if(mini[l]<=mini[r])ile[v]+=ile[l], mini[v]=mini[l];
	if(mini[r]<=mini[l])ile[v]+=ile[r], mini[v]=mini[r];
}
void add(int v, int L, int R, int l, int r, int c){
	if(l==L && r==R){
		lazy[v]+=c;
		mini[v]+=c;
		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;
void Set(int x, int y, int c){
	int tab[4]={co[x][y], co[x+1][y], co[x][y+1], co[x+1][y+1]};
	sort(tab, tab+4);
	//cerr<<x<<" "<<y<<"\n";
	//cerr<<tab[0]<<" "<<tab[1]-1<<" "<<c<<"\n";
	//cerr<<tab[2]<<" "<<tab[3]-1<<" "<<c<<"\n";
	if(tab[0]<tab[1])add(1, 0, N-1, tab[0], tab[1]-1, c);
	if(tab[2]<tab[3])add(1, 0, N-1, tab[2], tab[3]-1, c);
}
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+2, vector<int>(w+2, h*w));
	for(int i=0; i<h*w; i++){
		R[i]++;
		C[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);
	//cerr<<ile[1]<<"\n";
	for(int i=0; i<=h; i++){
		for(int j=0; j<=w; j++){
			Set(i, j, 1);
		}
	}
	//cerr<<ile[1]<<"\n";
}
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) {
//return -1;
	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...