답안 #1067360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067360 2024-08-20T15:34:11 Z juicy Sushi (JOI16_sushi) C++17
100 / 100
2145 ms 83284 KB
#include <bits/stdc++.h>

using namespace std;

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

const int N = 4e5 + 5, B = 635;

int n, q;
int a[N], blk[N], L[B], R[B];
priority_queue<int> pq[B];
priority_queue<int, vector<int>, greater<int>> lz[B];

void fix(int id) {
  for (int i = L[id]; i <= R[id]; ++i) {
    if (lz[id].size() && lz[id].top() < a[i]) {
      lz[id].push(a[i]); 
      a[i] = lz[id].top(); lz[id].pop();
    }
  }
  priority_queue<int>().swap(pq[id]);
  priority_queue<int, vector<int>, greater<int>>().swap(lz[id]);
}

void bld(int id) {
  for (int i = L[id]; i <= R[id]; ++i) {
    pq[id].push(a[i]);
  }
}

void upd(int l, int r, int &p) {
  if (blk[l] == blk[r]) {
    fix(blk[l]);
    for (int i = l; i <= r; ++i) {
      if (p < a[i]) {
        swap(p, a[i]);
      }
    }
    bld(blk[l]);
  } else {
    fix(blk[l]);
    for (int i = l; i <= R[blk[l]]; ++i) {
      if (p < a[i]) {
        swap(p, a[i]);
      }
    }
    bld(blk[l]);
    for (int i = blk[l] + 1; i < blk[r]; ++i) {
      if (p < pq[i].top()) {
        pq[i].push(p); lz[i].push(p);
        p = pq[i].top(); pq[i].pop();
      }
    }
    fix(blk[r]);
    for (int i = L[blk[r]]; i <= r; ++i) {
      if (p < a[i]) {
        swap(p, a[i]);
      }
    }
    bld(blk[r]);
  }
}

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

  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    blk[i] = i / B;
    R[blk[i]] = i;
    pq[blk[i]].push(a[i]);
  }
  for (int i = n; i; --i) {
    L[blk[i]] = i;
  }
  while (q--) {
    int s, t, p; cin >> s >> t >> p;
    if (s <= t) {
      upd(s, t, p);
    } else {
      upd(s, n, p);
      upd(1, t, p);
    }
    cout << p << "\n";
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2396 KB Output is correct
2 Correct 15 ms 2660 KB Output is correct
3 Correct 15 ms 2652 KB Output is correct
4 Correct 15 ms 2652 KB Output is correct
5 Correct 16 ms 2636 KB Output is correct
6 Correct 16 ms 2396 KB Output is correct
7 Correct 12 ms 2624 KB Output is correct
8 Correct 12 ms 2396 KB Output is correct
9 Correct 16 ms 2648 KB Output is correct
10 Correct 19 ms 2652 KB Output is correct
11 Correct 26 ms 2656 KB Output is correct
12 Correct 26 ms 2648 KB Output is correct
13 Correct 32 ms 2652 KB Output is correct
14 Correct 21 ms 2652 KB Output is correct
15 Correct 20 ms 2648 KB Output is correct
16 Correct 7 ms 2648 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2560 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1606 ms 79488 KB Output is correct
2 Correct 1666 ms 79952 KB Output is correct
3 Correct 160 ms 6228 KB Output is correct
4 Correct 1689 ms 79908 KB Output is correct
5 Correct 1602 ms 78676 KB Output is correct
6 Correct 1917 ms 78876 KB Output is correct
7 Correct 1908 ms 78648 KB Output is correct
8 Correct 1888 ms 78672 KB Output is correct
9 Correct 155 ms 6228 KB Output is correct
10 Correct 1543 ms 74324 KB Output is correct
11 Correct 155 ms 5976 KB Output is correct
12 Correct 1519 ms 75600 KB Output is correct
13 Correct 1600 ms 79696 KB Output is correct
14 Correct 1691 ms 79700 KB Output is correct
15 Correct 171 ms 6224 KB Output is correct
16 Correct 1616 ms 79700 KB Output is correct
17 Correct 1610 ms 78664 KB Output is correct
18 Correct 1877 ms 78676 KB Output is correct
19 Correct 1884 ms 78660 KB Output is correct
20 Correct 1898 ms 78848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 2396 KB Output is correct
2 Correct 15 ms 2660 KB Output is correct
3 Correct 15 ms 2652 KB Output is correct
4 Correct 15 ms 2652 KB Output is correct
5 Correct 16 ms 2636 KB Output is correct
6 Correct 16 ms 2396 KB Output is correct
7 Correct 12 ms 2624 KB Output is correct
8 Correct 12 ms 2396 KB Output is correct
9 Correct 16 ms 2648 KB Output is correct
10 Correct 19 ms 2652 KB Output is correct
11 Correct 26 ms 2656 KB Output is correct
12 Correct 26 ms 2648 KB Output is correct
13 Correct 32 ms 2652 KB Output is correct
14 Correct 21 ms 2652 KB Output is correct
15 Correct 20 ms 2648 KB Output is correct
16 Correct 7 ms 2648 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2560 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1606 ms 79488 KB Output is correct
24 Correct 1666 ms 79952 KB Output is correct
25 Correct 160 ms 6228 KB Output is correct
26 Correct 1689 ms 79908 KB Output is correct
27 Correct 1602 ms 78676 KB Output is correct
28 Correct 1917 ms 78876 KB Output is correct
29 Correct 1908 ms 78648 KB Output is correct
30 Correct 1888 ms 78672 KB Output is correct
31 Correct 155 ms 6228 KB Output is correct
32 Correct 1543 ms 74324 KB Output is correct
33 Correct 155 ms 5976 KB Output is correct
34 Correct 1519 ms 75600 KB Output is correct
35 Correct 1600 ms 79696 KB Output is correct
36 Correct 1691 ms 79700 KB Output is correct
37 Correct 171 ms 6224 KB Output is correct
38 Correct 1616 ms 79700 KB Output is correct
39 Correct 1610 ms 78664 KB Output is correct
40 Correct 1877 ms 78676 KB Output is correct
41 Correct 1884 ms 78660 KB Output is correct
42 Correct 1898 ms 78848 KB Output is correct
43 Correct 691 ms 10836 KB Output is correct
44 Correct 702 ms 10832 KB Output is correct
45 Correct 381 ms 7344 KB Output is correct
46 Correct 680 ms 10980 KB Output is correct
47 Correct 705 ms 10796 KB Output is correct
48 Correct 1768 ms 11348 KB Output is correct
49 Correct 2017 ms 11420 KB Output is correct
50 Correct 1989 ms 11416 KB Output is correct
51 Correct 2001 ms 11348 KB Output is correct
52 Correct 680 ms 11092 KB Output is correct
53 Correct 667 ms 11088 KB Output is correct
54 Correct 1863 ms 12076 KB Output is correct
55 Correct 2115 ms 12016 KB Output is correct
56 Correct 2145 ms 12184 KB Output is correct
57 Correct 2113 ms 12252 KB Output is correct
58 Correct 1533 ms 12116 KB Output is correct
59 Correct 1537 ms 12304 KB Output is correct
60 Correct 1627 ms 83284 KB Output is correct
61 Correct 1911 ms 83160 KB Output is correct
62 Correct 1908 ms 83244 KB Output is correct
63 Correct 1831 ms 83284 KB Output is correct
64 Correct 234 ms 7252 KB Output is correct
65 Correct 794 ms 44436 KB Output is correct
66 Correct 766 ms 45140 KB Output is correct
67 Correct 1397 ms 38640 KB Output is correct
68 Correct 1575 ms 38692 KB Output is correct
69 Correct 1615 ms 38784 KB Output is correct
70 Correct 1546 ms 38692 KB Output is correct