이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "seats.h"
#include <bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;
int n, m;
vector<int> v, rev;
int translate(int x, int y){
return m*x+y;
}
pii detranslate(int id){
return {id/m,id%m};
}
int getcount(pii coord, int t){
int dx[] = {0,0,1,1}, dy[] = {0,1,0,1};
int ret = 0;
for(int i = 0; i < 4; i++){
int x = dx[i]+coord.ff, y = dy[i]+coord.ss;
if(x < n && y < m && x >=0 && y >= 0){
ret+=v[translate(x,y)] <= t;
}
}
return ret;
}
#pragma region seg
struct SegTree{
struct seg{
int mn, ct, lz;
seg operator+(seg b){
if(mn < b.mn)
return *this;
if(b.mn < mn)
return b;
b.ct+=ct;
return b;
}
};
vector<seg> tree;
int ql, qr, val, sz;
void build(int id, int l, int r){
if(l == r){
tree[id] = {0,1,0};
return;
}
int e = id*2+1, d = id*2+2, m = (l+r)>>1;
build(e,l,m);
build(d,m+1,r);
tree[id] = tree[e]+tree[d];
}
SegTree(int n = 0){
tree.resize(4*n+4);
sz = n;
build(0,0,sz-1);
}
void refresh(int id, int l, int r){
if(tree[id].lz == 0)
return;
if(l != r){
int e = id*2+1, d = id*2+2, m = (l+r)>>1;
tree[e].lz+=tree[id].lz;
tree[d].lz+=tree[id].lz;
}
tree[id].mn+=tree[id].lz;
tree[id].lz = 0;
}
void update(int id, int l, int r){
refresh(id,l,r);
if(l > qr || r < ql)
return;
if(ql <= l && r <= qr){
tree[id].lz+=val;
refresh(id,l,r);
return;
}
int e = id*2+1, d = id*2+2, m = (l+r)>>1;
update(e,l,m);
update(d,m+1,r);
}
void makeupd(int l, int r, int v){
val = v;
ql = l;
qr = r;
update(0,0,sz-1);
}
} st;
#pragma endregion
void update(int x, int y, int type = 1){
vector<int> vals;
int dx[] = {0,0,1,1}, dy[] = {0,1,0,1};
for(int i = 0; i < 4; i++){
int xi = x+dx[i], yi = y + dy[i];
if(x < n && y < m && x >=0 && y >= 0){
vals.push_back(v[translate(xi,yi)]);
}
}
sort(all(vals));
int summing[] = {1,-1,0,1};
for(int i = 0; i < vals.size();i++){
st.makeupd(vals[i],n*m-1,summing[i]*type);
}
}
void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) {
//cout << 'a' << endl;
n = H;
m = W;
v = vector<int>(n*m);
rev = vector<int>(n*m);
for(int i = 0; i < n*m; i++){
v[R[i]*m+C[i]] = i;
rev[i] = R[i]*m+C[i];
}
st = SegTree(n*m);
for(int x = -1; x < n; x++){
for(int y = -1; y < m; y++){
update(x,y);
}
}
}
int swap_seats(int a, int b) {
array<pii,2> c({detranslate(rev[a]), detranslate(rev[b])});
int dx[] = {0,0,-1,-1};
int dy[] = {0,-1,-1,0};
for(int i = 0; i < 4; i ++){
for(int j = 0; j < 2; j++){
int x = c[j].ff + dx[i], y = c[j].ss + dy[i];
update(x,y,-1);
}
}
swap(v[rev[a]],v[rev[b]]);
swap(rev[a],rev[b]);
for(int i = 0; i < 4; i ++){
for(int j = 0; j < 2; j++){
int x = c[j].ff + dx[i], y = c[j].ss + dy[i];
update(x,y,1);
}
}
return st.tree[0].ct;
}
컴파일 시 표준 에러 (stderr) 메시지
seats.cpp:41: warning: ignoring '#pragma region seg' [-Wunknown-pragmas]
41 | #pragma region seg
|
seats.cpp:118: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
118 | #pragma endregion
|
seats.cpp: In member function 'void SegTree::refresh(int, int, int)':
seats.cpp:86:41: warning: unused variable 'm' [-Wunused-variable]
86 | int e = id*2+1, d = id*2+2, m = (l+r)>>1;
| ^
seats.cpp: In function 'void update(int, int, int)':
seats.cpp:136:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
136 | for(int i = 0; i < vals.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... |