QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#303349#15. 虫逢Unknown1508Compile Error//C++203.5kb2024-01-12 09:48:052024-01-12 09:48:05

Judging History

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

  • [2024-01-12 09:48:05]
  • 评测
  • [2024-01-12 09:48:05]
  • 提交

answer

#pragma GCC optimize("Ofast,unroll-loops")

#include <bits/stdc++.h>
using namespace std;

void main_program();

signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	main_program();
}

using u8 = uint8_t;
template <class T>
using uset = unordered_set<T>;

int n, M, L;
int n_div_10;
string s;

vector<int> mapping, answer;
vector<vector<int>> A;
int newval = 0;

void create_mapping(){
	mapping.assign(256, 0);
	int crr = 0;
	for (char c = 'a'; c <= 'z'; c++) mapping[c] = crr++;
	for (char c = 'A'; c <= 'Z'; c++) mapping[c] = crr++;
	for (char c = '0'; c <= '9'; c++) mapping[c] = crr++;
	for (char c: "~!@#$%^&()[]`:;\"'<>,.?/|\\=-{}") mapping[c] = crr++;
}

int remaining = 0;
map<pair<int, int>, bool> cache;
bool equivalent(int a, int b){
	if (a > b) swap(a, b);
	if (cache.count({a, b})) return cache[{a, b}];

	int cnt = 0;
	int it1 = 0, it2 = 0;
	while (it1 < L && it2 < L){
		if (A[a][it1] == A[b][it2]){
			it1++; it2++; cnt++;
		}
		else if (A[a][it1] < A[b][it2]) it1++;
		else it2++;

		if (remaining >= max(100, n_div_10) && it1 >= 6 && cnt == 0) return false;
	}

	return cache[{a, b}] = (cnt >= L/2);
}

using u32 = uint32_t;
u32 faster_rand(){
	static u32 state = 2945725598;
	state += 9877345679;
	u32 z = state;
	z = (z ^ (z >> 14)) * 897698346;
	z = (z ^ (z >> 12)) * 797536943;
	return z ^ (z >> 15);
}

vector<int> vec;
void run_hash_function(){
	for (auto &val: vec) val = faster_rand();
}

void main_program(){
	cin >> n >> M >> L;
	n_div_10 = n / 10;
	cin >> s;

	create_mapping();
	answer.assign(n * 2, -1);
	A.assign(n * 2, vector<int>(L));
	map<int, vector<int>> mp;

	map<int, int> compress;

	for (int i = 0; i < n * 2; i++){
		for (int j = 0; j < L; j++){
			int H = 0;
			for (int k = 0; k < 4; k++){
				H = H * 92 + mapping[s[i * L * 4 + j * 4 + k]];
			}
			mp[H].push_back(i);
			A[i][j] = H;
			compress[H] = 1;
		}
	}

	for (auto &[key, value]: compress) value = newval++;

	for (int i = 0; i < n * 2; i++){
		for (int j = 0; j < L; j++){
			A[i][j] = compress[A[i][j]];
		}
	}

	for (int i = 0; i < n * 2; i++){
		sort(A[i].begin(), A[i].end());
	}

	// for (int i = 0; i < n * 2; i++){
	// 	for (int j = 0; j < L; j++){
	// 		cout << A[i][j] << " ";
	// 	}
	// 	cout << "\n";
	// }

	vec.resize(newval);

	remaining = n;
	vector<pair<int, int>> group(n * 2);
	while (remaining){
		// cout << "New iteration" << endl;
		vector<int> order;

		run_hash_function();
		for (int i = 0; i < n * 2; i++){
			if (answer[i] >= 0) continue;
			group[i] = {INT_MAX, INT_MAX};
			order.push_back(i);
			for (int j = 0; j < L; j++){
				group[i].first = min(group[i].first, vec[A[i][j]]);
			}
		}

		int crridx = 0;
		run_hash_function();
		for (int i = 0; i < n * 2; i++){
			for (int j = 0; j < L; j++){
				group[crridx].second = min(group[crridx].second, vec[A[i][j]]);
			}
			crridx++;
		}

		shuffle(order.begin(), order.end());
		sort(order.begin(), order.end(), [&](int idx1, int idx2){
			return group[idx1] < group[idx2];
		});

		// for (auto idx: order) cout << "idx = " << idx << endl;

		int sz = order.size();
		for (int i = 0; i < sz; i++){
			int ii = order[i];
			if (answer[ii] >= 0) continue;
			for (int j = i + 1; j < min(i + 4, sz); j++){
				int jj = order[j];
				if (group[jj] != group[ii]) break;

				if (equivalent(ii, jj)){
					answer[ii] = jj;
					answer[jj] = ii;
					remaining--;
					break;
				}
			}
		}
	}

	for (int i = 0; i < n * 2; i++){
		cout << answer[i] + 1 << "\n";
	}
}

Details

answer.code: In function ‘void main_program()’:
answer.code:140:24: error: no matching function for call to ‘shuffle(std::vector<int>::iterator, std::vector<int>::iterator)’
  140 |                 shuffle(order.begin(), order.end());
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:3:
/usr/include/c++/11/bits/stl_algo.h:3729:5: note: candidate: ‘template<class _RAIter, class _UGenerator> void std::shuffle(_RAIter, _RAIter, _UGenerator&&)’
 3729 |     shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~~~~
/usr/include/c++/11/bits/stl_algo.h:3729:5: note:   template argument deduction/substitution failed:
answer.code:140:24: note:   candidate expects 3 arguments, 2 provided
  140 |                 shuffle(order.begin(), order.end());
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~