이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "seats.h"
#include <bits/stdc++.h>
using namespace std;
//macros
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define INF 1e9
#define pb push_back
#define fi first
#define se second
#define sz size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int h, w, n;
vi r, c;
vii pos;
int tot=0;
vi minR, maxR, minC, maxC;
vi added;
void give_initial_chart(int H, int W, vi R, vi C) {
h=H, w=W, r=R, c=C;
n = h*w;
pos.resize(n);
RE(i,n) pos[i] = {r[i], c[i]};
minR .assign(n, INF);
maxR .assign(n, -INF);
minC .assign(n, INF);
maxC .assign(n, -INF);
added.assign(n, 0);
RE(i,n) {
minR[i] = pos[i].fi;
maxR[i] = pos[i].fi;
minC[i] = pos[i].se;
maxC[i] = pos[i].se;
if(i != 0) {
minR[i] = min(minR[i], minR[i-1]);
maxR[i] = max(maxR[i], maxR[i-1]);
minC[i] = min(minC[i], minC[i-1]);
maxC[i] = max(maxC[i], maxC[i-1]);
}
if((maxR[i]-minR[i]+1)*(maxC[i]-minC[i]+1) == i+1) {
tot++;
added[i] = 1;
}
}
}
int swap_seats(int a, int b) {
swap(pos[a], pos[b]);
REP(i,a,b+1) {
tot -= added[i];
added[i] = 0;
minR[i] = pos[i].fi;
maxR[i] = pos[i].fi;
minC[i] = pos[i].se;
maxC[i] = pos[i].se;
if(i != 0) {
minR[i] = min(minR[i], minR[i-1]);
maxR[i] = max(maxR[i], maxR[i-1]);
minC[i] = min(minC[i], minC[i-1]);
maxC[i] = max(maxC[i], maxC[i-1]);
}
if((maxR[i]-minR[i]+1)*(maxC[i]-minC[i]+1) == i+1) {
tot++;
added[i] = 1;
}
}
return tot;
}
# | 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... |