QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#519663#5669. Traveling in Jade Cityucup-team1198#WA 646ms42508kbC++203.3kb2024-08-14 23:21:482024-08-14 23:21:48

Judging History

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

  • [2024-08-14 23:21:48]
  • 评测
  • 测评结果:WA
  • 用时:646ms
  • 内存:42508kb
  • [2024-08-14 23:21:48]
  • 提交

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;

const int INF = 1e9;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  int n, k, m, q;
  cin >> n >> k >> m >> q;
  vector<int> pref[3];
  pref[0].resize(k);
  pref[1].resize(n - k + 2);
  pref[2].resize(m + 2);
  set<int> dead[3];
  for (int i = 1; i <= k - 1; ++i) {
    cin >> pref[0][i];
  }
  for (int j = 0; j < k - 1; ++j)
    pref[0][j + 1] += pref[0][j];
  for (int i = k; i <= n; ++i) {
    cin >> pref[1][n - i + 1];
  }
  for (int j = 0; j < n - k + 1; ++j)
    pref[1][j + 1] += pref[1][j];
  for (int i = 0; i <= m; ++i)
    cin >> pref[2][i + 1];
  for (int j = 0; j < m + 1; ++j)
    pref[2][j + 1] += pref[2][j];

  vector<int> dist(n + m + 1);


  while (q--) {
    char c;
    cin >> c;
    if (c == 'q') {
      int u, v;
      cin >> u >> v;
      vector<pair<pair<int, int>, int>> edges;
      for (int i = 0; i < 3; ++i) {
        if (dead[i].empty())
          edges.emplace_back(make_pair(1, k), pref[i].back());
      }
      auto add_edges = [&](int x) {
        if (x == 1)
          return;
        if (x == k)
          return;
        int id, mx_road;
        if (x >= 2 && x <= k - 1) {
          id = 0;
          mx_road = x - 2;
        } else if (x <= n) {
          id = 1;
          mx_road = n - x;
        } else {
          id = 2;
          mx_road = x - n - 1;
        }
        auto tmp = dead[id].upper_bound(mx_road);
        if (tmp == dead[id].begin())
          edges.emplace_back(make_pair(1, x), pref[id][mx_road + 1]);
        if (tmp == dead[id].end())
          edges.emplace_back(make_pair(x, k), pref[id].back() - pref[id][mx_road + 1]);
      };
      add_edges(u);
      add_edges(v);
      for (auto [ab, w] : edges) {
        auto [a, b] = ab;
      }
      dist[1] = INF;
      dist[k] = INF;
      dist[v] = INF;
      dist[u] = 0;
      set<pair<int, int>> Q;
      Q.emplace(0, u);
      while (!Q.empty()) {
        int x = Q.begin()->second;
        Q.erase(Q.begin());
        for (auto [ab, w] : edges) {
          auto [a, b] = ab;
          if (a == x || b == x) {
            int y = a + b - x;
            if (dist[y] > dist[x] + w) {
              Q.erase(make_pair(dist[y], y));
              dist[y] = dist[x] + w;
              Q.emplace(dist[y], y);
            }
          }
        }
      }
      if (dist[v] == INF)
        cout << "impossible\n";
      else
        cout << dist[v] << '\n';
    } else if (c == 'c') {
      int x;
      cin >> x;
      if (x <= k - 1) {
        --x;
        if (dead[0].count(x))
          dead[0].erase(x);
        else
          dead[0].emplace(x);
      } else {
        x = n - x;
        if (dead[1].count(x))
          dead[1].erase(x);
        else
          dead[1].emplace(x);
      }
    } else {
      int x;
      cin >> x;
      if (dead[2].count(x))
        dead[2].erase(x);
      else
        dead[2].emplace(x);
    }
  }

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

4 3 1 9
2 3 8 4
1 1
q 3 4
x 0
q 3 4
c 3
q 3 4
c 1
q 3 4
x 0
q 3 4

output:

6
8
9
impossible
6

result:

ok 5 lines

Test #2:

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

input:

4 3 1 9
2 3 8 4
1 1
q 3 4
x 0
q 3 4
c 3
q 3 4
c 1
q 3 4
x 0
q 3 4

output:

6
8
9
impossible
6

result:

ok 5 lines

Test #3:

score: -100
Wrong Answer
time: 646ms
memory: 42508kb

input:

1000000 999999 1000000 1000000
200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 2...

output:

177406400
122264600
70328400
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
29295200
impossible
22163200
impossible
impossible
impossible
112881800
impossible
137420800
impossible
35339400
impossible
137782000
impossible
impossible
impossible
impos...

result:

wrong answer 19th lines differ - expected: '11422200', found: '112881800'