Submission #894216

# Submission time Handle Problem Language Result Execution time Memory
894216 2023-12-28T02:57:17 Z box Sushi (JOI16_sushi) C++17
100 / 100
1722 ms 81728 KB
/*
Statement
 
You are given a circular array A of length N. You are given Q queries, each
giving (l, r, a). You are to run the following code:
 
for (int i = l; i <= r; i++)
  if (a < A[i])
    swap(a, A[i]);
 
For each query, output the final value of a.
 
Scoring
 
5p: 1 <= N, Q <= 2e3
15p: For all queries, l = r = 1
80p: 1 <= N <= 4e5, 1 <= Q <= 2.5e4, 1 <= A_i <= 1e9
*/
 
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
 
const int N = 4e5, B = 633;
 
struct T {
  int *a, n;
  vector<int> u;
  priority_queue<int> v;
 
  void build(int *a_, int n_) {
    a = a_, n = n_;
    pull();
  }
  void pull() { v = priority_queue<int>(a, a + n); }
  int force(int l, int r, int x) {
    for (int i = l; i <= r; i++)
      if (x < a[i]) swap(x, a[i]);
    return x;
  }
  int put(int x) {
    int t = v.top();
    if (x < t) {
      v.pop();
      v.push(x);
      u.push_back(x);
      x = t;
    }
    return x;
  }
  void push() {
    if (u.empty()) return;
    static priority_queue<int, vector<int>, greater<int>> u_;
    u_ = priority_queue<int, vector<int>, greater<int>>(u.begin(), u.end());
    int t = u_.top();
    for (int i = 0; i < n; i++)
      if (t < a[i]) {
        u_.pop(), u_.push(a[i]);
        a[i] = t, t = u_.top();
      }
    u.clear();
  }
} b[(N - 1) / B + 1];
 
