# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
366612 | denkendoemeer | Seats (IOI18_seats) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "seats.h"
#include<bits/stdc++.h>
using namespace std;
int h,w,ans;
vector<pair<int,int>>v;
vector<int>xmin,xmax,ymin,ymax;
void give_initial_chart(int h2,int w2,vector<int>r,vector<int>c)
{
h=h2;
w=w2;
xmin=ymin=xmax=ymax=vector<int>(h*w);
int i;
for(i=0;i<h*w;i++)
v.push_back({r[i],c[i]});
xmin[0]=xmax[0]=v[0].first;
ymin[0]=ymax[0]=v[0].second;
for(i=1;i<h*w;i++){
xmin[i]=min(xmin[i-1],v[i].first);
xmax[i]=max(xmax[i-1],v[i].first);
ymin[i]=min(ymin[i-1],v[i].second);
ymax[i]=max(ymax[i-1],v[i].second);
}
for(i=0;i<h*w;i++){
if (i+1==(xmax[i]-xmin[i]+1)*(ymax[i]-ymin[i]+1))
ans++;
}
}
int swap_seats(int a,int b)
{
if (a>b)
swap(a,b);
swap(v[a],v[b]);
if (a==0){
xmin[0]=xmax[0]=v[0].first;
ymin[0]=ymax[0]=v[0].second;
}
for(i=max(a,1);i<=b;i++){
if (i+1==(xmax[i]-xmin[i]+1)*(ymax[i]-ymin[i]+1))
ans--;
xmin[i]=min(xmin[i-1],v[i].first);
xmax[i]=max(xmax[i-1],v[i].first);
ymin[i]=min(ymin[i-1],v[i].second);
ymax[i]=max(ymax[i-1],v[i].second);
if (i+1==(xmax[i]-xmin[i]+1)*(ymax[i]-ymin[i]+1))
ans++;
}
return ans;
}