제출 #143587

#제출 시각아이디문제언어결과실행 시간메모리
143587kdh9949Arranging Shoes (IOI19_shoes)C++17
45 / 100
136 ms27004 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define all(x) x.begin(),x.end()
#define cppio ios_base::sync_with_stdio(0);cin.tie(0)

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int N = 200005;

vector<int> u[N], v[N], t[N];
int a[N];

struct BIT{
	int d[N];
	void u(int x){ for(; x < N; x += x & -x) d[x]++; }
	int g(int x){ int r = 0; for(; x; x -= x & -x) r += d[x]; return r; }
	int g(int s, int e){ return g(e) - g(s - 1); }
} B;

ll count_swaps(vector<int> s) {
	int n = s.size() / 2;
	int c = 0;
	for(int i = 0; i < 2 * n; i++){
		(s[i] < 0 ? u : v)[abs(s[i])].pb(i);
		if(s[i] < 0) t[-s[i]].pb(++c);
	}
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < u[i].size(); j++){
			a[u[i][j]] = 2 * t[i][j] - 1;
			a[v[i][j]] = 2 * t[i][j];
		}
	}
	ll r = 0;
	for(int i = 0; i < 2 * n; i++){
		r += B.g(a[i] + 1, 2 * n);
		B.u(a[i]);
	}
	return r;
}

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:37:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0; j < u[i].size(); j++){
                  ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...