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

Compiler report

input/code.cpp: In function 'void* tf(std::pair<int, int>*)':
input/code.cpp:37:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
output/ccMKOtTO.o: In function `std::thread::thread<void* (&)(std::pair<int, int>*), std::pair<int, int>*>(void* (&)(std::pair<int, int>*), std::pair<int, int>*&&)':
code.cpp:(.text._ZNSt6threadC2IRFPvPSt4pairIiiEEJS4_EEEOT_DpOT0_[_ZNSt6threadC5IRFPvPSt4pairIiiEEJS4_EEEOT_DpOT0_]+0x3c): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status

Code

#include <iostream>
#include <set>
#include <thread>

using namespace std;

int n, k;
int *a;

long long int ret = 0;

int tc = 0;

void *tf(pair<int, int> *se)
{
	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];

	tc = 2;
	thread t1(tf, new pair<int, int>(0, n/2));
	thread t2(tf, new pair<int, int>(n/2, n));

	t1.join();
	t2.join();	

	cout << ret << endl;

	return 0;
}