이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "seats.h"
#include <bits/stdc++.h>
using namespace std;
struct T{
pair <int, int> mn,sum;
int cnt;
}st[4000001];
int n;
vector <int> r,c;
vector <vector <int>> a;
T operator +(T a, T b){
T c;
b.mn.first+=a.sum.first;
b.mn.second+=a.sum.second;
c.mn=min(a.mn,b.mn);
c.cnt=0;
if (c.mn==a.mn)
c.cnt+=a.cnt;
if (c.mn==b.mn)
c.cnt+=b.cnt;
c.sum={a.sum.first+b.sum.first,a.sum.second+b.sum.second};
return c;
}
int cell(int i, int j){
return (i<0||i>=a.size()||j<0||j>=a[0].size()?n:a[i][j]);
}
vector <int> best(int i, int j){
vector <int> v;
for (int k=0;k<2;k++)
for (int l=0;l<2;l++)
v.push_back(cell(i+k,j+l));
sort(v.begin(),v.end());
return v;
}
pair <int, int> calc(int i){
int res=0,res2=0;
for (int j=0;j<2;j++)
for (int k=0;k<2;k++){
auto v=best(r[i]-j,c[i]-k);
res+=(i==v[0])-(i==v[1]);
res2+=(i==v[2])-(i==v[3]);
}
return {res,res2};
}
void build(int node, int l, int r){
if (l==r){
st[node].mn=st[node].sum=calc(l);
st[node].cnt=1;
return;
}
int mid=(l+r)>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
st[node]=st[node<<1]+st[node<<1|1];
}
void update(int node, int l, int r, int i){
if (l>i||r<i||l>r)
return;
if (l==r){
st[node].mn=st[node].sum=calc(i);
st[node].cnt=1;
return;
}
int mid=(l+r)>>1;
update(node<<1,l,mid,i);
update(node<<1|1,mid+1,r,i);
st[node]=st[node<<1]+st[node<<1|1];
}
void give_initial_chart(int H, int W, vector <int> R, vector <int> C){
r=R;
c=C;
n=H*W;
a.resize(H);
for (int i=0;i<H;i++)
a[i].assign(W,0);
for (int i=0;i<n;i++)
a[r[i]][c[i]]=i;
build(1,0,n-1);
}
int swap_seats(int x, int y){
swap(r[x],r[y]);
swap(c[x],c[y]);
swap(a[r[x]][c[x]],a[r[y]][c[y]]);
for (int i=-1;i<2;i++)
for (int j=-1;j<2;j++){
update(1,0,n-1,cell(r[x]+i,c[x]+j));
update(1,0,n-1,cell(r[y]+i,c[y]+j));
}
return st[1].cnt;
}
컴파일 시 표준 에러 (stderr) 메시지
seats.cpp: In function 'int cell(int, int)':
seats.cpp:25:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | return (i<0||i>=a.size()||j<0||j>=a[0].size()?n:a[i][j]);
| ~^~~~~~~~~~
seats.cpp:25:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | return (i<0||i>=a.size()||j<0||j>=a[0].size()?n:a[i][j]);
| ~^~~~~~~~~~~~~
# | 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... |