이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
int n,r,pos;
long long ans;
vector<int>locl[500001],locr[500001],indl[500001],indr[500001];
int tree[500001];
void upd(int node,int tl,int tr){
if(tl==tr){
tree[node] = 1;
return;
}
int mid = (tl+tr)/2;
if(pos<mid)
upd(node*2,tl,mid);
else
upd(node*2+1,mid+1,tr);
tree[node] = tree[node*2] + tree[node*2+1];
}
int get(int node,int tl,int tr){
if(r<tl)return 0;
if(tr<=r)return tree[node];
int mid = (tr+tl)/2;
int x = get(node*2,tl,mid);
int y = get(node*2+1,mid+1,tr);
return x+y;
}
long long count_swaps(std::vector<int> s) {
n = s.size()/2;
for(int i=0;i<s.size();i++){
if(s[i]<0){
locl[-s[i]] = i;
} else {
locr[s[i]] = i;
}
}
for(int i=0;i<s.size();i++){
if(s[i]<0){
int loc = locr[ s[i] ][ indr[ s[i] ] ];
r = loc;
ans += loc - i - get(1,0,s.size()-1);
indr[ s[i] ] ++;
pos = loc;
upd(1,0,s.size()-1);
} else {
int loc = locl[ s[i] ][ indl[ s[i] ] ];
r = loc;
ans += loc - i + 1 - get(1,0,s.size()-1);
indl[ s[i] ] ++;
pos = loc;
upd(1,0,s.size()-1);
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp:7:1: error: 'vector' does not name a type
vector<int>locl[500001],locr[500001],indl[500001],indr[500001];
^~~~~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:46:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<s.size();i++){
~^~~~~~~~~
shoes.cpp:48:4: error: 'locl' was not declared in this scope
locl[-s[i]] = i;
^~~~
shoes.cpp:48:4: note: suggested alternative: 'bool'
locl[-s[i]] = i;
^~~~
bool
shoes.cpp:50:4: error: 'locr' was not declared in this scope
locr[s[i]] = i;
^~~~
shoes.cpp:50:4: note: suggested alternative: 'long'
locr[s[i]] = i;
^~~~
long
shoes.cpp:54:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<s.size();i++){
~^~~~~~~~~
shoes.cpp:56:14: error: 'locr' was not declared in this scope
int loc = locr[ s[i] ][ indr[ s[i] ] ];
^~~~
shoes.cpp:56:14: note: suggested alternative: 'loc'
int loc = locr[ s[i] ][ indr[ s[i] ] ];
^~~~
loc
shoes.cpp:56:28: error: 'indr' was not declared in this scope
int loc = locr[ s[i] ][ indr[ s[i] ] ];
^~~~
shoes.cpp:56:28: note: suggested alternative: 'int'
int loc = locr[ s[i] ][ indr[ s[i] ] ];
^~~~
int
shoes.cpp:64:14: error: 'locl' was not declared in this scope
int loc = locl[ s[i] ][ indl[ s[i] ] ];
^~~~
shoes.cpp:64:14: note: suggested alternative: 'loc'
int loc = locl[ s[i] ][ indl[ s[i] ] ];
^~~~
loc
shoes.cpp:64:28: error: 'indl' was not declared in this scope
int loc = locl[ s[i] ][ indl[ s[i] ] ];
^~~~
shoes.cpp:64:28: note: suggested alternative: 'int'
int loc = locl[ s[i] ][ indl[ s[i] ] ];
^~~~
int