답안 #1087430

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087430 2024-09-12T17:21:16 Z juicy 케이크 (CEOI14_cake) C++17
73.3333 / 100
397 ms 16208 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int inf = 1e9;

struct Segtree {
  int n;
  vector<int> s;

  Segtree() = default;

  Segtree(int n): n(n), s(4 * n, inf) {};

  void upd(int i, int x) {
    int id = 1, l = 1, r = n;
    while (l ^ r) {
      int m = (l + r) / 2;
      id *= 2;
      if (i <= m) {
        r = m;
      } else {
        l = m + 1;
        id += 1;
      }
    }
    s[id] = x;
    while (id > 1) {
      id /= 2;
      s[id] = max(s[id * 2], s[id * 2 + 1]);
    }
  }

  int walk(int i, int id, int l, int r) {
    if (l == r) {
      return l;
    }
    int m = (l + r) / 2;
    return s[id * 2] > i ? walk(i, id * 2, l, m) : walk(i, id * 2 + 1, m + 1, r);
  }

  int walk(int i) {
    return walk(i, 1, 1, n);
  }

  int qry(int i) {
    int id = 1, l = 1, r = n, res = 0;
    while (l ^ r) {
      int m = (l + r) / 2;
      id *= 2;
      if (i <= m) {
        r = m;
      } else {
        l = m + 1;
        res = max(res, s[id]);
        id += 1;
      }
    }
    return max(res, s[id]);
  }
};

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  int n, a; cin >> n >> a; --a;
  Segtree lt(n), rt(n);
  deque<int> dq(min(n, 10));
  auto upd = [&](int i, int x) {
    if (i == a) {
      return;
    }
    if (i < a) {
      lt.upd(a - i, x);
    } else {
      rt.upd(i - a, x);
    }
  };
  int N = 2e5, M = 1e6;
  for (int i = 0; i < n; ++i) {
    int x; cin >> x;
    if (x > n - 10) {
      int j = x - max(1, n - 9);
      dq[j] = i;
      upd(i, M + j + 1);
    } else {
      upd(i, x);
    }
  }
  // exit(0);
  int q; cin >> q;
  while (q--) {
    char t; cin >> t;
    if (t == 'E') {
      int i, e; cin >> i >> e; --i;
      auto it = find(dq.begin(), dq.end(), i);
      if (it != dq.end()) {
        dq.erase(it);
      }
      dq.insert(dq.end() - e + 1, i);
      if (dq.size() > 10) {
        int j = dq.front(); dq.pop_front();
        upd(j, ++N);
      }
      for (int i = 0; i < dq.size(); ++i) {
        upd(dq[i], M + i + 1);
      }
    } else {
      int i; cin >> i; --i;
      if (i == a) {
        cout << 0 << "\n";
        continue;
      }
      if (i < a) {
        int m = lt.qry(a - i);
        cout << rt.walk(m) + a - i - 1 << "\n";
      } else {
        int m = rt.qry(i - a);
        cout << i - a + lt.walk(m) - 1 << "\n";
      }
    }
  }
  return 0;
}

Compilation message

cake.cpp: In function 'int main()':
cake.cpp:111:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |       for (int i = 0; i < dq.size(); ++i) {
      |                       ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 7 ms 916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 361 ms 4944 KB Output is correct
2 Correct 270 ms 5204 KB Output is correct
3 Correct 336 ms 5204 KB Output is correct
4 Correct 286 ms 5224 KB Output is correct
5 Correct 366 ms 5712 KB Output is correct
6 Correct 354 ms 6208 KB Output is correct
7 Correct 392 ms 5960 KB Output is correct
8 Correct 308 ms 6228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 5456 KB Output is correct
2 Correct 34 ms 5204 KB Output is correct
3 Correct 31 ms 5348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Incorrect 63 ms 11344 KB Output isn't correct
6 Incorrect 58 ms 11220 KB Output isn't correct
7 Correct 54 ms 11084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 856 KB Output is correct
2 Correct 26 ms 1116 KB Output is correct
3 Correct 55 ms 3112 KB Output is correct
4 Correct 52 ms 3136 KB Output is correct
5 Correct 68 ms 1852 KB Output is correct
6 Correct 103 ms 4616 KB Output is correct
7 Correct 101 ms 2640 KB Output is correct
8 Correct 190 ms 5968 KB Output is correct
9 Incorrect 385 ms 16204 KB Output isn't correct
10 Correct 238 ms 5440 KB Output is correct
11 Correct 273 ms 6480 KB Output is correct
12 Correct 397 ms 14164 KB Output is correct
13 Incorrect 328 ms 16208 KB Output isn't correct