QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#290584#2670. Arranging shoesMoRanSkyCompile Error//C++231.4kb2023-12-25 05:58:122023-12-25 05:58:13

Judging History

你现在查看的是最新测评结果

  • [2023-12-25 05:58:13]
  • 评测
  • [2023-12-25 05:58:12]
  • 提交

answer

// Skyqwq
#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }

template <typename T> void inline read(T &x) {
    int f = 1; x = 0; char s = getchar();
    while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
    while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
    x *= f;
}

const int N = 2e5 + 5;

int n, a[N], c[N];

LL ans;

map<int, set<int> > pos;

void inline add(int x, int k) {
	for (; x <= 2 * n; x += x & -x) c[x] += k;
}

int inline ask(int x) {
	int ret = 0;
	for (; x ; x -= x & -x) ret += c[x];
	return ret;
}

bool vis[N];

int main() {
	read(n);
	for (int i = 1; i <= 2 * n; i++) add(i, 1), read(a[i]), pos[a[i]].insert(i);
	for (int i = 1; i <= 2 * n; i++) {
		if (vis[i]) continue;
		add(i, -1);
		pos[a[i]].erase(i);
		if (a[i] < 0) {
			int nx = *pos[-a[i]].begin();
			pos[-a[i]].erase(nx);
			vis[nx] = 1;
			ans += ask(nx - 1);
			add(nx, -1);
		} else {
			int nx = *pos[-a[i]].begin();
			pos[-a[i]].erase(nx);
			vis[nx] = 1;
			ans += ask(nx - 1) + 1;
			add(nx, -1);
		}
	}
	printf("%lld\n", ans);
    return 0;
}

详细

/usr/bin/ld: /tmp/ccc31Lbs.o: in function `main':
answer.code:(.text.startup+0x0): multiple definition of `main'; /tmp/cc3AmsAs.o:implementer.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc3AmsAs.o: in function `main':
implementer.cpp:(.text.startup+0x2a1): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status