QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#676548 | #8782. Schoolgirls | ucup-team5062 | WA | 180ms | 4064kb | C++17 | 3.3kb | 2024-10-25 21:59:42 | 2024-10-25 21:59:43 |
Judging History
answer
#include <random>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
mt19937_64 mt(1);
int64_t MOD;
class modint {
private:
int64_t x;
public:
modint() : x(0) {}
modint(int64_t x_) : x(x_ >= 0 ? x_ % MOD : (x_ + 1) % MOD + (MOD - 1)) {}
int64_t get() const { return x; }
modint& operator+=(const modint& m) { x = (x + m.x) % MOD; return *this; }
modint& operator-=(const modint& m) { x = (x - m.x + MOD) % MOD; return *this; }
modint& operator*=(const modint& m) { x = __int128_t(x) * m.x % MOD; return *this; }
modint operator+(const modint& m) const { return modint(*this) += m; }
modint operator-(const modint& m) const { return modint(*this) -= m; }
modint operator*(const modint& m) const { return modint(*this) *= m; }
modint pow(long long b) const {
modint res(1), a(*this);
while (b) {
if (b & 1) {
res *= a;
}
a *= a;
b >>= 1;
}
return res;
}
modint inv() const {
return pow(MOD - 2);
}
};
bool isprime(long long x) {
if (x <= 1) {
return false;
}
for (int i = 2; 1LL * i * i <= x; i++) {
if (x % i == 0) {
return false;
}
}
return true;
}
string to_string(const vector<int>& arr) {
string res = "[";
for (int i = 0; i < int(arr.size()); i++) {
if (i != 0) {
res += ", ";
}
res += to_string(arr[i]);
}
res += "]";
return res;
}
int main() {
// step #1. input
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, M, Q;
cin >> N >> M >> Q;
vector<int> A(N + M, -1), B(N + M, -1), C(N + M, -1);
for (int i = N; i < N + M; i++) {
cin >> A[i] >> B[i] >> C[i];
A[i]--;
B[i]--;
C[i]--;
}
vector<int> R(Q);
vector<vector<int> > P(Q);
for (int i = 0; i < Q; i++) {
cin >> R[i];
P[i].resize(R[i]);
for (int j = 0; j < R[i]; j++) {
cin >> P[i][j];
P[i][j]--;
}
}
// step #2. decide prime
do {
MOD = 2 * N * (mt() % (1000000000000000 / (2 * N))) + 1;
} while (!isprime(MOD));
// step #3. decide root
vector<int> pdiv;
for (int i = 2; 1LL * i * i <= MOD - 1; i++) {
if ((MOD - 1) % i == 0) {
if (isprime(i)) {
pdiv.push_back(i);
}
if (isprime((MOD - 1) / i)) {
pdiv.push_back((MOD - 1) / i);
}
}
}
sort(pdiv.begin(), pdiv.end());
modint root;
while (true) {
root = mt() % (MOD - 1) + 1;
bool f = true;
for (int i : pdiv) {
if (modint(root).pow((MOD - 1) / i).get() == 1) {
f = false;
break;
}
}
if (f) {
break;
}
}
modint gen = root.pow((MOD - 1) / (2 * N));
// step #4. initialize
vector<modint> h(N + M);
for (int i = 0; i < N; i++) {
h[i] = gen.pow(i * 2);
}
// step #5. simulation
for (int i = N; i < N + M; i++) {
h[i] = h[A[i]] + h[C[i]] - h[B[i]];
}
// step #6. calculation
for (int i = 0; i < Q; i++) {
if ((2 * N) % R[i] != 0) {
cout << "No\n";
} else {
modint center = 0;
for (int j = 0; j < R[i]; j++) {
center += h[P[i][j]];
}
center *= modint(R[i]).inv();
vector<int64_t> q1(R[i]), q2(R[i]);
for (int j = 0; j < R[i]; j++) {
q1[j] = ((h[P[i][0]] - center) * gen.pow((2 * N) / R[i] * j) + center).get();
q2[j] = h[P[i][j]].get();
}
sort(q1.begin(), q1.end());
sort(q2.begin(), q2.end());
cout << (q1 == q2 ? "Yes\n" : "No\n");
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 141ms
memory: 3624kb
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: 180ms
memory: 3760kb
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: -100
Wrong Answer
time: 140ms
memory: 4064kb
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:
wrong answer expected YES, found NO [107th token]