QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#434875 | #8782. Schoolgirls | ucup-team055# | WA | 4ms | 3616kb | C++20 | 2.1kb | 2024-06-08 17:46:39 | 2024-06-08 17:46:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
bool is_prime(int n) {
for (int d = 2; d * d <= n; d++)
if (n % d == 0)
return false;
return true;
}
int modpow(int a, int e, int p) {
int r = 1;
while (e) {
if (e & 1)
r = (long long)r * a % p;
a = (long long)a * a % p;
e >>= 1;
}
return r;
}
int find_proot(int p) {
vector<int> ex;
for (int i = 2; i < p - 1; i++) {
if ((p - 1) % i == 0 && is_prime(i))
ex.push_back((p - 1) / i);
}
for (int g = 2; g < p; g++) {
bool ok = true;
for (auto e : ex) {
if (modpow(g, e, p) == 1) {
ok = false;
break;
}
}
if (ok)
return g;
}
return -1;
}
int main() {
int n, m, k;
cin >> n >> m >> k;
int p = n + 1;
while (!is_prime(p))
p += n;
const int g = find_proot(p);
vector<int> mlog(p), mexp(p - 1);
mlog[0] = -1;
{
int w = 1;
rep(i, 0, p - 1) {
mlog[w] = i;
mexp[i] = w;
w = (long long)w * g % p;
}
}
vector<int> Ks(1);
rep(i, 0, n) Ks.push_back(mexp[(p-1)/n*i]);
rep(i, 0, m) {
int a, b, c;
cin >> a >> b >> c;
int r = (Ks[a] + Ks[c] - Ks[b] + p) % p;
Ks.push_back(r);
}
rep(qs, 0, k) {
int r;
cin >> r;
vector<int> ords;
int sum = 0;
rep(i, 0, r) {
int x;
cin >> x;
ords.push_back(Ks[x]);
sum = (sum + Ks[x]) % p;
}
if (set(ords.begin(), ords.end()).size() == 1) {
cout << "Yes\n";
continue;
}
// b*r
const int b = (long long)sum * modpow(r, p - 2, p) % p;
bool ok = true;
for (auto& e : ords) {
e = (e + p - b) % p;
if (e == 0) {
ok = false;
break;
}
e = mlog[e];
}
if (!ok) {
cout << "No\n";
continue;
}
sort(ords.begin(), ords.end());
set<int> diff;
rep(i, 0, r) {
diff.insert((ords[(i + 1) % r] - ords[i] + (p - 1)) % (p - 1));
}
cout << (diff.size() == 1 ? "Yes" : "No") << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3488kb
input:
3 6 8 1 2 3 3 1 4 5 4 3 3 1 2 4 5 3 4 5 2 6 4 7 6 5 1 2 3 1 3 2 3 1 1 8 4 2 5 6 7 3 2 1 4 3 6 5 9 3 4 7 9 4 1 3 2 8
output:
Yes Yes Yes No No No Yes No
result:
ok 8 token(s): yes count is 4, no count is 4
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
12 0 1 12 12 11 10 9 8 7 6 5 4 3 2 1
output:
Yes
result:
ok YES
Test #3:
score: 0
Accepted
time: 4ms
memory: 3552kb
input:
3 0 6685 5 1 3 1 2 2 3 1 2 3 5 3 1 3 3 1 4 1 1 1 3 3 3 2 1 5 2 3 2 1 3 6 2 2 3 2 3 1 5 3 1 2 3 2 3 3 3 2 5 3 2 2 2 3 5 2 2 3 3 1 6 3 3 1 3 1 3 6 2 3 3 2 2 1 5 2 2 3 2 2 6 2 3 3 2 1 3 6 2 2 2 2 1 3 3 3 1 2 4 3 2 1 1 5 3 1 3 2 3 4 3 1 1 2 4 2 2 2 3 3 1 2 2 4 2 3 3 1 3 2 2 2 4 1 2 2 3 3 3 3 3 4 1 3 1 3...
output:
No Yes No No Yes No No No No No No No No No No No Yes No No No No No No Yes No Yes No No No No No No No No No No No No Yes No No No No No No No No Yes No No No No No Yes No Yes No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No Yes No No No No No N...
result:
ok 6685 token(s): yes count is 680, no count is 6005
Test #4:
score: 0
Accepted
time: 3ms
memory: 3616kb
input:
3 1 6654 3 3 1 5 1 2 2 3 3 4 2 1 4 2 4 3 3 2 1 5 4 1 2 1 4 3 1 4 4 6 3 1 2 1 1 4 4 1 2 1 2 5 1 4 3 4 4 4 2 4 4 1 6 3 2 4 2 4 3 3 1 2 1 3 3 2 4 5 4 3 2 1 2 4 3 2 2 1 4 2 1 4 2 4 4 4 2 1 6 2 1 4 2 2 3 4 4 1 2 1 5 2 2 3 3 3 4 2 2 1 4 3 4 3 1 6 4 2 2 4 2 2 6 1 4 1 1 2 2 5 1 4 1 4 3 6 3 2 1 4 1 2 5 2 4 3...
output:
No No No No Yes No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No Yes No No No Yes Yes No No No No Yes No No No No No No No No No No No No No Yes No No No No No Yes No Yes No Yes No Yes Yes No No Yes No Yes ...
result:
ok 6654 token(s): yes count is 768, no count is 5886
Test #5:
score: -100
Wrong Answer
time: 3ms
memory: 3536kb
input:
3 3 6656 2 3 2 1 2 1 2 3 4 5 3 1 2 3 5 5 3 2 2 2 2 6 5 3 1 4 1 1 5 3 1 5 5 4 3 1 3 6 6 6 3 3 1 4 6 4 2 2 3 1 3 6 4 3 3 5 1 4 3 4 1 5 4 4 2 4 5 3 4 3 5 3 6 4 6 4 3 1 6 5 6 1 1 3 6 1 1 3 4 6 3 6 3 2 2 4 1 6 5 6 2 3 2 1 3 5 3 3 6 1 3 1 2 1 6 4 3 1 3 2 4 4 5 6 3 6 5 6 3 1 4 3 6 5 1 2 4 3 6 3 4 3 5 3 5 4...
output:
No No No No No No No Yes No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No Yes No No No No No No No No No Yes No No No No No No No No No No No No No No No No No No No No No No No No No No No No No N...
result:
wrong answer expected NO, found YES [8th token]