QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#437862 | #8782. Schoolgirls | ucup-team1198 | WA | 13ms | 7188kb | C++14 | 5.2kb | 2024-06-09 18:58:55 | 2024-06-09 18:58:56 |
Judging History
answer
#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int P;
int reduce(int x) {
x %= P;
if (x < 0) return x + P;
return x;
}
int add(int a, int b) {
return reduce(a - P + b);
}
int sub(int a, int b) {
return reduce(a - b);
}
int mul(int a, int b) {
return (1ll * a * b) % P;
}
int pw(int x, int n) {
int res = 1;
while (n) {
if (n % 2 == 0) {
x = mul(x, x);
n /= 2;
} else {
res = mul(res, x);
--n;
}
}
return res;
}
int XI;
vector<int> operator+(vector<int> a, const vector<int>& b) {
for (int i = 0; i < (int)a.size(); ++i) {
a[i] = add(a[i], b[i]);
}
return a;
}
vector<int> operator-(vector<int> a, const vector<int>& b) {
for (int i = 0; i < (int)a.size(); ++i) {
a[i] = sub(a[i], b[i]);
}
return a;
}
vector<int> operator*(vector<int> a, const vector<int>& b) {
for (int i = 0; i < (int)a.size(); ++i) {
a[i] = mul(a[i], b[i]);
}
return a;
}
vector<int> operator*(vector<int> a, int n) {
for (int& x : a) {
x = mul(n, x);
}
return a;
}
const int MAXN = 4e4 + 100;
vector<int> coord[MAXN];
const int B = 5757, HMOD2 = 1e9 + 1000 - 7;
/**int hsh(const vector<int>& a) {
int res = 0;
for (int x : a) {
res = (1ll * res * B + x) % HMOD2;
}
return res;
}*/
const int START = 2e9;
vector<int> query[MAXN];
array<int, 3> pts[MAXN];
vector<int> pw(vector<int> x, int n) {
vector<int> res(x.size(), 1);
while (n) {
if (n % 2 == 0) {
x = x * x;
n /= 2;
} else {
res = res * x;
--n;
}
}
return res;
}
vector<bool> solve(int n, int m, int k, int start) {
for (int i = (start + n - 1) / n * n + 1;; i += n) {
bool f = true;
for (int x = 2; x * x <= i && f; ++x) {
f &= (i % x != 0);
}
if (f) {
P = i;
break;
}
}
int p1 = P - 1;
vector<int> prm;
for (int i = 2; i * i <= p1; ++i) {
if (p1 % i == 0) {
prm.push_back(i);
while (p1 % i == 0) p1 /= i;
}
}
if (p1 != 1) {
prm.push_back(p1);
}
for (int g = 2;; ++g) {
bool f = true;
for (int q : prm) {
if (pw(g, (P - 1) / q) == 1) {
f = false;
break;
}
}
if (f) {
XI = pw(g, (P - 1) / n); /// nth root of unity
break;
}
}
vector<int> x(n);
x[0] = 1;
for (int i = 1; i < n; ++i) {
x[i] = mul(x[i - 1], XI);
assert(x[i] != 1);
}
assert(mul(x.back(), XI) == 1);
coord[0] = vector<int>(n, 1);
for (int i = 1; i < n; ++i) {
coord[i] = coord[i - 1] * x;
}
for (int i = 0; i < m; ++i) {
int a, b, c;
a = pts[i][0]; b = pts[i][1]; c = pts[i][2];
--a; --b; --c;
coord[i + n] = coord[a] + coord[c] - coord[b];
}
vector<bool> ans(k);
for (int id = 0; id < k; ++id) {
int r = query[id].size();
assert(r >= 3);
vector<int> pos = query[id];
vector<int> sum(n, 0);
for (int i = 0; i < r; ++i) {
--pos[i];
sum = sum + coord[pos[i]];
}
bool all_same = true;
for (int i = 1; i < r; ++i) {
all_same &= (coord[pos[i]] == coord[pos[0]]);
}
if (all_same) {
ans[id] = true;
continue;
}
vector<int> cur_rot;
if (n % r == 0) {
cur_rot = coord[n / r];
} else if (n % 2 == 1 && (2 * n) % r == 0) {
cur_rot = vector<int>(n, 0) - coord[(n + 1) / 2];
int val = 2 * n / r;
val = (val - 1) / 2;
cur_rot = cur_rot * coord[val];
} else {
ans[id] = 0;
continue;
}
if (n == 4) assert(r == 4);
assert(pw(cur_rot, r) == vector<int>(n, 1));
vector<vector<int>> check, rot;
for (int i = 0; i < r; ++i) {
vector<int> cur = (coord[pos[i]] * r - sum);
check.push_back(cur);
cur = cur * cur_rot;
rot.push_back(cur);
}
sort(check.begin(), check.end());
sort(rot.begin(), rot.end());
if (check == rot) {
ans[id] = 1;
} else {
ans[id] = 0;
}
}
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i < m; ++i) {
cin >> pts[i][0] >> pts[i][1] >> pts[i][2];
}
for (int i = 0; i < k; ++i) {
int r;
cin >> r;
query[i].resize(r);
for (int& x : query[i]) {
cin >> x;
}
}
vector<int> starts;
/**for (int i = 1; i <= 20; ++i) {
starts.push_back(i * 50'000'000);
}*/
starts.push_back(1'000'000'000);
vector<bool> ans(k, 1);
for (int s : starts) {
auto res = solve(n, m, k, s);
for (int i = 0; i < k; ++i) {
ans[i] = ans[i] & res[i];
}
}
for (int i = 0; i < k; ++i) {
if (ans[i]) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 5520kb
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: 1ms
memory: 5752kb
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: 6ms
memory: 5968kb
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: 6ms
memory: 5732kb
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: 0
Accepted
time: 6ms
memory: 5676kb
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 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 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 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 No No No No No No ...
result:
ok 6656 token(s): yes count is 100, no count is 6556
Test #6:
score: 0
Accepted
time: 6ms
memory: 5772kb
input:
3 7 6638 1 2 1 3 1 2 4 3 2 6 1 5 3 1 5 5 2 1 7 3 8 5 7 2 9 10 7 5 1 4 1 4 6 3 5 4 1 3 1 2 8 4 9 8 1 7 4 4 4 2 7 4 2 2 3 9 4 2 5 6 9 4 5 3 3 1 3 1 3 4 4 2 8 4 5 3 9 6 10 6 2 8 4 4 6 7 3 5 3 6 3 5 8 6 4 3 2 2 1 4 9 2 5 2 6 9 6 5 4 8 9 6 9 7 5 9 5 3 3 5 6 2 6 8 4 3 8 1 8 4 7 8 8 7 4 10 3 5 10 6 7 7 2 1...
output:
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 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 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 N...
result:
ok 6638 token(s): yes count is 144, no count is 6494
Test #7:
score: 0
Accepted
time: 6ms
memory: 5676kb
input:
3 15 6655 2 3 1 3 4 1 2 3 4 6 2 3 6 1 2 4 1 6 8 8 1 1 5 4 4 9 6 6 1 5 12 11 7 12 3 12 8 10 1 7 10 4 10 17 12 4 12 8 10 4 6 14 16 15 9 1 12 5 10 16 18 3 10 6 2 11 9 11 2 2 4 1 8 1 13 4 12 13 12 7 5 16 12 5 18 8 5 14 13 13 12 3 5 3 6 18 5 16 4 1 16 17 16 3 10 10 10 6 17 8 16 14 11 14 3 5 3 13 3 13 9 1...
output:
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 Yes No No No No No No No No No No No No No No No No No No No Yes 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 No No No No No No No No No No N...
result:
ok 6655 token(s): yes count is 92, no count is 6563
Test #8:
score: 0
Accepted
time: 13ms
memory: 7188kb
input:
3 30000 6650 1 2 1 4 3 4 3 5 5 3 2 3 6 4 7 2 1 6 7 8 1 5 3 6 1 2 10 11 1 1 8 6 12 7 1 3 11 13 12 7 6 15 10 7 13 1 6 7 13 1 1 19 3 18 4 21 15 3 18 22 19 16 18 16 24 18 19 20 7 21 9 17 27 20 3 21 13 7 22 1 27 2 11 20 31 28 4 15 29 2 22 1 12 19 29 9 6 28 30 23 18 27 2 2 5 37 10 20 25 4 27 32 29 33 41 3...
output:
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 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 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 No No No No No No No No No No No No No ...
result:
ok 6650 token(s): yes count is 0, no count is 6650
Test #9:
score: 0
Accepted
time: 4ms
memory: 5964kb
input:
4 0 5533 3 3 3 2 8 2 3 1 3 4 1 3 4 8 4 2 3 4 3 4 3 2 7 4 4 4 4 4 1 2 5 1 1 4 1 2 3 3 2 1 5 2 1 1 1 2 6 2 3 2 3 4 4 6 4 4 3 2 3 1 4 2 2 1 1 5 2 1 4 1 4 3 4 1 2 3 2 3 3 5 4 2 3 2 1 8 4 2 1 3 2 1 3 4 4 2 2 4 4 4 1 2 3 2 3 3 3 4 7 3 3 2 4 1 3 2 3 2 1 3 6 2 1 2 1 1 2 4 3 4 2 1 6 2 2 1 2 3 4 8 4 4 4 1 2 1...
output:
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 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 No No No No No No No No No No No ...
result:
ok 5533 token(s): yes count is 162, no count is 5371
Test #10:
score: 0
Accepted
time: 4ms
memory: 5968kb
input:
4 1 5458 3 4 4 8 5 3 3 1 4 3 2 4 3 4 2 5 4 2 2 4 1 4 1 1 5 4 5 2 5 5 5 3 4 4 2 4 1 4 5 5 1 4 6 2 5 1 3 2 2 5 3 2 2 1 4 5 1 2 5 2 3 3 1 5 3 5 5 1 5 1 2 4 3 2 1 3 4 2 5 1 2 3 3 2 5 5 3 3 1 1 4 3 3 5 4 4 5 1 2 5 8 5 3 4 5 5 1 3 5 3 5 5 4 8 5 5 2 3 5 1 2 3 4 3 2 2 3 8 1 4 2 5 5 3 1 3 6 2 2 5 4 5 3 8 5 5...
output:
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 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 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 ...
result:
ok 5458 token(s): yes count is 194, no count is 5264
Test #11:
score: 0
Accepted
time: 4ms
memory: 5708kb
input:
4 3 5462 3 4 2 3 4 2 3 4 2 7 7 3 3 7 5 2 1 6 4 1 5 3 2 4 8 5 2 3 7 4 3 6 7 4 1 4 6 5 8 3 2 6 1 7 6 1 3 4 7 5 3 4 6 7 1 7 1 2 3 8 6 2 7 7 7 2 3 3 7 2 3 7 6 3 5 7 5 2 4 5 4 3 5 7 2 2 2 1 5 4 5 5 3 1 3 1 6 3 7 7 5 4 2 6 5 1 6 6 2 4 1 6 1 3 4 3 5 4 3 5 2 7 7 4 4 7 3 7 7 1 5 7 5 3 6 6 4 7 5 3 4 6 1 3 1 6...
output:
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 No No No No No No No No No No No Yes 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 No No No No No No No No No No No No ...
result:
ok 5462 token(s): yes count is 149, no count is 5313
Test #12:
score: -100
Wrong Answer
time: 4ms
memory: 5668kb
input:
4 7 5463 4 2 1 1 3 1 5 5 2 2 1 1 3 2 2 4 1 7 10 9 7 6 2 11 2 10 6 1 4 11 4 4 3 3 5 5 3 4 7 7 10 8 5 9 7 11 9 5 4 11 8 1 6 5 5 9 1 6 6 5 2 11 7 8 1 3 5 8 8 7 9 6 10 9 10 3 3 6 5 1 9 6 3 7 4 5 1 7 9 5 8 9 6 11 2 3 6 6 3 3 11 8 3 4 7 2 6 4 7 4 5 8 6 11 10 3 5 11 1 4 8 10 6 1 3 10 4 6 3 8 9 5 11 2 11 1 ...
output:
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 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 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 No No No No No No No No No No...
result:
wrong answer expected YES, found NO [57th token]