CSES - Datatähti 2019 alku - Results
Submission details
Task:Taulukko
Sender:Ilmari2000
Submission time:2018-10-08 16:20:08 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void* perform_work(void*)':
input/code.cpp:39:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
output/ccYETkDZ.o: In function `main':
code.cpp:(.text.startup+0xdf): undefined reference to `pthread_create'
code.cpp:(.text.startup+0x11f): undefined reference to `pthread_create'
code.cpp:(.text.startup+0x163): undefined reference to `pthread_create'
code.cpp:(.text.startup+0x1a5): undefined reference to `pthread_create'
code.cpp:(.text.startup+0x1e7): undefined reference to `pthread_create'
output/ccYETkDZ.o:code.cpp:(.text.startup+0x232): more undefined references to `pthread_create' follow
collect2: error: ld returned 1 exit status

Code

#include <iostream>
#include <set>

#include <pthread.h>

using namespace std;

int n, k;
int *a;

long long int ret = 0;

int tc = 0;

void *perform_work(void *arg)
{
	pair<int, int> *se = (pair<int, int>*)arg;
	for(int i = se->first; i < se->second; i++)
	{
		set<int> nums;
		int u = 0;

		for(int j = 0; i+j < n; j++)
		{
			if(!nums.count(a[i+j]))
			{
				nums.insert(a[i+j]);
				u++;
			}

			if(u > k)
				break;

			ret++;
		}
	}
	
	tc--;
}

int main()
{
	cin >> n >> k;

	a = new int[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];

	pthread_t threads[8];
	tc = 8;

	pthread_create(&threads[0], NULL, perform_work, new pair<int, int>(0, n / 8));
	pthread_create(&threads[1], NULL, perform_work, new pair<int, int>(1 * n / 8, 2 * n / 8));
	pthread_create(&threads[2], NULL, perform_work, new pair<int, int>(2 * n / 8, 3 * n / 8));
	pthread_create(&threads[3], NULL, perform_work, new pair<int, int>(3 * n / 8, 4 * n / 8));
	pthread_create(&threads[4], NULL, perform_work, new pair<int, int>(4 * n / 8, 5 * n / 8));
	pthread_create(&threads[5], NULL, perform_work, new pair<int, int>(5 * n / 8, 6 * n / 8));
	pthread_create(&threads[6], NULL, perform_work, new pair<int, int>(6 * n / 8, 7 * n / 8));
	pthread_create(&threads[7], NULL, perform_work, new pair<int, int>(7 * n / 8, n));

	while(tc);

	cout << ret << endl;

	return 0;
}