Submission #734771

# Submission time Handle Problem Language Result Execution time Memory
734771 2023-05-03T04:56:56 Z abcvuitunggio Sushi (JOI16_sushi) C++17
100 / 100
3822 ms 81912 KB
#include <bits/stdc++.h>
using namespace std;
const int sz=632;
priority_queue <int> q[400000/sz+1];
priority_queue <int, vector <int>, greater <int>> p[400000/sz+1];
int n,x[400000],cur;
void reset(int i){
    for (int j=i*sz;j<min(i*sz+sz,n);j++){
        p[i].push(x[j]);
        x[j]=p[i].top();
        p[i].pop();
    }
    p[i]=priority_queue <int, vector <int>, greater <int>>();
    q[i]=priority_queue <int>();
}
void f(int l, int r){
    int b=l/sz,e=r/sz;
    reset(b);
    for (int i=l;i<min(b*sz+sz,r+1);i++)
        if (x[i]>cur)
            swap(x[i],cur);
    for (int i=b*sz;i<min(b*sz+sz,n);i++)
        q[b].push(x[i]);
    if (b==e)
        return;
    for (int i=b+1;i<e;i++){
        p[i].push(cur);
        q[i].push(cur);
        cur=q[i].top();
        q[i].pop();
    }
    reset(e);
    for (int i=e*sz;i<=r;i++)
        if (x[i]>cur)
            swap(x[i],cur);
    for (int i=e*sz;i<min(e*sz+sz,n);i++)
        q[e].push(x[i]);
}
void init(){
    for (int i=0;i<n;i++)
        q[i/sz].push(x[i]);
}
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    int q,s,t,p;
    cin >> n >> q;
    for (int i=0;i<n;i++)
        cin >> x[i];
    init();
    while (q--){
        cin >> s >> t >> p;
        s--;
        t--;
        cur=p;
        if (s<=t)
            f(s,t);
        else{
            f(s,n-1);
            f(0,t);
        }
        cout << cur << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 65 ms 396 KB Output is correct
2 Correct 62 ms 400 KB Output is correct
3 Correct 62 ms 408 KB Output is correct
4 Correct 61 ms 396 KB Output is correct
5 Correct 62 ms 340 KB Output is correct
6 Correct 66 ms 388 KB Output is correct
7 Correct 53 ms 396 KB Output is correct
8 Correct 51 ms 380 KB Output is correct
9 Correct 62 ms 396 KB Output is correct
10 Correct 61 ms 396 KB Output is correct
11 Correct 71 ms 400 KB Output is correct
12 Correct 72 ms 396 KB Output is correct
13 Correct 79 ms 384 KB Output is correct
14 Correct 81 ms 396 KB Output is correct
15 Correct 82 ms 404 KB Output is correct
16 Correct 26 ms 400 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 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2652 ms 77360 KB Output is correct
2 Correct 2666 ms 80328 KB Output is correct
3 Correct 1503 ms 78200 KB Output is correct
4 Correct 2744 ms 81752 KB Output is correct
5 Correct 2304 ms 81864 KB Output is correct
6 Correct 2894 ms 81792 KB Output is correct
7 Correct 2763 ms 81660 KB Output is correct
8 Correct 2749 ms 81740 KB Output is correct
9 Correct 1269 ms 78328 KB Output is correct
10 Correct 2318 ms 80184 KB Output is correct
11 Correct 1248 ms 78408 KB Output is correct
12 Correct 2246 ms 80660 KB Output is correct
13 Correct 2697 ms 81848 KB Output is correct
14 Correct 2624 ms 80300 KB Output is correct
15 Correct 1481 ms 78228 KB Output is correct
16 Correct 2641 ms 81696 KB Output is correct
17 Correct 2328 ms 81800 KB Output is correct
18 Correct 2927 ms 81660 KB Output is correct
19 Correct 2769 ms 81656 KB Output is correct
20 Correct 2746 ms 81892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 396 KB Output is correct
2 Correct 62 ms 400 KB Output is correct
3 Correct 62 ms 408 KB Output is correct
4 Correct 61 ms 396 KB Output is correct
5 Correct 62 ms 340 KB Output is correct
6 Correct 66 ms 388 KB Output is correct
7 Correct 53 ms 396 KB Output is correct
8 Correct 51 ms 380 KB Output is correct
9 Correct 62 ms 396 KB Output is correct
10 Correct 61 ms 396 KB Output is correct
11 Correct 71 ms 400 KB Output is correct
12 Correct 72 ms 396 KB Output is correct
13 Correct 79 ms 384 KB Output is correct
14 Correct 81 ms 396 KB Output is correct
15 Correct 82 ms 404 KB Output is correct
16 Correct 26 ms 400 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 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 2652 ms 77360 KB Output is correct
24 Correct 2666 ms 80328 KB Output is correct
25 Correct 1503 ms 78200 KB Output is correct
26 Correct 2744 ms 81752 KB Output is correct
27 Correct 2304 ms 81864 KB Output is correct
28 Correct 2894 ms 81792 KB Output is correct
29 Correct 2763 ms 81660 KB Output is correct
30 Correct 2749 ms 81740 KB Output is correct
31 Correct 1269 ms 78328 KB Output is correct
32 Correct 2318 ms 80184 KB Output is correct
33 Correct 1248 ms 78408 KB Output is correct
34 Correct 2246 ms 80660 KB Output is correct
35 Correct 2697 ms 81848 KB Output is correct
36 Correct 2624 ms 80300 KB Output is correct
37 Correct 1481 ms 78228 KB Output is correct
38 Correct 2641 ms 81696 KB Output is correct
39 Correct 2328 ms 81800 KB Output is correct
40 Correct 2927 ms 81660 KB Output is correct
41 Correct 2769 ms 81656 KB Output is correct
42 Correct 2746 ms 81892 KB Output is correct
43 Correct 2291 ms 9832 KB Output is correct
44 Correct 2304 ms 10096 KB Output is correct
45 Correct 1849 ms 6748 KB Output is correct
46 Correct 2340 ms 9984 KB Output is correct
47 Correct 2293 ms 10116 KB Output is correct
48 Correct 2947 ms 10168 KB Output is correct
49 Correct 3156 ms 9992 KB Output is correct
50 Correct 3166 ms 9932 KB Output is correct
51 Correct 3160 ms 10260 KB Output is correct
52 Correct 2968 ms 11892 KB Output is correct
53 Correct 2942 ms 11904 KB Output is correct
54 Correct 3595 ms 11784 KB Output is correct
55 Correct 3822 ms 11712 KB Output is correct
56 Correct 3810 ms 12156 KB Output is correct
57 Correct 3776 ms 11672 KB Output is correct
58 Correct 2229 ms 10872 KB Output is correct
59 Correct 2201 ms 10628 KB Output is correct
60 Correct 2330 ms 81912 KB Output is correct
61 Correct 2764 ms 81800 KB Output is correct
62 Correct 2702 ms 81892 KB Output is correct
63 Correct 2629 ms 81784 KB Output is correct
64 Correct 1325 ms 6628 KB Output is correct
65 Correct 1416 ms 44680 KB Output is correct
66 Correct 1416 ms 44748 KB Output is correct
67 Correct 3194 ms 50624 KB Output is correct
68 Correct 3544 ms 50728 KB Output is correct
69 Correct 3567 ms 50428 KB Output is correct
70 Correct 3581 ms 50460 KB Output is correct