Submission #149652

# Submission time Handle Problem Language Result Execution time Memory
149652 2019-09-01T06:54:33 Z 20190901(#3597, tongnamuu, jf297, upple1) King of Chairs (FXCUP4_chairs) C++17
17 / 100
314 ms 40392 KB
#include "king.h"
#include <algorithm>
#include <iostream>
int mylower_bound(std::vector<int>& c, int n, int val) {
	int start = 0, end = n;
	while (start <= end) {
		int mid = (start + end) / 2;
		if (c[mid] < val) start = mid + 1;
		else end = mid - 1;
	}
	return start;
}
long long SendInfo(std::vector<int> W, std::vector<int> C) {
	int N = W.size();
	sort(W.begin(), W.end());
	sort(C.begin(), C.end());
	long long cansitbegin = -2;
	long long cansitend = -2;
	int X = N - 1;
	for (int i = N - 1; i >= 0; --i) {
		int index = mylower_bound(C, X, W[i]);
		if (index <= X) {
			if (cansitend == -2) {
				cansitend = X;
				cansitbegin = X;
			}
			else {
				cansitbegin = X;
			}
			X--;
		}
	}
	return cansitend * 1000001 + cansitbegin;
}

#include "vassal.h"
#include <vector>
std::vector<int> recover[1000001];
int seg[4000004];
void update(int node, int start, int end, int index, int val) {
	if (index<start || index>end) return;
	if (start == end) {
		seg[node] += val;
		return;
	}
	update(node * 2, start, (start + end) / 2, index, val);
	update(node * 2 + 1, (start + end) / 2 + 1, end, index, val);
	seg[node] = seg[node * 2] + seg[node * 2 + 1];
}
int sumquery(int node, int start, int end, int i, int j) {
	if (start > j || end < i) return 0;
	if (i <= start && end <= j) return seg[node];
	return sumquery(node * 2, start, (start + end) / 2, i, j) + sumquery(node * 2 + 1, (start + end) / 2 + 1, end, i, j);
}
int kthquery(int node, int start, int end, int kth) {
	if (start == end) return start;
	if (seg[2 * node] >= kth) {
		return kthquery(node * 2, start, (start + end) / 2, kth);
	}
	else return kthquery(node * 2 + 1, (start + end) / 2 + 1, end, kth - seg[node * 2]);
}
void Init(long long B, std::vector<int> C){
	int N = C.size();
	int start = B % 1000001;
	int endw = B / 1000001;
	for (int i = start; i <= endw; ++i) {
		update(1, 1, 1000000, C[i], 1);
		recover[C[i]].push_back(i);
	}
}

int Maid(int W){
	int before = sumquery(1, 1, 1000000, 1, W - 1);
	int cnt = sumquery(1, 1, 1000000, W, 1000000);
	if (cnt == 0) return -1;
	else {
		int ans = kthquery(1, 1, 1000000, before + 1);
		update(1, 1, 1000000, ans, -1);
		int index = recover[ans][recover[ans].size() - 1];
		recover[ans].pop_back();
		return index;
	}
}

Compilation message

vassal.cpp: In function 'void Init(long long int, std::vector<int>)':
vassal.cpp:28:6: warning: unused variable 'N' [-Wunused-variable]
  int N = C.size();
      ^
# Verdict Execution time Memory Grader output
1 Correct 24 ms 24596 KB Correct
2 Correct 25 ms 24720 KB Correct
3 Correct 24 ms 24852 KB Correct
4 Correct 24 ms 24852 KB Correct
5 Correct 24 ms 24728 KB Correct
# Verdict Execution time Memory Grader output
1 Incorrect 122 ms 36712 KB Wrong
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 163 ms 36700 KB B = 51294051598
2 Partially correct 263 ms 39712 KB B = 91757092109
3 Partially correct 229 ms 36548 KB B = 99999150152
4 Partially correct 274 ms 40392 KB B = 99999100149
5 Partially correct 313 ms 40388 KB B = 99999100401
6 Partially correct 314 ms 40392 KB B = 99999100253
7 Partially correct 224 ms 36556 KB B = 99999150089
8 Runtime error 82 ms 27980 KB Execution failed because the return code was nonzero