QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136181#5038. CityPetroTarnavskyi#RE 0ms0kbC++171.7kb2023-08-07 15:32:502023-08-07 15:32:52

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-07 15:32:52]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-08-07 15:32:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

int mod;

int add(int a, int b)
{
	return (a + b < mod) ? (a + b) : (a + b - mod);
}

int sub(int a, int b)
{
	return (a - b < 0) ? (a - b + mod) : (a - b);
}

int mult(int a, int b)
{
	return 1LL * a * b % mod;
}

int binpow(int a, int n)
{
	int res = 1;
	while(n){
		if(n & 1)
			res = mult(res, a);
		a = mult(a, a);
		n /= 2;
	}
	return res;
}

int inv(int a)
{
	return binpow(a, mod - 2);
}

int check(VI& a, int q)
{
	int qi = inv(q);
	map<int, int> m;
	int n = SZ(a);
	int ans = 0;
	FOR (i, 0, n)
	{
		int ai = mult(a[i], qi);
		m[a[i]] = m[ai] + 1; 
		ans = max(ans, m[a[i]]);
	}
	return ans;
}

void solve()
{
	int n;
	cin >> n >> mod;
	VI a(n);
	FOR (i, 0, n) cin >> a[i];
	VI ai(n);
	FOR (i, 0, n) ai[i] = inv(a[i]);
	
	map<int, int> cand;
	FOR (i, 1, n)
	{
		int q = mult(a[i], ai[i - 1]);
		cand[q]++;
		if (i > 1)
		{
			q = mult(a[i], ai[i - 2]);
			cand[q]++;
		}
	}
	vector<PII> v;
	for (auto [q, c] : cand) v.PB({c, q});
	sort(ALL(v), greater());
	
	VI ans = {-1};
	FOR (i, 0, min(7, SZ(v)))
	{
		int x = check(a, v[i].S);
		if (x * 2 >= n) ans.PB(x);
	}
	cout << *max_element(ALL(ans)) << '\n';
	
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int t;
	cin >> t;
	while (t--)
	{
		solve();
	}
	
	return 0;
}


详细

Test #1:

score: 0
Runtime Error

input:

1 1

output:


result: