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>
#define f0r(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
using namespace std;
vector<pair<int,int>>v;
vector<pair<pii,pii>>state;
vector<bool>nice;
int ca;
int h, w;
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
h = H;
w = W;
ca = 0;
f0r(i, H * W){
v.pb({R[i], C[i]});
}
pii x = {v[0].first, v[0].first};
pii y = {v[0].second, v[0].second};
nice.resize(h*w);
f0r(i, h*w){
x.first = min(v[i].first, x.first);
x.second = max(v[i].first, x.second);
y.first = min(v[i].second, y.first);
y.second = max(v[i].second, y.second);
state.pb({x,y});
if((x.second - x.first + 1) * (y.second - y.first + 1) == i+1){
nice[i] = 1;
ca++;
}
else{
nice[i] = 0;
}
}
//cout<<ca<<'\n';
}
int swap_seats(int a, int b) {
if(a > b)swap(a, b);
swap(v[a], v[b]);
pii x;
pii y;
if(a == 0)x = {1e9, -1};
else x = state[a-1].first;
if(a == 0)y = {1e9, -1};
else y = state[a-1].second;
int minus = 0;
for(int i = a; i<=b; i++){
minus += nice[i];
}
ca -= minus;
int plus = 0;
for(int i = a; i<=b; i++){
x.first = min(v[i].first, x.first);
x.second = max(v[i].first, x.second);
y.first = min(v[i].second, y.first);
y.second = max(v[i].second, y.second);
state[i] = {x,y};
if((x.second - x.first + 1) * (y.second - y.first + 1) == i+1){
nice[i] = 1;
plus++;
}
else{
nice[i] = 0;
}
}
ca += plus;
//cout<<minus<<' '<<plus<<'\n';
//f0r(i, h*w)cout<<nice[i]<<' ';
//cout<<'\n';
return ca;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |