제출 #206053

#제출 시각아이디문제언어결과실행 시간메모리
206053spdskatrArranging Shoes (IOI19_shoes)C++14
100 / 100
131 ms24184 KiB
#include "shoes.h"
#include <vector>
#include <cstdlib>
#include <cstdio>
#define SZ (1<<18)
using namespace std;

int N, st[1<<19], claimed[1<<18];
vector<int> pos[1<<19];

void seg_set(int i, int v) {
	for (st[i += SZ] = v; i > 1; i >>= 1) {
		st[i>>1] = st[i] + st[i^1];
	}
}
int seg_sum(int l, int r) {
	int res = 0;
	for (l += SZ, r += SZ; l < r; l >>= 1, r >>= 1) {
		if (l&1) res += st[l++];
		if (r&1) res += st[--r];
	}
	return res;
}

long long count_swaps(vector<int> s) {
	long long ans = 0;
	N = (int)s.size() / 2;
	for (int i = s.size() - 1; i >= 0; i--) {
		pos[s[i] + SZ].push_back(i);
		seg_set(i, 1);
	}
	for (int i = 0; i < s.size(); i++) {
		if (!claimed[i]) {
			pos[s[i]+SZ].pop_back();
			if (s[i] < 0) {
				int otherpos = pos[-s[i]+SZ].back(); pos[-s[i]+SZ].pop_back();
				ans = (ans + seg_sum(i+1, otherpos));
				seg_set(otherpos, 0);
				claimed[otherpos] = 1;
			} else {
				int otherpos = pos[-s[i]+SZ].back(); pos[-s[i]+SZ].pop_back();
				ans = (ans + seg_sum(i, otherpos));
				seg_set(otherpos, 0);
				claimed[otherpos] = 1;
			}
		}
	}
	return ans;
}

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:32:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < s.size(); i++) {
                  ~~^~~~~~~~~~
#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...