# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
203833 |
2020-02-22T12:31:57 Z |
youngyojun |
Sushi (JOI16_sushi) |
C++11 |
|
5106 ms |
82544 KB |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400005;
const int MAXQ = 25005;
const int SQRN = 655;
struct BUK {
priority_queue<int, vector<int>, greater<int>> QV;
priority_queue<int> PQ;
int A[SQRN];
int S, E, N;
int cal(int s, int e, int x) {
for(int i = s; i <= e; i++)
if(x < A[i]) swap(A[i], x);
return x;
}
int f(int p, int q, int x) {
p = max(S, p); q = min(E, q);
if(p > q) return x;
if(PQ.top() <= x) return x;
if(p <= S && E <= q) {
QV.push(x);
int ret = PQ.top(); PQ.pop();
PQ.push(x);
return ret;
}
if(!QV.empty()) {
for(int i = 0; i < N; i++) {
if(A[i] <= QV.top()) continue;
int t = QV.top(); QV.pop();
QV.push(A[i]);
A[i] = t;
}
for(; !QV.empty(); QV.pop());
}
int ret = cal(p-S, q-S, x);
for(; !PQ.empty(); PQ.pop());
for(int i = 0; i < N; i++)
PQ.push(A[i]);
return ret;
}
} buk[SQRN]; int bukn;
int A[MAXN];
int B[MAXQ], C[MAXQ], D[MAXQ];
int N, Q;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> N >> Q;
for(int i = 1; i <= N; i++) cin >> A[i];
for(int i = 1; i <= Q; i++) cin >> B[i] >> C[i] >> D[i];
for(int i = 1, s, e;; i++) {
s = (i-1)*SQRN + 1;
e = min(N, i*SQRN);
if(s > e) break;
buk[i].S = s; buk[i].E = e;
buk[i].N = e-s+1;
for(int j = s; j <= e; j++) {
buk[i].A[j-s] = A[j];
buk[i].PQ.push(A[j]);
}
bukn = i;
}
for(int qi = 1, s, e, x; qi <= Q; qi++) {
s = B[qi]; e = C[qi]; x = D[qi];
if(s <= e) {
for(int i = 1; i <= bukn; i++)
x = buk[i].f(s, e, x);
} else {
for(int i = 1; i <= bukn; i++) {
x = buk[i].f(s, N, x);
}
for(int i = 1; i <= bukn; i++)
x = buk[i].f(1, e, x);
}
cout << x << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
2296 KB |
Output is correct |
2 |
Correct |
116 ms |
2168 KB |
Output is correct |
3 |
Correct |
114 ms |
2168 KB |
Output is correct |
4 |
Correct |
124 ms |
2168 KB |
Output is correct |
5 |
Correct |
119 ms |
2296 KB |
Output is correct |
6 |
Correct |
119 ms |
2168 KB |
Output is correct |
7 |
Correct |
26 ms |
2168 KB |
Output is correct |
8 |
Correct |
26 ms |
2168 KB |
Output is correct |
9 |
Correct |
122 ms |
2372 KB |
Output is correct |
10 |
Correct |
120 ms |
2296 KB |
Output is correct |
11 |
Correct |
144 ms |
2168 KB |
Output is correct |
12 |
Correct |
144 ms |
2168 KB |
Output is correct |
13 |
Correct |
154 ms |
2424 KB |
Output is correct |
14 |
Correct |
90 ms |
2168 KB |
Output is correct |
15 |
Correct |
88 ms |
2168 KB |
Output is correct |
16 |
Correct |
105 ms |
2168 KB |
Output is correct |
17 |
Correct |
6 ms |
2040 KB |
Output is correct |
18 |
Correct |
6 ms |
2040 KB |
Output is correct |
19 |
Correct |
6 ms |
2040 KB |
Output is correct |
20 |
Correct |
5 ms |
2040 KB |
Output is correct |
21 |
Correct |
6 ms |
2044 KB |
Output is correct |
22 |
Correct |
6 ms |
2040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2899 ms |
82140 KB |
Output is correct |
2 |
Correct |
2969 ms |
80664 KB |
Output is correct |
3 |
Correct |
96 ms |
7540 KB |
Output is correct |
4 |
Correct |
2953 ms |
82168 KB |
Output is correct |
5 |
Correct |
2690 ms |
81728 KB |
Output is correct |
6 |
Correct |
3201 ms |
81720 KB |
Output is correct |
7 |
Correct |
3198 ms |
81756 KB |
Output is correct |
8 |
Correct |
3183 ms |
81724 KB |
Output is correct |
9 |
Correct |
90 ms |
7672 KB |
Output is correct |
10 |
Correct |
2539 ms |
76152 KB |
Output is correct |
11 |
Correct |
85 ms |
7544 KB |
Output is correct |
12 |
Correct |
2568 ms |
77072 KB |
Output is correct |
13 |
Correct |
2949 ms |
81656 KB |
Output is correct |
14 |
Correct |
2950 ms |
80124 KB |
Output is correct |
15 |
Correct |
169 ms |
7520 KB |
Output is correct |
16 |
Correct |
2914 ms |
82544 KB |
Output is correct |
17 |
Correct |
2731 ms |
81484 KB |
Output is correct |
18 |
Correct |
3189 ms |
81708 KB |
Output is correct |
19 |
Correct |
3197 ms |
81516 KB |
Output is correct |
20 |
Correct |
3165 ms |
81600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
118 ms |
2296 KB |
Output is correct |
2 |
Correct |
116 ms |
2168 KB |
Output is correct |
3 |
Correct |
114 ms |
2168 KB |
Output is correct |
4 |
Correct |
124 ms |
2168 KB |
Output is correct |
5 |
Correct |
119 ms |
2296 KB |
Output is correct |
6 |
Correct |
119 ms |
2168 KB |
Output is correct |
7 |
Correct |
26 ms |
2168 KB |
Output is correct |
8 |
Correct |
26 ms |
2168 KB |
Output is correct |
9 |
Correct |
122 ms |
2372 KB |
Output is correct |
10 |
Correct |
120 ms |
2296 KB |
Output is correct |
11 |
Correct |
144 ms |
2168 KB |
Output is correct |
12 |
Correct |
144 ms |
2168 KB |
Output is correct |
13 |
Correct |
154 ms |
2424 KB |
Output is correct |
14 |
Correct |
90 ms |
2168 KB |
Output is correct |
15 |
Correct |
88 ms |
2168 KB |
Output is correct |
16 |
Correct |
105 ms |
2168 KB |
Output is correct |
17 |
Correct |
6 ms |
2040 KB |
Output is correct |
18 |
Correct |
6 ms |
2040 KB |
Output is correct |
19 |
Correct |
6 ms |
2040 KB |
Output is correct |
20 |
Correct |
5 ms |
2040 KB |
Output is correct |
21 |
Correct |
6 ms |
2044 KB |
Output is correct |
22 |
Correct |
6 ms |
2040 KB |
Output is correct |
23 |
Correct |
2899 ms |
82140 KB |
Output is correct |
24 |
Correct |
2969 ms |
80664 KB |
Output is correct |
25 |
Correct |
96 ms |
7540 KB |
Output is correct |
26 |
Correct |
2953 ms |
82168 KB |
Output is correct |
27 |
Correct |
2690 ms |
81728 KB |
Output is correct |
28 |
Correct |
3201 ms |
81720 KB |
Output is correct |
29 |
Correct |
3198 ms |
81756 KB |
Output is correct |
30 |
Correct |
3183 ms |
81724 KB |
Output is correct |
31 |
Correct |
90 ms |
7672 KB |
Output is correct |
32 |
Correct |
2539 ms |
76152 KB |
Output is correct |
33 |
Correct |
85 ms |
7544 KB |
Output is correct |
34 |
Correct |
2568 ms |
77072 KB |
Output is correct |
35 |
Correct |
2949 ms |
81656 KB |
Output is correct |
36 |
Correct |
2950 ms |
80124 KB |
Output is correct |
37 |
Correct |
169 ms |
7520 KB |
Output is correct |
38 |
Correct |
2914 ms |
82544 KB |
Output is correct |
39 |
Correct |
2731 ms |
81484 KB |
Output is correct |
40 |
Correct |
3189 ms |
81708 KB |
Output is correct |
41 |
Correct |
3197 ms |
81516 KB |
Output is correct |
42 |
Correct |
3165 ms |
81600 KB |
Output is correct |
43 |
Correct |
1786 ms |
11892 KB |
Output is correct |
44 |
Correct |
1824 ms |
11768 KB |
Output is correct |
45 |
Correct |
440 ms |
7832 KB |
Output is correct |
46 |
Correct |
1759 ms |
11884 KB |
Output is correct |
47 |
Correct |
1725 ms |
12024 KB |
Output is correct |
48 |
Correct |
4070 ms |
13432 KB |
Output is correct |
49 |
Correct |
4417 ms |
13648 KB |
Output is correct |
50 |
Correct |
4366 ms |
13824 KB |
Output is correct |
51 |
Correct |
4329 ms |
13656 KB |
Output is correct |
52 |
Correct |
1785 ms |
12792 KB |
Output is correct |
53 |
Correct |
1811 ms |
12860 KB |
Output is correct |
54 |
Correct |
3807 ms |
15992 KB |
Output is correct |
55 |
Correct |
3976 ms |
15864 KB |
Output is correct |
56 |
Correct |
3990 ms |
16264 KB |
Output is correct |
57 |
Correct |
4003 ms |
16124 KB |
Output is correct |
58 |
Correct |
3659 ms |
16248 KB |
Output is correct |
59 |
Correct |
3646 ms |
16240 KB |
Output is correct |
60 |
Correct |
4351 ms |
81272 KB |
Output is correct |
61 |
Correct |
5096 ms |
81292 KB |
Output is correct |
62 |
Correct |
5084 ms |
81544 KB |
Output is correct |
63 |
Correct |
5106 ms |
81400 KB |
Output is correct |
64 |
Correct |
562 ms |
7928 KB |
Output is correct |
65 |
Correct |
1399 ms |
43896 KB |
Output is correct |
66 |
Correct |
1387 ms |
44188 KB |
Output is correct |
67 |
Correct |
2978 ms |
49656 KB |
Output is correct |
68 |
Correct |
3413 ms |
49656 KB |
Output is correct |
69 |
Correct |
3433 ms |
49644 KB |
Output is correct |
70 |
Correct |
3390 ms |
49572 KB |
Output is correct |