Submission #419306

#TimeUsernameProblemLanguageResultExecution timeMemory
419306AntekbSeats (IOI18_seats)C++14
100 / 100
2864 ms126684 KiB
#include "seats.h"
#include<bits/stdc++.h>
#define st first
#define nd second
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;
	}
	//cerr<<ile[1]<<"\n";
	vector<pair<int, int> > V;
	for(int i=0; i<=h; i++){
		for(int j=0; j<=w; j++){
			int tab[4]={co[i][j], co[i+1][j], co[i][j+1], co[i+1][j+1]};
			sort(tab, tab+4);
			if(tab[0]<tab[1])V.push_back({tab[0], 1}), V.push_back({tab[1], -1});
			if(tab[2]<tab[3])V.push_back({tab[2], 1}), V.push_back({tab[3], -1});
		}
	}
	sort(V.begin(), V.end());
	int wsk=0;
	int cnt=0;
	for(int i=0; i<h*w; i++){
		while(wsk<V.size() && V[wsk].st==i){
			cnt+=V[wsk++].nd;
		}
		mini[N+i]=cnt;
	}
	for(int i=N-1; i>0; i--)upd(i);
	//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];
}

Compilation message (stderr)

seats.cpp: In function 'void give_initial_chart(int, int, std::vector<int>, std::vector<int>)':
seats.cpp:78:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |   while(wsk<V.size() && V[wsk].st==i){
      |         ~~~^~~~~~~~~
#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...