# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
595906 |
2022-07-14T08:01:05 Z |
이동현(#8445) |
Sushi (JOI16_sushi) |
C++17 |
|
12000 ms |
258184 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int BS = 1000;
multiset<int> num[BS];
multiset<int> que[BS];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int B = 1970;
int n, q; cin >> n >> q;
//n = 400000, q = 25000;
vector<int> a(n);
for(int i = 0; i < n; ++i){
cin >> a[i];
// a[i] = i + 1;
num[i / B].insert(a[i]);
}
while(q--){
int x, y, k; cin >> x >> y >> k; --x, --y;
// x = 0, y = n - 1, k = q + 300;
auto sol = [&](int x, int y, int k)->int{
auto doque = [&](int pos)->void{
int bp = pos / B;
if(!(int)que[bp].size()){
return;
}
int l = bp * B, r = min(n, l + B);
if((int)que[bp].size() == 1){
int val = *que[bp].begin();
for(int i = l; i < r; ++i) if(val < a[i]) swap(val, a[i]);
}
else if((int)que[bp].size() == 2){
int v1 = *que[bp].begin(), v2 = *(--que[bp].end());
for(int i = l; i < r; ++i){
if(v1 < a[i]) swap(v1, a[i]);
if(v2 < a[i]) swap(v2, a[i]);
}
}
else if((int)que[bp].size() == 3){
int v1 = *que[bp].begin(), v2 = *(--(--que[bp].end())), v3 = *(--que[bp].end());
for(int i = l; i < r; ++i){
if(v1 < a[i]) swap(v1, a[i]);
if(v2 < a[i]) swap(v2, a[i]);
if(v3 < a[i]) swap(v3, a[i]);
}
}
else{
for(int i = l; i < r; ++i){
que[bp].insert(a[i]);
a[i] = *(que[bp].begin());
que[bp].erase(que[bp].begin());
}
}
que[bp].clear();
};
doque(x), doque(y);
int xb = x / B, yb = y / B;
int xl = xb * B, xr = min(n, xl + B);
int yl = yb * B, yr = min(n, yl + B);
if(xb < yb){
for(int i = x; i < xr; ++i){
if(a[i] > k){
auto p = num[xb].lower_bound(a[i]);
num[xb].erase(p);
swap(a[i], k);
num[xb].insert(a[i]);
}
}
for(int i = xb + 1; i < yb; ++i){
que[i].insert(k);
num[i].insert(k);
k = *(--num[i].end());
num[i].erase(--num[i].end());
}
for(int i = yl; i <= y; ++i){
if(a[i] > k){
auto p = num[yb].lower_bound(a[i]);
num[yb].erase(p);
swap(a[i], k);
num[yb].insert(a[i]);
}
}
}
else{
for(int i = x; i <= y; ++i){
if(a[i] > k){
auto p = num[xb].lower_bound(a[i]);
num[xb].erase(p);
swap(a[i], k);
num[xb].insert(a[i]);
}
}
}
return k;
};
//if(x <= y) sol(x, y, k);
//else sol(0, y, sol(x, n - 1, k));
if(x <= y) cout << sol(x, y, k) << '\n';
else cout << sol(0, y, sol(x, n - 1, k)) << '\n';
}
return 0;
}
Compilation message
sushi.cpp: In lambda function:
sushi.cpp:64:30: warning: unused variable 'yr' [-Wunused-variable]
64 | int yl = yb * B, yr = min(n, yl + B);
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
468 KB |
Output is correct |
2 |
Correct |
10 ms |
468 KB |
Output is correct |
3 |
Correct |
8 ms |
532 KB |
Output is correct |
4 |
Correct |
10 ms |
468 KB |
Output is correct |
5 |
Correct |
9 ms |
468 KB |
Output is correct |
6 |
Correct |
9 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
10 ms |
520 KB |
Output is correct |
10 |
Correct |
8 ms |
468 KB |
Output is correct |
11 |
Correct |
93 ms |
512 KB |
Output is correct |
12 |
Correct |
99 ms |
512 KB |
Output is correct |
13 |
Correct |
89 ms |
516 KB |
Output is correct |
14 |
Correct |
14 ms |
468 KB |
Output is correct |
15 |
Correct |
15 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6978 ms |
258184 KB |
Output is correct |
2 |
Correct |
10981 ms |
258088 KB |
Output is correct |
3 |
Correct |
4089 ms |
257940 KB |
Output is correct |
4 |
Correct |
7007 ms |
258080 KB |
Output is correct |
5 |
Correct |
9441 ms |
258116 KB |
Output is correct |
6 |
Correct |
11436 ms |
258124 KB |
Output is correct |
7 |
Correct |
11101 ms |
258072 KB |
Output is correct |
8 |
Correct |
10892 ms |
258164 KB |
Output is correct |
9 |
Correct |
3614 ms |
257896 KB |
Output is correct |
10 |
Correct |
2799 ms |
258060 KB |
Output is correct |
11 |
Correct |
3425 ms |
257896 KB |
Output is correct |
12 |
Correct |
3251 ms |
258032 KB |
Output is correct |
13 |
Correct |
7353 ms |
258072 KB |
Output is correct |
14 |
Correct |
7592 ms |
258028 KB |
Output is correct |
15 |
Correct |
3970 ms |
257916 KB |
Output is correct |
16 |
Correct |
8084 ms |
258044 KB |
Output is correct |
17 |
Correct |
9337 ms |
258048 KB |
Output is correct |
18 |
Correct |
11699 ms |
258060 KB |
Output is correct |
19 |
Execution timed out |
12043 ms |
258120 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
468 KB |
Output is correct |
2 |
Correct |
10 ms |
468 KB |
Output is correct |
3 |
Correct |
8 ms |
532 KB |
Output is correct |
4 |
Correct |
10 ms |
468 KB |
Output is correct |
5 |
Correct |
9 ms |
468 KB |
Output is correct |
6 |
Correct |
9 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
4 ms |
468 KB |
Output is correct |
9 |
Correct |
10 ms |
520 KB |
Output is correct |
10 |
Correct |
8 ms |
468 KB |
Output is correct |
11 |
Correct |
93 ms |
512 KB |
Output is correct |
12 |
Correct |
99 ms |
512 KB |
Output is correct |
13 |
Correct |
89 ms |
516 KB |
Output is correct |
14 |
Correct |
14 ms |
468 KB |
Output is correct |
15 |
Correct |
15 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
6978 ms |
258184 KB |
Output is correct |
24 |
Correct |
10981 ms |
258088 KB |
Output is correct |
25 |
Correct |
4089 ms |
257940 KB |
Output is correct |
26 |
Correct |
7007 ms |
258080 KB |
Output is correct |
27 |
Correct |
9441 ms |
258116 KB |
Output is correct |
28 |
Correct |
11436 ms |
258124 KB |
Output is correct |
29 |
Correct |
11101 ms |
258072 KB |
Output is correct |
30 |
Correct |
10892 ms |
258164 KB |
Output is correct |
31 |
Correct |
3614 ms |
257896 KB |
Output is correct |
32 |
Correct |
2799 ms |
258060 KB |
Output is correct |
33 |
Correct |
3425 ms |
257896 KB |
Output is correct |
34 |
Correct |
3251 ms |
258032 KB |
Output is correct |
35 |
Correct |
7353 ms |
258072 KB |
Output is correct |
36 |
Correct |
7592 ms |
258028 KB |
Output is correct |
37 |
Correct |
3970 ms |
257916 KB |
Output is correct |
38 |
Correct |
8084 ms |
258044 KB |
Output is correct |
39 |
Correct |
9337 ms |
258048 KB |
Output is correct |
40 |
Correct |
11699 ms |
258060 KB |
Output is correct |
41 |
Execution timed out |
12043 ms |
258120 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |