이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
#include <shoes.h>
using namespace std;
//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007
typedef long long ll;
ll add(ll a, ll b) {
a += b;
if(a >= MOD) {
a -= MOD;
}
return a;
}
ll sub(ll a, ll b) {
a -= b;
if(a < 0) {
a += MOD;
}
return a;
}
ll mul(ll a, ll b) {
return (a * b)%MOD;
}
void add_self(ll& a, ll b) {
a = add(a, b);
}
void sub_self(ll& a, ll b) {
a = sub(a, b);
}
void mul_self(ll& a, ll b) {
a = mul(a, b);
}
const ll MAXN = 200010;
ll tree[MAXN];
ll N;
void update(ll ind, ll num) {
while (ind<=MAXN) {
tree[ind]+=num;
ind+=(ind&-ind);
}
}
ll getsum(ll ind) {
ll sum = 0;
while (ind) {
sum+=tree[ind];
ind-=(ind&-ind);
}
return sum;
}
map<ll, queue<ll>> closest;
ll closestind[MAXN];
ll vis[MAXN];
ll S[MAXN];
long long count_swaps(std::vector<int> s) {
N = s.size();
for (ll i = 0; i<s.size(); i++) S[i+1] = s[i];
for (ll i = 1; i<=N; i++) {
if (closest.find(S[i]) == closest.end()) {
queue<ll> q1;
closest[S[i]] = q1;
}
if (closest.find(-S[i]) != closest.end()) {
closestind[closest[-S[i]].front()] = i;
closest[-S[i]].pop();
} else {
closest[S[i]].push(i);
}
}
ll ans = 0;
for (ll i = 1; i<=N; i++) {
if (!vis[i]) {
ans+=closestind[i]-i-1-(getsum(closestind[i])-getsum(i))+(S[i] > 0);
update(closestind[i], 1);
vis[closestind[i]] = 1;
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:90:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (ll i = 0; i<s.size(); i++) S[i+1] = s[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... |