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;
const int N = 15e2;
struct nod{
int mn,mx;
}seg[2][4*N*N];
nod operator+(nod a, nod b){
return {min(a.mn,b.mn),max(a.mx,b.mx)};
}
int sz;
void upd(int pos, int x, int y, int l = 0, int r = sz - 1, int node = 1){
if(l == r){
seg[0][node] = {x, x};
seg[1][node] = {y, y};
}else{
int mij = (l + r)/2;
if(pos <= mij){
upd(pos, x, y, l, mij, node*2);
}else{
upd(pos, x, y, mij + 1, r, node*2 + 1);
}
seg[0][node] = seg[0][node*2] + seg[0][node*2 + 1];
seg[1][node] = seg[1][node*2] + seg[1][node*2 + 1];
}
}
pair<nod,nod> operator+(pair<nod,nod> a, pair<nod,nod> b){
return {a.first + b.first, a.second + b.second};
}
pair<nod,nod> query(int ql, int qr, int l = 0, int r = sz - 1, int node = 1){
if(ql <= l && r <= qr){
return {seg[0][node], seg[1][node]};
}else{
int mij = (l + r)/2;
if(qr <= mij){
return query(ql, qr, l, mij, node*2);
}else if(mij <= ql + 1){
return query(ql, qr, mij + 1, r, node*2 + 1);
}else{
return query(ql, qr, l, mij, node*2) + query(ql, qr, mij + 1, r, node*2 + 1);
}
}
}
std::vector<std::vector<int>> v;
vector <int> x,y;
int n,m;
void give_initial_chart(int n2, int m2, std::vector<int> a, std::vector<int> b) {
n = n2;m = m2;
v.assign(n, vector<int>(m,0));
x = a;
y = b;
sz = n*m;
for(int i = 0;i < n*m;i++){
v[x[i]][y[i]] = i;
upd(i, x[i], y[i]);
}
}
int swap_seats(int a, int b){
swap(x[a],x[b]);
swap(y[a],y[b]);
upd(a, x[a], y[a]);
upd(b, x[b], y[b]);
int ans = 0;
int i = 0;
while(i < n*m){
pair<nod,nod> p = query(0, i);
//cout<<p.second.mx<<' '<<p.second.mn<<' '<<p.first.mx<<' '<<p.first.mn<<'\n';
int matrixsz = (p.second.mx - p.second.mn + 1)*(p.first.mx - p.first.mn + 1);
if(matrixsz == i + 1){
ans++;
}
i = max(i + 1, matrixsz - 1);
}
return ans;
}
# | 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... |