이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#define int long long
#define P(x) do {if(debug) cout << x << endl;} while(false)
#define H(x) P(#x << ": " << x)
#define FR(i, a, b) for(int i = (a); i < (b); ++i)
#define F(i, n) FR(i, 0, n)
#define DR(i, a, b) for(int i = (b); i --> (a);)
#define D(i, n) DR(i, 0, n)
#define S(s) (int)(s).size()
#define ALL(x) (x).begin(), (x).end()
#define MI(x, a) (x) = min(x, a)
#define MA(x, a) (x) = max(x, a)
#define V vector
#define pb push_back
#define mp make_pair
using namespace std;
const bool debug = 0;
//const int inf = 1e18;
struct ftree{
vector<int> tree;
int n;
ftree(int _n){
tree.resize(_n+1, 0);
n = _n;
}
int query(int i){
int res = 0;
for(int j = i; j>0; j-=(j&-j)){
res+=tree[j];
}
//res+=ftree[0];µ
return res;
}
void update(int i, int change){
//int change = v-(query(i+1)+query(i));
for(int j = i+1; j<tree.size(); j+=(j&-j)){
tree[j]+=change;
}
}
};
long long count_swaps(vector<int> S){
int n = S.size()/2;
//cout<<"AAA";
vector<vector<int> > pos(2*n+5);
for(int i = 2*n-1; i>=0; i--){
H(S[i]);
H(S[i]+n);
pos[S[i]+n].push_back(i);
}
ftree ft(2*n);
vector<bool> vis(2*n, 0);
int cnt = 0;
//cout<<"blib"<<endl;
for(int i = 0; i < 2*n; i++){
if(vis[i]) continue;
int x = pos[n-S[i]].back();
pos[n-S[i]].pop_back();
pos[S[i]+n].pop_back();
H(i);
H(x);
H( x - i - ((S[i]<0)?1:0));
cnt += x - i - ((S[i]<0)?1:0);
H(cnt);
cnt -= ft.query(x) - ft.query(i+1);
H(cnt);
ft.update(x, 1);
vis[x]=true;
}
return cnt;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In member function 'void ftree::update(int, int)':
shoes.cpp:38:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = i+1; j<tree.size(); j+=(j&-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... |