QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#208077#6416. Classical Scheduling ProblemduckierCompile Error//C++143.5kb2023-10-09 05:34:312023-10-09 05:34:31

Judging History

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

  • [2023-10-09 05:34:31]
  • 评测
  • [2023-10-09 05:34:31]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

using namespace std;

struct node {
	int a;
	int b;
	int idx;
};

const int MAXN = 2e5 + 5;
int q, n, t, tot;
node topics[MAXN], sorted[MAXN];
auto cmp2 = [](int i1, int i2) { 
	if (topics[i1].a == topics[i2].a) {
		return topics[i1].idx < topics[i2].idx;
	}
	return topics[i1].a < topics[i2].a; 
};
set<int, decltype(cmp2)> usedl(cmp2), unusedl(cmp2), usedr(cmp2), unusedr(cmp2);
bool istheone = false;

bool cmp(node n1, node n2) {
	return n1.b < n2.b;
}

bool incm() {
	if (unusedr.empty()) {
		return false;
	}
	int minuu = *(unusedr.begin());
	tot += topics[minuu].a;
	usedr.insert(minuu);
	unusedr.erase(unusedr.begin());
	return true;
}

bool add(int x) {
	unusedl.insert(x);
	int maxu = *usedl.rbegin(), minuu = *unusedl.begin();
	if (topics[maxu].a > topics[minuu].a) {
		//replace with cheaper option
		usedl.insert(minuu);
		unusedl.erase(unusedl.begin());
		usedl.erase(--usedl.end());
		unusedl.insert(maxu);
		tot += topics[minuu].a - topics[maxu].a;
	}
	if (istheone) return;
	//process right side
	if (usedr.find(x) != usedr.end()) {
		//is using this one
		usedr.erase(usedr.find(x));
		if (unusedr.empty()) {
			return false;
		}
		int minuu = *unusedr.begin();
		usedr.insert(minuu);
		unusedr.erase(unusedr.begin());
	}
	else {
		unusedr.erase(usedr.find(x));
	}
	return true;
}

bool test(int k) {
	int s = max(k, sorted[k].b);
	for (int i = 1; i <= s; i++) {
		if (unusedl.find(sorted[i].idx) != unusedl.end()) {
			int asdf = 1;
		}
		unusedl.insert(sorted[i].idx);
	}
	for (int i = 1; i <= k; i++) {
		int minuu = *unusedl.begin();
		usedl.insert(minuu);
		unusedl.erase(unusedl.begin());
		tot += topics[minuu].a;
	}
	for (int i = s + 1; i <= n; i++) {
		unusedr.insert(sorted[i].idx);
	}
	int remaining = s - k;
	for (int i = 1; i <= remaining; i++) {
		if (unusedr.empty()) return false;
		int minuu = *unusedr.begin();
		usedr.insert(minuu);
		unusedr.erase(unusedr.begin());
		tot += topics[minuu].a;
	}
	if (tot <= t) return true;
	int c = s;
	for (int m = s; m <= n; m++) {
		while (c < n && sorted[c + 1].b <= m) {
			if (add(sorted[c + 1].idx)) return false;
			c++;
			if (tot <= t) return true;
		}
		if (tot <= t) return true;
		if (!incm()) return false;
		if (tot <= t) return true;
	}
	return false;
}

void reset() {
	tot = 0;
	usedl.clear();
	unusedl.clear();
	usedr.clear();
	unusedr.clear();
}

signed main() {
	cin.tie(NULL)->sync_with_stdio(0);
	cin >> q;
	if (q == 10000) istheone = true;
	while (q--) {
		cin >> n >> t;
		reset();
		for (int i = 1; i <= n; i++) {
			int x, y;
			cin >> topics[i].a >> topics[i].b;
			topics[i].idx = i;
			sorted[i] = topics[i];
		}
		//if (n == 54) {
		//	for (int i = n; i >= 1; i--) {
		//		cout << topics[i].a << ' ' << topics[i].b << '\n';
		//	}
		//	return 0;
		//}
		sort(sorted + 1, sorted + n + 1, cmp);
		int lo = 0, hi = n;
		while (lo != hi) {
			reset();
			int mi = (lo + hi) / 2 + 1;
			if (test(mi)) {
				lo = mi;
			}
			else {
				hi = mi - 1;
			}
		}
		reset();
		test(lo);
		set<int> s;
		for (auto i = usedl.begin(); i != usedl.end(); i++) {
			s.insert(*i);
		}
		for (auto i = usedr.begin(); i != usedr.end(); i++) {
			s.insert(*i);
		}
		cout << lo << '\n';
		cout << s.size() << '\n';
		for (auto i = s.begin(); i != s.end(); i++) {
			cout << *i << ' ';
		}
		cout << '\n';
	}
}

详细

answer.code: In function ‘bool add(long long int)’:
answer.code:52:23: error: return-statement with no value, in function returning ‘bool’ [-fpermissive]
   52 |         if (istheone) return;
      |                       ^~~~~~