이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "seats.h"
#include <cassert>
#include <tuple>
using namespace std;
struct Node {
int mn, mx;
Node(): mn(1e9), mx(0) {}
Node(int a): mn(a), mx(a) {}
Node(Node l, Node r) {
mn = min(l.mn, r.mn);
mx = max(l.mx, r.mx);
}
};
struct SegTree {
int sz;
vector<Node> tree;
int ql, qr;
SegTree() {}
SegTree(vector<int> v) {
sz = 1;
while (sz < v.size()) sz *= 2;
tree.resize(2*sz, Node());
for (int i = 0; i < v.size(); i++) tree[sz+i] = Node(v[i]);
for (int i = v.size(); i < sz; i++) tree[sz+i] = Node();
for (int i = sz-1; i >= 1; i--) tree[i] = Node(tree[2*i], tree[2*i+1]);
}
void update(int i, int x) {
i += sz;
tree[i] = Node(x);
while (i > 1) {
i /= 2;
tree[i] = Node(tree[2*i], tree[2*i+1]);
}
}
Node __query(int ni, int nl, int nr) {
if (qr <= nl || nr <= ql) return Node();
if (ql <= nl && nr <= qr) return tree[ni];
int nm = (nl+nr)/2;
return Node(__query(2*ni, nl, nm), __query(2*ni+1, nm, nr));
}
pair<int, int> query(int l, int r) {
ql = l;
qr = r;
auto res = __query(1, 0, sz);
return {res.mn, res.mx};
}
};
vector<int> R, C;
SegTree rSeg, cSeg;
void give_initial_chart(int H, int W, vector<int> R, vector<int> C) {
assert(H <= 10'000);
assert(W <= 10'000);
::R = R;
::C = C;
rSeg = SegTree(R);
cSeg = SegTree(C);
}
int swap_seats(int a, int b) {
// update
swap(R[a], R[b]);
swap(C[a], C[b]);
rSeg.update(a, R[a]);
rSeg.update(b, R[b]);
cSeg.update(a, C[a]);
cSeg.update(b, C[b]);
// query
int i = 1, ans = 1;
int mnR = R[0], mnC = C[0], mxR = R[0], mxC = C[0];
while (i < C.size()) {
tie(mnR, mxR) = rSeg.query(0, i);
tie(mnC, mxC) = cSeg.query(0, i);
if ((mxR - mnR + 1) * (mxC - mnC + 1) == i) {
ans++;
i += min(mxR - mnR + 1, mxC - mnC + 1);
} else {
i = (mxR - mnR + 1) * (mxC - mnC + 1);
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
seats.cpp: In constructor 'SegTree::SegTree(std::vector<int>)':
seats.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | while (sz < v.size()) sz *= 2;
| ~~~^~~~~~~~~~
seats.cpp:26:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (int i = 0; i < v.size(); i++) tree[sz+i] = Node(v[i]);
| ~~^~~~~~~~~~
seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:75:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | while (i < C.size()) {
| ~~^~~~~~~~~~
# | 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... |