CSES - Datatähti 2019 alku - Results
Submission details
Task:Taulukko
Sender:EA999
Submission time:2018-10-07 16:45:44 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:7:20: error: no matching function for call to 'std::basic_istream<char>::tie(bool)'
  std::cin.tie(false);
                    ^
In file included from /usr/include/c++/7/ios:44:0,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from input/code.cpp:1:
/usr/include/c++/7/bits/basic_ios.h:295:7: note: candidate: std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie() const [with _CharT = char; _Traits = std::char_traits<char>]
       tie() const
       ^~~
/usr/include/c++/7/bits/basic_ios.h:295:7: note:   candidate expects 0 arguments, 1 provided
/usr/include/c++/7/bits/basic_ios.h:307:7: note: candidate: std::basic_ostream<_CharT, _Traits>* std::basic_ios<_CharT, _Traits>::tie(std::basic_ostream<_CharT, _Traits>*) [with _CharT = char; _Traits = std::char_traits<char>]
       tie(basic_ostream<_CharT, _Traits>* __tiestr)
       ^~~
/usr...

Code

#include <iostream>
#include <iomanip>
#include <unordered_set>
int main()
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(false);

	std::unordered_set<int_fast64_t> joukko;
	int_fast32_t n, k;
	int_fast64_t luku,vastaus=1; //1, koska lasketaan myös koko jono 
	std::scanf("%i %i", &n, &k);
	joukko.reserve(k);
	for(int_fast64_t oikea=0;oikea<n;oikea++)
	{
		std::scanf("%li", &luku);
		if (joukko.size()==k)
		{
			vastaus += n - oikea + 1;
			joukko.erase(joukko.begin());
		}
		joukko.insert(luku);
	}
	if (vastaus==1)
	{
		//jos vastaus on vieläkin 1, koko jonokaan ei käy
		vastaus--;
	}
	std::printf("%li", vastaus);
	return 0;
}