# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
699874 |
2023-02-18T07:36:04 Z |
bdl |
Sushi (JOI16_sushi) |
C++17 |
|
1950 ms |
77692 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
05: 1 <= N, Q <= 2e3
15: For all queries, l = r = 1
80: 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 |
19 ms |
468 KB |
Output is correct |
2 |
Correct |
18 ms |
464 KB |
Output is correct |
3 |
Correct |
19 ms |
452 KB |
Output is correct |
4 |
Correct |
19 ms |
428 KB |
Output is correct |
5 |
Correct |
19 ms |
436 KB |
Output is correct |
6 |
Correct |
18 ms |
340 KB |
Output is correct |
7 |
Correct |
15 ms |
424 KB |
Output is correct |
8 |
Correct |
15 ms |
428 KB |
Output is correct |
9 |
Correct |
23 ms |
456 KB |
Output is correct |
10 |
Correct |
20 ms |
476 KB |
Output is correct |
11 |
Correct |
23 ms |
464 KB |
Output is correct |
12 |
Correct |
21 ms |
456 KB |
Output is correct |
13 |
Correct |
22 ms |
468 KB |
Output is correct |
14 |
Correct |
24 ms |
340 KB |
Output is correct |
15 |
Correct |
24 ms |
340 KB |
Output is correct |
16 |
Correct |
9 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1377 ms |
77692 KB |
Output is correct |
2 |
Correct |
1307 ms |
77392 KB |
Output is correct |
3 |
Correct |
191 ms |
3964 KB |
Output is correct |
4 |
Correct |
1302 ms |
77448 KB |
Output is correct |
5 |
Correct |
782 ms |
76624 KB |
Output is correct |
6 |
Correct |
1227 ms |
76672 KB |
Output is correct |
7 |
Correct |
1204 ms |
76556 KB |
Output is correct |
8 |
Correct |
1170 ms |
76596 KB |
Output is correct |
9 |
Correct |
163 ms |
4040 KB |
Output is correct |
10 |
Correct |
761 ms |
72596 KB |
Output is correct |
11 |
Correct |
167 ms |
3928 KB |
Output is correct |
12 |
Correct |
761 ms |
73496 KB |
Output is correct |
13 |
Correct |
1340 ms |
77504 KB |
Output is correct |
14 |
Correct |
1321 ms |
77672 KB |
Output is correct |
15 |
Correct |
190 ms |
3936 KB |
Output is correct |
16 |
Correct |
1351 ms |
77692 KB |
Output is correct |
17 |
Correct |
903 ms |
76576 KB |
Output is correct |
18 |
Correct |
1286 ms |
76644 KB |
Output is correct |
19 |
Correct |
1291 ms |
76660 KB |
Output is correct |
20 |
Correct |
1220 ms |
76564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
468 KB |
Output is correct |
2 |
Correct |
18 ms |
464 KB |
Output is correct |
3 |
Correct |
19 ms |
452 KB |
Output is correct |
4 |
Correct |
19 ms |
428 KB |
Output is correct |
5 |
Correct |
19 ms |
436 KB |
Output is correct |
6 |
Correct |
18 ms |
340 KB |
Output is correct |
7 |
Correct |
15 ms |
424 KB |
Output is correct |
8 |
Correct |
15 ms |
428 KB |
Output is correct |
9 |
Correct |
23 ms |
456 KB |
Output is correct |
10 |
Correct |
20 ms |
476 KB |
Output is correct |
11 |
Correct |
23 ms |
464 KB |
Output is correct |
12 |
Correct |
21 ms |
456 KB |
Output is correct |
13 |
Correct |
22 ms |
468 KB |
Output is correct |
14 |
Correct |
24 ms |
340 KB |
Output is correct |
15 |
Correct |
24 ms |
340 KB |
Output is correct |
16 |
Correct |
9 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1377 ms |
77692 KB |
Output is correct |
24 |
Correct |
1307 ms |
77392 KB |
Output is correct |
25 |
Correct |
191 ms |
3964 KB |
Output is correct |
26 |
Correct |
1302 ms |
77448 KB |
Output is correct |
27 |
Correct |
782 ms |
76624 KB |
Output is correct |
28 |
Correct |
1227 ms |
76672 KB |
Output is correct |
29 |
Correct |
1204 ms |
76556 KB |
Output is correct |
30 |
Correct |
1170 ms |
76596 KB |
Output is correct |
31 |
Correct |
163 ms |
4040 KB |
Output is correct |
32 |
Correct |
761 ms |
72596 KB |
Output is correct |
33 |
Correct |
167 ms |
3928 KB |
Output is correct |
34 |
Correct |
761 ms |
73496 KB |
Output is correct |
35 |
Correct |
1340 ms |
77504 KB |
Output is correct |
36 |
Correct |
1321 ms |
77672 KB |
Output is correct |
37 |
Correct |
190 ms |
3936 KB |
Output is correct |
38 |
Correct |
1351 ms |
77692 KB |
Output is correct |
39 |
Correct |
903 ms |
76576 KB |
Output is correct |
40 |
Correct |
1286 ms |
76644 KB |
Output is correct |
41 |
Correct |
1291 ms |
76660 KB |
Output is correct |
42 |
Correct |
1220 ms |
76564 KB |
Output is correct |
43 |
Correct |
605 ms |
4712 KB |
Output is correct |
44 |
Correct |
628 ms |
4932 KB |
Output is correct |
45 |
Correct |
359 ms |
3880 KB |
Output is correct |
46 |
Correct |
596 ms |
4696 KB |
Output is correct |
47 |
Correct |
603 ms |
4624 KB |
Output is correct |
48 |
Correct |
1818 ms |
6504 KB |
Output is correct |
49 |
Correct |
1950 ms |
6096 KB |
Output is correct |
50 |
Correct |
1921 ms |
5984 KB |
Output is correct |
51 |
Correct |
1944 ms |
6024 KB |
Output is correct |
52 |
Correct |
726 ms |
5456 KB |
Output is correct |
53 |
Correct |
716 ms |
5268 KB |
Output is correct |
54 |
Correct |
1639 ms |
8520 KB |
Output is correct |
55 |
Correct |
1711 ms |
8356 KB |
Output is correct |
56 |
Correct |
1721 ms |
8584 KB |
Output is correct |
57 |
Correct |
1729 ms |
8504 KB |
Output is correct |
58 |
Correct |
1561 ms |
8900 KB |
Output is correct |
59 |
Correct |
1536 ms |
9040 KB |
Output is correct |
60 |
Correct |
843 ms |
76108 KB |
Output is correct |
61 |
Correct |
1254 ms |
76272 KB |
Output is correct |
62 |
Correct |
1249 ms |
76260 KB |
Output is correct |
63 |
Correct |
1261 ms |
76136 KB |
Output is correct |
64 |
Correct |
229 ms |
3528 KB |
Output is correct |
65 |
Correct |
536 ms |
39132 KB |
Output is correct |
66 |
Correct |
424 ms |
39476 KB |
Output is correct |
67 |
Correct |
708 ms |
43448 KB |
Output is correct |
68 |
Correct |
897 ms |
43472 KB |
Output is correct |
69 |
Correct |
892 ms |
43524 KB |
Output is correct |
70 |
Correct |
842 ms |
43512 KB |
Output is correct |