답안 #595866

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
595866 2022-07-14T07:47:05 Z 이동현(#8445) Sushi (JOI16_sushi) C++17
5 / 100
12000 ms 21436 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, NS = (int)4e5 + 4;
multiset<int> num[BS];
multiset<int> que[BS];
int lst[NS];
int ask[NS][3];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int B = 1900;
    int n, q; cin >> n >> q;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        num[i / B].insert(a[i]);
    }
    for(int i = 0; i < q; ++i){
        cin >> ask[i][0] >> ask[i][1] >> ask[i][2];
        lst[ask[i][0] / B] = lst[ask[i][1] / B] = i;
        if(ask[i][0] > ask[i][1]) lst[(n - 1) / B] = lst[0] = i;
    }
    for(int qq = 0; qq < q; ++qq){
        int x, y, k;
        x = ask[qq][0] - 1, y = ask[qq][1] - 1, k = ask[qq][2];
        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);
                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){
                    if(lst[i] > qq) 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:48:30: warning: unused variable 'yr' [-Wunused-variable]
   48 |             int yl = yb * B, yr = min(n, yl + B);
      |                              ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 468 KB Output is correct
2 Correct 10 ms 468 KB Output is correct
3 Correct 14 ms 556 KB Output is correct
4 Correct 16 ms 568 KB Output is correct
5 Correct 8 ms 468 KB Output is correct
6 Correct 8 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 17 ms 468 KB Output is correct
10 Correct 8 ms 468 KB Output is correct
11 Correct 102 ms 540 KB Output is correct
12 Correct 100 ms 552 KB Output is correct
13 Correct 75 ms 556 KB Output is correct
14 Correct 14 ms 468 KB Output is correct
15 Correct 14 ms 568 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 3466 ms 21292 KB Output is correct
2 Correct 3749 ms 21244 KB Output is correct
3 Correct 2009 ms 21212 KB Output is correct
4 Correct 3572 ms 21436 KB Output is correct
5 Correct 11400 ms 21356 KB Output is correct
6 Correct 9815 ms 21280 KB Output is correct
7 Correct 10334 ms 21336 KB Output is correct
8 Correct 10117 ms 21264 KB Output is correct
9 Correct 1705 ms 21208 KB Output is correct
10 Correct 5737 ms 21224 KB Output is correct
11 Correct 3298 ms 21124 KB Output is correct
12 Execution timed out 12088 ms 21172 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 468 KB Output is correct
2 Correct 10 ms 468 KB Output is correct
3 Correct 14 ms 556 KB Output is correct
4 Correct 16 ms 568 KB Output is correct
5 Correct 8 ms 468 KB Output is correct
6 Correct 8 ms 468 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 17 ms 468 KB Output is correct
10 Correct 8 ms 468 KB Output is correct
11 Correct 102 ms 540 KB Output is correct
12 Correct 100 ms 552 KB Output is correct
13 Correct 75 ms 556 KB Output is correct
14 Correct 14 ms 468 KB Output is correct
15 Correct 14 ms 568 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 0 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 3466 ms 21292 KB Output is correct
24 Correct 3749 ms 21244 KB Output is correct
25 Correct 2009 ms 21212 KB Output is correct
26 Correct 3572 ms 21436 KB Output is correct
27 Correct 11400 ms 21356 KB Output is correct
28 Correct 9815 ms 21280 KB Output is correct
29 Correct 10334 ms 21336 KB Output is correct
30 Correct 10117 ms 21264 KB Output is correct
31 Correct 1705 ms 21208 KB Output is correct
32 Correct 5737 ms 21224 KB Output is correct
33 Correct 3298 ms 21124 KB Output is correct
34 Execution timed out 12088 ms 21172 KB Time limit exceeded
35 Halted 0 ms 0 KB -