Submission #1018626

#TimeUsernameProblemLanguageResultExecution timeMemory
1018626vjudge1Izbori (COCI22_izbori)C++17
25 / 110
3034 ms1112 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

random_device rd;
mt19937_64 rng(rd.entropy() != 0 ? rd() : chrono::high_resolution_clock::now().time_since_epoch().count());

constexpr uint MOD = 1e9+7;
constexpr uint mod = 998244353;
constexpr long double PI = 3.14159265358979323846264; // PI 23 decimal digit
struct chash {
	static constexpr int64_t C = int64_t(2e18 * PI) + 23;
	const int64_t RANDOM = rng();
	const int64_t B = uniform_int_distribution<int64_t>(0, MOD - 1)(rng);
	const int64_t b = uniform_int_distribution<int64_t>(0, mod - 1)(rng);
	template <typename T1, typename T2> inline size_t operator()(pair<T1, T2> const& x) const;
	template <typename T, enable_if_t<is_integral<T>::value, bool> = true>
	inline size_t operator()(T const& x) const {
		return __builtin_bswap64((int64_t(x)^RANDOM)*C);
	}
	inline size_t operator()(string const& x) const {
		int64_t curb = 1, curB = 1, curh = 0, curH = 0;
		for(int i=0; i<x.size(); i++) {
			curh += (curb * this->operator()(x[i])) % mod;
			curH += (curB * this->operator()(x[i])) % MOD;
			curh %= mod;
			curH %= MOD;
			curb = (curb * b) % mod;
			curB = (curB * B) % MOD;
		}
		size_t hash = int64_t(uint(curh)) + (int64_t(uint(curH))<<32);
		return this->operator()(hash);
	}
};
template <typename T1, typename T2> inline size_t chash::operator()(pair<T1, T2> const& x) const {
	return this->operator()((this->operator()(x.F) % MOD + ((this->operator()(x.S) % MOD) * B) % MOD) % MOD);
}

template <typename T1, typename T2> using cmap = __gnu_pbds::gp_hash_table<T1, T2, chash>;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto &x:a) cin >> x;
	int ans = 0;
	for(int i = 0; i < n; i ++) {
		cmap<int, int> m;
		int curmax = 0;
		for(int j = i; j < n; j ++) {
			m[a[j]]++;
			curmax = max(curmax, m[a[j]]);
			if(curmax > (j - i + 1) / 2) ans++;
		}
	}
	cout << ans << '\n';
}

Compilation message (stderr)

Main.cpp: In member function 'size_t chash::operator()(const string&) const':
Main.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(int i=0; i<x.size(); i++) {
      |                ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...