QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#136181 | #5038. City | PetroTarnavskyi# | RE | 0ms | 0kb | C++17 | 1.7kb | 2023-08-07 15:32:50 | 2023-08-07 15:32:52 |
Judging History
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