Submission #1027705

# Submission time Handle Problem Language Result Execution time Memory
1027705 2024-07-19T09:21:54 Z 우민규(#10951) Sushi (JOI16_sushi) C++17
5 / 100
688 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'

const int bucket = 1;

int n, q;

struct Segment {
  vector<int> arr;
  priority_queue<int> in_arr;
  vector<int> queued;
  int push(int x) {
    queued.push_back(x);
    in_arr.push(x);
    auto out = in_arr.top();
    in_arr.pop();
    return out;
  }
  void apply() {
    // rebuild arr, clear queued, don't modify in_arr

    priority_queue<int, vector<int>, greater<int>> in_queue;
    for (auto q : queued) in_queue.push(q);
    for (auto& a : arr) {
      in_queue.push(a);
      a = in_queue.top();
      in_queue.pop();
    }
    queued.clear();
  }
  void build() {
    while (!in_arr.empty()) in_arr.pop();
    for (auto a : arr) in_arr.push(a);
  }
};

void solve() {
  cin >> n >> q;
  vector<Segment> segments((n + bucket - 1) / bucket);
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    segments[i / bucket].arr.push_back(x);
  }
  for (auto& s : segments) s.build();
  auto query_naive = [&](int l, int r, int b, int p) {
    segments[b].apply();
    for (int i = l; i < r; ++i) {
      if (p < segments[b].arr[i]) {
        swap(p, segments[b].arr[i]);
      }
    }
    segments[b].build();
    return p;
  };
  auto query = [&](int s, int t, int p) {
    int sb = s / bucket, tb = (t - 1) / bucket;
    if (sb == tb) {
      return query_naive(s - sb * bucket, t - sb * bucket, sb, p);
    }
    p = query_naive(s - sb * bucket, bucket, sb, p);
    for (int i = sb + 1; i < tb; ++i) {
      p = segments[i].push(p);
    }
    return query_naive(0, t - tb * bucket, tb, p);
  };
  for (int i = 0; i < q; ++i) {
    if (i == 3) {
      int x = 3;
    }
    int s, t, p;
    cin >> s >> t >> p;
    s -= 1;
    // s -> t-1
    if (s >= t) {
      // s -> N-1, 0 -> t
      p = query(s, n, p);
      s = 0;
    }
    cout << query(s, t, p) << "\n";
  }
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;

  while (t--) {
    solve();
  }
  return 0;
}

Compilation message

sushi.cpp: In function 'void solve()':
sushi.cpp:70:11: warning: unused variable 'x' [-Wunused-variable]
   70 |       int x = 3;
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 35 ms 9300 KB Output is correct
2 Correct 33 ms 8784 KB Output is correct
3 Correct 35 ms 8784 KB Output is correct
4 Correct 32 ms 8528 KB Output is correct
5 Correct 35 ms 8528 KB Output is correct
6 Correct 36 ms 9308 KB Output is correct
7 Correct 31 ms 8476 KB Output is correct
8 Correct 24 ms 8784 KB Output is correct
9 Correct 33 ms 8796 KB Output is correct
10 Correct 35 ms 8532 KB Output is correct
11 Correct 34 ms 8496 KB Output is correct
12 Correct 32 ms 8540 KB Output is correct
13 Correct 40 ms 9556 KB Output is correct
14 Correct 81 ms 15700 KB Output is correct
15 Correct 91 ms 15700 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 688 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 9300 KB Output is correct
2 Correct 33 ms 8784 KB Output is correct
3 Correct 35 ms 8784 KB Output is correct
4 Correct 32 ms 8528 KB Output is correct
5 Correct 35 ms 8528 KB Output is correct
6 Correct 36 ms 9308 KB Output is correct
7 Correct 31 ms 8476 KB Output is correct
8 Correct 24 ms 8784 KB Output is correct
9 Correct 33 ms 8796 KB Output is correct
10 Correct 35 ms 8532 KB Output is correct
11 Correct 34 ms 8496 KB Output is correct
12 Correct 32 ms 8540 KB Output is correct
13 Correct 40 ms 9556 KB Output is correct
14 Correct 81 ms 15700 KB Output is correct
15 Correct 91 ms 15700 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Runtime error 688 ms 262144 KB Execution killed with signal 9
24 Halted 0 ms 0 KB -