이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second
#define cbr cerr<<"hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x,y) (lower_bound(all(x),y)-x.begin())
#define ubd(x,y) (upper_bound(all(x),y)-x.begin())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
using ll=long long;
using ld=long double;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>;
#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (200006)
ll n, fw[MAXN];
void update(int x,ll nval){
++ x;
for(;x<MAXN;x+=x&(-x)) fw[x]+=nval;
}
ll sum(int x){
++ x;
ll res=0;
for(;x;x-=x&(-x)) res+=fw[x];
return res;
}
long long count_swaps(std::vector<int> A) {
ll n=A.size()/2, ans = 0;
deque<deque<deque<ll>>> sz(n+1, deque<deque<ll>>(2, deque<ll>()));
vector<pi> e;
vector<ll> v(2*n,0);
FOR(i,0,2*n-1){
bool R = A[i]>0;
ll x=abs(A[i]);
sz[x][R].eb(i);
if(sz[x][0].size()&&sz[x][1].size()){
e.eb(sz[x][0][0],sz[x][1][0]),sz[x][0].pop_front(), sz[x][1].pop_front();
}
}
assert(e.size() == n);
FOR(i,0,n-1)A[e[i].f]=-(i+1), A[e[i].s]=i+1;
for(auto i:e){
ll a=i.f,b=i.s;
if(a>b)swap(a,b), ++ans;
v[b]=v[a]=a;
}
FOR(i,0,2*n-1){
if(v[i] ^ i) ans += sum(MAXN-2) - sum(v[i]);
update(v[i], 1);
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
In file included from /usr/include/c++/7/cassert:44:0,
from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
from shoes.cpp:3:
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:55:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
assert(e.size() == n);
~~~~~~~~~^~~~
# | 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... |