QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#89510#5669. Traveling in Jade Cityphtniit#WA 1485ms206792kbC++113.3kb2023-03-20 11:47:112023-03-20 11:47:15

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-20 11:47:15]
  • 评测
  • 测评结果:WA
  • 用时:1485ms
  • 内存:206792kb
  • [2023-03-20 11:47:11]
  • 提交

answer

#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast","-funroll-loops")
//#pragma GCC target("sse4.1","sse4.2","ssse3","sse3","sse2","sse","avx2","avx","popcnt","tune=native")

using namespace std;

typedef long double ldb;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef pair<int, int> pii;

// priority_queue<int, vector<int>, greater<int>> minq;
// ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// fflush(stdout);

const int inf = 1000000007;
const i64 prm = 998244353;
const i64 inf2 = ((i64)inf) * inf;
const i64 bone = 1;
const int maxn = 2000010;

inline int read(){
  int x=0,f=0; char ch=getchar();
  while(!isdigit(ch)) f|=(ch==45),ch=getchar();
  while(isdigit(ch)) x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
  return f?-x:x;
}

struct S {
  i64 c[maxn];
  i64 tot;
  int sz;
  void up(int k, int w) {
    for (int i = k; i <= sz; i += i&-i) {
      c[i] += w;
    }
    tot += w;
  }
  i64 sum(int k) {
    i64 res = 0;
    for (int i = k; i > 0; i -= i&-i) {
      res += c[i];
    }
    return res;
  }
  i64 query(int u, int v) {
    if (u == v) {
      return 0;
    }
    if (u > v) {
      swap(u, v);
    }
    i64 ans = sum(v-1) - sum(u-1);
    return min(ans, tot-ans);
  }
} s[3];

int a[maxn][2], b[maxn][2];
vector<pii> A[maxn];
vector<pii> B[maxn];

int main() {
  int n = read(), k = read(), m = read(), q = read();

  s[0].tot = 0;
  s[0].sz = n;

  s[1].tot = 0;
  s[1].sz = k-1 + m+1;

  s[2].tot = 0;
  s[2].sz = n+1-k + m+1;

  for (int i = 1; i <= n; ++i) {
    a[i][0] = read();
    a[i][1] = inf;
    A[i].emplace_back(0, i);
    if (i < k) {
      A[i].emplace_back(1, i);
    } else {
      A[i].emplace_back(2, i+1-k + m+1);
    }
    for (auto e: A[i]) {
      s[e.first].up(e.second, a[i][0]);
    }
  }
  for (int i = 0; i <= m; ++i) {
    b[i][0] = read();
    b[i][1] = inf;
    B[i].emplace_back(1, m-i + k);
    B[i].emplace_back(2, i+1);// + n+1-k);
    for (auto e: B[i]) {
      s[e.first].up(e.second, b[i][0]);
    }
  }

  auto getvt = [&](int u) {
    vector<pii> vt;
    if (u == 1) {
      vt = A[1];
      for (auto e: B[0]) {
        vt.emplace_back(e);
      }
    }
    else if (u <= n) {
      vt = A[u];
    } else {
      vt = B[u - n];
    }
    return vt;
  };

  auto gao = [&](int u, int v) {
    int ans = inf;
    auto vtu = getvt(u), vtv = getvt(v);
    for (auto e1: vtu) {
      for (auto e2: vtv) if (e1.first == e2.first) {
        i64 res = s[e1.first].query(e1.second, e2.second);
        if (res < ans) {
          ans = res;
        }
      }
    }
    return ans;
  };

  while (q--) {
    static char t[12];
    scanf("%s", t);
    if (t[0] == 'c') {
      int i = read();
      for (auto e: A[i]) {
        s[e.first].up(e.second, a[i][1]-a[i][0]);
      }
      swap(a[i][0], a[i][1]);
    } else if (t[0] == 'x') {
      int j = read();
      for (auto e: B[j]) {
        s[e.first].up(e.second, b[j][1]-b[j][0]);
      }
      swap(b[j][0], b[j][1]);
    } else {
      int u = read(), v = read();
      int ans = gao(u, v);
      ans = min(gao(u, 1) + gao(1, v), ans);
      ans = min(gao(u, k) + gao(k, v), ans);
      if (ans >= inf) {
        puts("impossible");
      } else {
        printf("%d\n", ans);
      }
    }
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 31ms
memory: 97444kb

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

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

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
122264400
70328400
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
impossible
29295200
impossible
22163200
impossible
impossible
impossible
11422200
impossible
62579800
impossible
35339400
impossible
20157200
impossible
impossible
impossible
impossib...

result:

wrong answer 2nd lines differ - expected: '122264600', found: '122264400'