이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "seats.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> r, c;
int h, w;
vector<vector<int> > seg[2];
void update(int pos, int ini, int fim, int id, int val, int x, int k);
int query(int pos, int ini, int fim, int p, int q, int x, int k);
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
r = R, c = C;
h = H, w = W;
seg[0] = vector<vector<int> > (h, vector<int> (4 * w));
seg[1] = vector<vector<int> > (w, vector<int> (4 * h));
for(int i = 0; i < r.size(); i++){
update(1, 0, w, c[i], i, r[i], 0);
update(1, 0, h, r[i], i, c[i], 1);
}
}
int swap_seats(int a, int b) {
swap(r[a], r[b]);
swap(c[a], c[b]);
update(1, 0, w, c[a], a, r[a], 0);
update(1, 0, h, r[a], a, c[a], 1);
update(1, 0, w, c[b], b, r[b], 0);
update(1, 0, h, r[b], b, c[b], 1);
int cur = 0;
int maxi = 0;
int maxr = r[0], minr = r[0], maxc = c[0], minc = c[0];
int ret = 0;
while(cur < h * w){
// printf("%d\n", cur);
while(maxr < r[cur]){
maxr++;
maxi = max(maxi, query(1, 0, w, minc, maxc, maxr, 0));
}
while(minr > r[cur]){
minr--;
maxi = max(maxi, query(1, 0, w, minc, maxc, minr, 0));
}
while(maxc < c[cur]){
maxc++;
maxi = max(maxi, query(1, 0, h, minr, maxr, maxc, 1));
}
while(minc > c[cur]){
minc--;
maxi = max(maxi, query(1, 0, h, minr, maxr, minc, 1));
}
if(maxi == (maxr - minr + 1) * (maxc - minc + 1) - 1) ret++;
cur = maxi + 1;
}
return ret;
}
void update(int pos, int ini, int fim, int id, int val, int x, int k){
if(ini > id || fim < id) return;
if(ini == fim){
seg[k][x][pos] = val;
return;
}
int mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
update(e, ini, mid, id, val, x, k);
update(d, mid + 1, fim, id, val, x, k);
seg[k][x][pos] = max(seg[k][x][e], seg[k][x][d]);
}
int query(int pos, int ini, int fim, int p, int q, int x, int k){
if(ini > q || fim < p) return 0;
if(ini >= p && fim <= q) return seg[k][x][pos];
int mid = (ini + fim) >> 1, e = pos << 1, d = e | 1;
return max(query(e, ini, mid, p, q, x, k), query(d, mid + 1, fim, p, q, x, k));
}
컴파일 시 표준 에러 (stderr) 메시지
seats.cpp: In function 'void give_initial_chart(int, int, std::vector<int>, std::vector<int>)':
seats.cpp:19:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int i = 0; i < r.size(); i++){
| ~~^~~~~~~~~~
# | 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... |