이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
//#include "shoes.h"
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <ll, pii> piii;
typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> OST;
const ll NMAX = 200005;
const ll INF = (1LL << 30);
const ll MOD = 1000000007;
const ll BLOCK = 101;
const ll nr_of_bits = 35;
queue <int> pz[NMAX];
int v[NMAX];
int aib[NMAX];
int n;
void update(int x, int v){
for(int i = x; i <= n; i += i&(-i))
aib[i] += v;
}
int query(int x){
int v = 0;
for(int i = x; i > 0; i -= i&(-i))
v += aib[i];
return v;
}
int cod(int x){
if(x > 0)
return x + n;
else return -x;
}
long long count_swaps(vector<int> s) {
n = s.size();
for(int i = 0; i < s.size(); i++){
v[i + 1] = s[i];
pz[cod(v[i + 1])].push(i + 1);
update(i + 1, 1);
}
ll sol = 0;
for(int i = 1; i <= n; i++){
if(pz[cod(v[i])].front() != i)
continue;
pz[cod(v[i])].pop();
if(v[i] < 0)
update(i, -1);
int cn = pz[cod(-v[i])].front();
pz[cod(-v[i])].pop();
update(cn, -1);
sol += 1LL * query(cn);
if(v[i] > 0)
update(i, -1);
}
return sol;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i = 0; i < s.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... |