QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#806011#9810. Obliviate, Then Reincarnateucup-team3691WA 297ms65800kbC++143.5kb2024-12-08 20:27:502024-12-08 20:27:50

Judging History

This is the latest submission verdict.

  • [2024-12-08 20:27:50]
  • Judged
  • Verdict: WA
  • Time: 297ms
  • Memory: 65800kb
  • [2024-12-08 20:27:50]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

using ll = long long;
using ull = unsigned long long;

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(bool b) {
  return b ? "true" : "false";
}

template <typename A, typename B>
string to_string(const pair<A, B> &p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename T>
string to_string(const T &v) {
  string s = "{";
  bool first = true;
  for (const auto &it : v) {
    if (!first)
      s += ", ";
    else
      first = false;
    s += to_string(it);
  }
  return s += "}";
}

void debug_out() {
  cerr << endl;
}

template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
  cerr << to_string(first) << " ";
  debug_out(rest...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

auto startTime = high_resolution_clock::now();
int get_time() {
  auto stopTime = chrono::high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(stopTime - startTime);
  return duration.count(); // in ms
}

const int DIM = 5e5 + 5;
const ll INF = 1e18;

bool cyc[DIM];
int viz[DIM];
int nr;
int low[DIM], lim[DIM];
int wh[DIM];
vector<pair<int, int>> v[DIM];
vector<pair<int, int>> vt[DIM];
vector<vector<int>> ctc;
stack<int> st;

void dfs(int nod) {
  viz[nod] = 1;
  low[nod] = lim[nod] = ++nr;
  st.push(nod);

  for (auto it : v[nod]) {
    if (!viz[it.first]) {
      dfs(it.first);
      low[nod] = min(low[nod], low[it.first]);
    } else {
      low[nod] = min(low[nod], lim[it.first]);
    }
  }

  if (low[nod] == lim[nod]) {
    ctc.emplace_back();
    int x;
    do {
      x = st.top();
      st.pop();

      viz[x] = 2;
      wh[x] = ctc.size();
      ctc.back().push_back(x);
    } while (x != nod);
  }
}

void dfs2(int nod) {
  viz[nod] = 3;
  for (auto it : v[nod]) {
    if (viz[it.first] < 3) {
      dfs2(it.first);
    }
    cyc[nod] |= cyc[it.first];
  }
  viz[nod] = 4;
}

int f[DIM];
ll sum[DIM];

bool dfs3(int nod) {
  f[nod] = 1;
  for (auto it : vt[nod]) {
    if (wh[it.first] != wh[nod])
      continue;

    if (f[it.first]) {
      if (sum[it.first] != sum[nod] + it.second)
        return true;
    } else {
      sum[it.first] = sum[nod] + it.second;
      bool r = dfs3(it.first);
      if (r)
        return true;
    }
  }

  f[nod] = 2;
  return false;
}

void solve() {
  int n, m, q;
  cin >> n >> m >> q;

  for (int i = 1; i <= m; ++i) {
    int a, b, x, y;
    cin >> a >> b;
    if (b == 0)
      continue;
    x = (a % n + n) % n;
    y = ((a + b) % n + n) % n;

    v[x].push_back({y, b});
    vt[x].push_back({y, b});
    vt[y].push_back({x, -b});
  }

  for (int i = 0; i < n; ++i) {
    if (!viz[i]) {
      dfs(i);
    }
  }

  for (auto &c : ctc) {
    if (dfs3(c[0])) {
      for (auto nod : c) {
        cyc[nod] = 1;
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    if (viz[i] < 3)
      dfs2(i);
  }

  for (int i = 1; i <= q; ++i) {
    int x;
    cin >> x;
    x = (x % n + n) % n;
    if (cyc[x]) {
      cout << "Yes\n";
    } else {
      cout << "No\n";
    }
  }
}

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  int t = 1;
//  cin >> t;
  while (t--)
    solve();

  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 34352kb

input:

3 2 3
1 1
-1 3
1
2
3

output:

Yes
Yes
No

result:

ok 3 tokens

Test #2:

score: 0
Accepted
time: 4ms
memory: 34536kb

input:

3 2 3
1 1
-1 0
1
2
3

output:

No
No
No

result:

ok 3 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 34544kb

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

score: 0
Accepted
time: 0ms
memory: 34372kb

input:

3 2 3
0 1000000000
1 -1000000000
-1000000000
0
-1000000000

output:

No
No
No

result:

ok 3 tokens

Test #5:

score: 0
Accepted
time: 263ms
memory: 60064kb

input:

50134 500000 500000
-154428638 -283522863
-186373509 -327130969
154999046 46750274
-933523447 349415487
-437683609 140099255
864996699 -262318199
811293034 -264299324
120273173 52410685
874944410 -52048424
445049930 -803690605
-138111276 -104634331
720288580 126597671
471164416 -348777147
-356502322...

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 500000 tokens

Test #6:

score: -100
Wrong Answer
time: 297ms
memory: 65800kb

input:

100848 500000 500000
720352587 361776806
231853504 -933882325
960971230 -83519300
-152772415 -631132247
842871215 -666621297
857194330 -754943024
-698506963 -705416545
-3551931 -927937446
628710320 -942247987
674921043 847145884
-325629529 475694308
-339363446 686789318
236702996 654762989
420412365...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Y...

result:

wrong answer 619th words differ - expected: 'No', found: 'Yes'