int update(int l, int r, int x) {
  if (l / B == r / B) {
    b[l / B].push();
    x = b[l / B].force(l - l / B * B, r - l / B * B, x);
    b[l / B].pull();
  } else {
    b[l / B].push();
    x = b[l / B].force(l - l / B * B, b[l / B].n - 1, x);
    b[l / B].pull();
    for (int i = l / B + 1; i < r / B; i++) x = b[i].put(x);
    b[r / B].push();
    x = b[r / B].force(0, r - r / B * B, x);
    b[r / B].pull();
  }
  return x;
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q;
  cin >> n >> q;
  static int a[N];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i <= (n - 1) / B; i++)
    b[i].build(a + B * i, min(n, B * (i + 1)) - B * i);
  while (q--) {
    int l, r, x;
    cin >> l >> r >> x, l--, r--;
    if (l <= r)
      x = update(l, r, x);
    else {
      swap(l, r);
      x = update(r, n - 1, x);
      x = update(0, l, x);
    }
    cout << x << '\n';
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 600 KB Output is correct
2 Correct 13 ms 600 KB Output is correct
3 Correct 20 ms 524 KB Output is correct
4 Correct 14 ms 604 KB Output is correct
5 Correct 14 ms 348 KB Output is correct
6 Correct 13 ms 348 KB Output is correct
7 Correct 11 ms 344 KB Output is correct
8 Correct 15 ms 348 KB Output is correct
9 Correct 14 ms 604 KB Output is correct
10 Correct 14 ms 604 KB Output is correct
11 Correct 14 ms 600 KB Output is correct
12 Correct 15 ms 576 KB Output is correct
13 Correct 16 ms 604 KB Output is correct
14 Correct 18 ms 604 KB Output is correct
15 Correct 17 ms 600 KB Output is correct
16 Correct 7 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 600 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1105 ms 81372 KB Output is correct
2 Correct 1089 ms 79992 KB Output is correct
3 Correct 149 ms 4652 KB Output is correct
4 Correct 1080 ms 81728 KB Output is correct
5 Correct 666 ms 80664 KB Output is correct
6 Correct 1036 ms 80844 KB Output is correct
7 Correct 983 ms 80724 KB Output is correct
8 Correct 1006 ms 80756 KB Output is correct
9 Correct 136 ms 4844 KB Output is correct
10 Correct 576 ms 75632 KB Output is correct
11 Correct 149 ms 4644 KB Output is correct
12 Correct 585 ms 76392 KB Output is correct
13 Correct 1139 ms 81404 KB Output is correct
14 Correct 1145 ms 80404 KB Output is correct
15 Correct 149 ms 4800 KB Output is correct
16 Correct 1200 ms 81680 KB Output is correct
17 Correct 650 ms 80568 KB Output is correct
18 Correct 1024 ms 80520 KB Output is correct
19 Correct 994 ms 80532 KB Output is correct
20 Correct 965 ms 80752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 600 KB Output is correct
2 Correct 13 ms 600 KB Output is correct
3 Correct 20 ms 524 KB Output is correct
4 Correct 14 ms 604 KB Output is correct
5 Correct 14 ms 348 KB Output is correct
6 Correct 13 ms 348 KB Output is correct
7 Correct 11 ms 344 KB Output is correct
8 Correct 15 ms 348 KB Output is correct
9 Correct 14 ms 604 KB Output is correct
10 Correct 14 ms 604 KB Output is correct
11 Correct 14 ms 600 KB Output is correct
12 Correct 15 ms 576 KB Output is correct
13 Correct 16 ms 604 KB Output is correct
14 Correct 18 ms 604 KB Output is correct
15 Correct 17 ms 600 KB Output is correct
16 Correct 7 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 600 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1105 ms 81372 KB Output is correct
24 Correct 1089 ms 79992 KB Output is correct
25 Correct 149 ms 4652 KB Output is correct
26 Correct 1080 ms 81728 KB Output is correct
27 Correct 666 ms 80664 KB Output is correct
28 Correct 1036 ms 80844 KB Output is correct
29 Correct 983 ms 80724 KB Output is correct
30 Correct 1006 ms 80756 KB Output is correct
31 Correct 136 ms 4844 KB Output is correct
32 Correct 576 ms 75632 KB Output is correct
33 Correct 149 ms 4644 KB Output is correct
34 Correct 585 ms 76392 KB Output is correct
35 Correct 1139 ms 81404 KB Output is correct
36 Correct 1145 ms 80404 KB Output is correct
37 Correct 149 ms 4800 KB Output is correct
38 Correct 1200 ms 81680 KB Output is correct
39 Correct 650 ms 80568 KB Output is correct
40 Correct 1024 ms 80520 KB Output is correct
41 Correct 994 ms 80532 KB Output is correct
42 Correct 965 ms 80752 KB Output is correct
43 Correct 551 ms 8880 KB Output is correct
44 Correct 556 ms 9028 KB Output is correct
45 Correct 285 ms 5044 KB Output is correct
46 Correct 566 ms 8720 KB Output is correct
47 Correct 559 ms 8872 KB Output is correct
48 Correct 1604 ms 10820 KB Output is correct
49 Correct 1722 ms 10432 KB Output is correct
50 Correct 1707 ms 10468 KB Output is correct
51 Correct 1671 ms 10656 KB Output is correct
52 Correct 583 ms 9800 KB Output is correct
53 Correct 576 ms 9600 KB Output is correct
54 Correct 1519 ms 12780 KB Output is correct
55 Correct 1592 ms 12760 KB Output is correct
56 Correct 1551 ms 12996 KB Output is correct
57 Correct 1583 ms 12916 KB Output is correct
58 Correct 1360 ms 13020 KB Output is correct
59 Correct 1378 ms 13528 KB Output is correct
60 Correct 665 ms 80536 KB Output is correct
61 Correct 1095 ms 80572 KB Output is correct
62 Correct 1024 ms 80604 KB Output is correct
63 Correct 997 ms 80744 KB Output is correct
64 Correct 192 ms 4648 KB Output is correct
65 Correct 440 ms 42364 KB Output is correct
66 Correct 384 ms 42592 KB Output is correct
67 Correct 537 ms 48004 KB Output is correct
68 Correct 721 ms 48016 KB Output is correct
69 Correct 712 ms 47900 KB Output is correct
70 Correct 686 ms 47948 KB Output is correct