QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#437852#8782. Schoolgirlsucup-team1198WA 7ms5728kbC++144.9kb2024-06-09 18:52:152024-06-09 18:52:16

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-09 18:52:16]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:5728kb
  • [2024-06-09 18:52:15]
  • 提交

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();
    vector<int> pos = query[id];
    vector<int> sum(n, 0);
    for (int i = 0; i < r; ++i) {
      --pos[i];
      sum = sum + coord[pos[i]];
    }
    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;
    }
    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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5428kb

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: 2ms
memory: 5508kb

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

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]