QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#436212#8782. SchoolgirlsForever_Young#WA 261ms20056kbC++174.1kb2024-06-08 23:39:182024-06-08 23:39:18

Judging History

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

  • [2024-06-14 13:48:47]
  • hack成功,自动添加数据
  • (/hack/679)
  • [2024-06-14 13:05:18]
  • hack成功,自动添加数据
  • (/hack/678)
  • [2024-06-14 12:22:35]
  • hack成功,自动添加数据
  • (/hack/676)
  • [2024-06-08 23:39:18]
  • 评测
  • 测评结果:WA
  • 用时:261ms
  • 内存:20056kb
  • [2024-06-08 23:39:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) ((x).begin()), ((x).end())
typedef long long LL;
inline LL fastpo(LL x, LL n, LL mod) {
    LL res(1);
    while(n) {
        if(n & 1) {
            res = res * (LL)x % mod;
        }
        x = x * (LL) x % mod;
        n /= 2;
    }
    return res;
}
const int inf = 1e9 + 7;
const int L = 9999999;
const int N = 10000111;
bool f[N];
int np = 0;
int p[N / 10];
const int M = 53333;
int a[M], b[M], c[M], h[M];
bool answer[M];
vector<int> q[M];
int powmod (int a, int b, int p) {
    int res = 1;
    while (b)
        if (b & 1)
            res = int (res * 1ll * a % p),  --b;
        else
            a = int (a * 1ll * a % p),  b >>= 1;
    return res;
}

int findpr (int p) {
    vector<int> fact;
    int phi = p-1,  n = phi;
    for (int i=2; i*i<=n; ++i)
        if (n % i == 0) {
            fact.push_back (i);
            while (n % i == 0)
                n /= i;
        }
    if (n > 1)
        fact.push_back (n);

    for (int res=2; res<=p; ++res) {
        bool ok = true;
        for (size_t i=0; i<fact.size() && ok; ++i)
            ok &= powmod (res, phi / fact[i], p) != 1;
        if (ok)  return res;
    }
    return -1;
}
int main() {
    fill(f + 2, f + L + 1, true);
    p[0] = inf;
    for(int i = 2; i <= L; i++) {
        if(f[i]) {
             p[++np] = i;
        }
        for(int j = 1; j <= np && p[j] * i <= L && i % p[j - 1]; j++) {
            f[i * p[j]] = 0;
        }
    }
    int n, m, k;
    scanf("%d%d%d", &n, &m, &k);
    for(int i = 1; i <= m; i++) {
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
    }
    for(int i = 1; i <= k; i++) {
        int r;
        scanf("%d", &r);
        for(int j = 0; j < r; j++) {
            int x;
            scanf("%d", &x);
            q[i].pb(x);
        }
        answer[i] = true;
    }
    int mod = -1;
    
    int cc = 0;
    for(int i = 1; i * n + 1 <= L; i++) {
        if(i * n + 1 >= 50000 && f[i * n + 1]) {
            mod = i * n + 1;
        } else {
            continue;
        }
        cc++;
        if(cc == 101) {
            break;
        }
        int pr = findpr(mod);
        // printf("%d %d\n", pr, mod);
        for(int i = 1; i <= 1; i++) {
            
            int pp = fastpo(pr, i, mod);
            int g = fastpo(pp, (mod - 1) / n, mod);
            // printf("g = %d %d\n", g, fastpo(g, n, mod));
            for(int i = 1; i <= n; i++) {
                h[i] = i == 1 ? 1 : (LL)h[i - 1] * g % mod;
            }
            for(int j = 1; j <= m; j++) {
                h[n + j] = ((LL)h[c[j]] + h[a[j]] - h[b[j]] + mod) % mod;
            }
            // for(int i = 1; i <= n + m; i++) {
            //     printf("%d ", h[i]);
            // }
            // printf("\n");
            for(int j = 1; j <= k; j++) {
                int r = q[j].size();
                set<int> st;
                int sum = 0;
                vector<int> xs;
                // printf("j = %d\n", j);
                for(int id : q[j]) {
                    int x = h[id];
                    xs.pb(x);
                    sum = (sum + x) % mod;
                    // if(j == 3) {
                    //     printf("%d %d %d\n", id, x, int((LL)x * g % mod));
                    // }
                }
                sum = (LL)sum * fastpo(r, mod - 2, mod) % mod;
                for(int x : xs) {
                    st.insert((x - sum + mod) % mod);
                }
                bool flag = true;
                for(int x : xs) {
                    int y = (LL)(x - sum + mod) * g % mod;
                    if(st.count(y) == 0) {
                        flag = false;
                        break;
                    }
                }
                if(st.size() != r && st.size() != 1) {
                    flag = false;
                }
                if(!flag) {
                    answer[j] = false;
                }
            }
        }
    }

    
    for(int i = 1; i <= k; i++) {
        printf("%s\n", answer[i] ? "Yes" : "No");
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 39ms
memory: 19544kb

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: 36ms
memory: 19804kb

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: 238ms
memory: 19804kb

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: 233ms
memory: 19348kb

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: 259ms
memory: 19320kb

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: 261ms
memory: 19100kb

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: -100
Wrong Answer
time: 259ms
memory: 20056kb

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:

wrong answer expected NO, found YES [797th token]