Submission #647101

# Submission time Handle Problem Language Result Execution time Memory
647101 2022-10-01T15:05:17 Z georgievskiy popa (BOI18_popa) C++17
Compilation error
0 ms 0 KB
// #define LOCAL
#ifndef LOCAL
#include "popa.h"
#endif
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL

int ARR[100], LEFT[100], RIGHT[100];
int f_gcd(int a, int b) {
	int g = 0;
	for (int i = a; i <= b; i++)
		g = __gcd(g, ARR[i]);
	return g;
}

int query(int a, int b, int c, int d) {
	return f_gcd(a, b) == f_gcd(c, d);
}

#endif

int rec(int l, int r, int* left, int* right, vector<int>& dl, vector<int>& dr) {
	if (l >= r)
		return -1;
	if (l + 1 == r)
		return l;
	int root = -1;
	for (int i = l; i < r; i++) {
		if (dl[i] <= l && dr[i] >= r - 1) {
			root = i;
			break;
		}
	}
	assert(root >= l && root < r);
	left[root] = rec(l, root, left, right);
	right[root] = rec(root + 1, r, left, right);
	return root;
}

int solve(int n, int* left, int* right) {
	fill(left, left + n, -1), fill(right, right + n, -1);
	vector<int> dl(n), dr(n);
	for (int i = 0; i < n; i++) {
		{
			int l = -1, r = i;
			while (r - l > 1) {
				int c = (l + r) / 2;
				if (query(c, i, i, i))
					r = c;
				else
					l = c;
			}
			dl[i] = r;
		}
		{
			int l = i, r = n;
			while (r - l > 1) {
				int c = (l + r) / 2;
				if (query(i, c, i, i))
					l = c;
				else
					r = c;
			}
			dr[i] = l;
		}
	}
	return rec(0, n, left, right);
}

#ifdef LOCAL

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> ARR[i];
	solve(n, LEFT, RIGHT);
	for (int i = 0; i < n; i++)
		cout << LEFT[i] << " ";
	cout << "\n";
	for (int i = 0; i < n; i++)
		cout << RIGHT[i] << " ";
	cout << "\n";
	return 0;
}

#endif

Compilation message

popa.cpp: In function 'int rec(int, int, int*, int*, std::vector<int>&, std::vector<int>&)':
popa.cpp:37:39: error: too few arguments to function 'int rec(int, int, int*, int*, std::vector<int>&, std::vector<int>&)'
   37 |  left[root] = rec(l, root, left, right);
      |                                       ^
popa.cpp:24:5: note: declared here
   24 | int rec(int l, int r, int* left, int* right, vector<int>& dl, vector<int>& dr) {
      |     ^~~
popa.cpp:38:44: error: too few arguments to function 'int rec(int, int, int*, int*, std::vector<int>&, std::vector<int>&)'
   38 |  right[root] = rec(root + 1, r, left, right);
      |                                            ^
popa.cpp:24:5: note: declared here
   24 | int rec(int l, int r, int* left, int* right, vector<int>& dl, vector<int>& dr) {
      |     ^~~
popa.cpp: In function 'int solve(int, int*, int*)':
popa.cpp:69:30: error: too few arguments to function 'int rec(int, int, int*, int*, std::vector<int>&, std::vector<int>&)'
   69 |  return rec(0, n, left, right);
      |                              ^
popa.cpp:24:5: note: declared here
   24 | int rec(int l, int r, int* left, int* right, vector<int>& dl, vector<int>& dr) {
      |     ^~~