이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include<iostream>
#include<queue>
using namespace std;
queue<int> closer[2][200001];
int comp[200001];
bool vis[200001];
typedef struct
{
int st[800001];
int N, x, y;
void build()
{
for(int i = 0; i < N*4; i++)
st[i]=0;
return;
}
int query(int stf, int stf2)
{
x=stf; y=stf2;
return query(0, N-1, 0);
}
int query(int ini, int fin, int ind)
{
if(ini>y || x>fin)
return 0;
if(ini>=x && y>=fin)
return st[ind];
int mit = (ini+fin)/2, ls=(ind*2)+1, rs=(ind*2)+2;
return query(ini, mit, ls)+query(mit+1, fin, rs);
}
void insert(int stf)
{
x=stf;
insert(0, N-1, 0);
return;
}
void insert(int ini, int fin, int ind)
{
if(ini==fin)
{
st[ind]++;
return;
}
int mit = (ini+fin)/2, ls=(2*ind)+1, rs=(2*ind)+2;
if(x<=mit)
insert(ini, mit, ls);
else insert(mit+1, fin, rs);
st[ind] = st[ls]+st[rs];
return;
}
}Wasd;
Wasd mqun;
long long d=0;
long long count_swaps(vector<int> s) {
int n = s.size();
for(int i = 0; i < n; i++)
comp[i]=s[i];
for(int i = 0; i < n; i++)
if(comp[i]<0)
closer[1][comp[i]*-1].push(i);
else closer[0][comp[i]].push(i);
mqun.N=n;
mqun.build();
for(int i = 0; i < n; i++)
if(!vis[i])
{
bool z = false;
if(comp[i]>0)
z=true;
else comp[i]*=-1;
int j = closer[z][comp[i]].front();
closer[z][comp[i]].pop();
closer[!z][comp[i]].pop();
d+=((j-i+z)-1)-mqun.query(i, j);
vis[i]=true;
vis[j]=true;
mqun.insert(j);
}
return d;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:67:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(int i = 0; i < n; i++)
^~~
shoes.cpp:82:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
return d;
^~~~~~
# | 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... |