이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
typedef int64_t lld;
typedef pair<int, int> pii;
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<typename T, typename comp = greater<T>>
using OST = tree<T, null_type, comp, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p){
return out << "(" << p.ff << ", " << p.ss << ")";
}
map<int, int> cnt;
map<pii, int> mp;
vector<int> bit;
void add(int i){
i = bit.size()-i;
do bit[i]++;
while((i += i&-i) < bit.size());
}
int query(int i){
i = bit.size()-i;
int ans = 0;
do ans += bit[i];
while(i -= i&-i);
return ans;
}
OST<int> ost;
long long count_swaps(vector<int> s) {
lld ans = 0; int id = 0;
for(auto i: s)if(mp[{-i, cnt[i]}])mp[{i, cnt[i]}] = mp[{-i, cnt[i]}], cnt[i]++; else mp[{i, cnt[i]++}] = ++id;
cnt.clear(), id = 0; bit.resize(2*s.size()+4);
for(auto i: s)id = (i > 0?mp[{-i, cnt[i]++}]*2+1:mp[{i, cnt[i]++}]*2), ans += query(id), add(id);
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'void add(int)':
shoes.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | while((i += i&-i) < bit.size());
| ~~~~~~~~~~~~^~~~~~~~~~~~
# | 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... |