Submission #597480

# Submission time Handle Problem Language Result Execution time Memory
597480 2022-07-16T05:50:53 Z 79brue Sushi (JOI16_sushi) C++17
100 / 100
10348 ms 80040 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
int LIM = 650;

int n, q;
int arr[400002];
priority_queue<int> exist[2000]; /// 존재하는 수들의 multiset
priority_queue<int, vector<int>, greater<int> > add[2000]; /// 추가될 수들의 multiset

void remakePQ(int g){
    int s = g*LIM, e = min(g*LIM+LIM-1, n-1);
    while(!add[g].empty()) add[g].pop();
    while(!exist[g].empty()) exist[g].pop();
    for(int i=s; i<=e; i++) exist[g].push(arr[i]);
}

void resolve(int g){
    int s = g*LIM, e = min(g*LIM+LIM-1, n-1);
    for(int i=s; i<=e; i++){
        add[g].push(arr[i]);
        arr[i] = add[g].top();
        add[g].pop();
    }
    remakePQ(g);
}

int solve(int s, int e, int v){ /// s에서 e 사이에 v를 추가한다
    int sg = s/LIM, eg = e/LIM;
    if(sg == eg){
        resolve(sg);
        for(int i=s; i<=e; i++){
            if(arr[i] > v) swap(arr[i], v);
        }
        remakePQ(sg);
        return v;
    }

    { /// sg 처리
        resolve(sg);
        for(int i=s; i<(sg+1)*LIM; i++) if(arr[i] > v) swap(arr[i], v);
        remakePQ(sg);
    }
    for(int i=sg+1; i<eg; i++){
        add[i].push(v);
        exist[i].push(v);
        v = exist[i].top();
        exist[i].pop();
    }
    { /// sg 처리
        resolve(eg);
        for(int i=eg*LIM; i<=e; i++) if(arr[i] > v) swap(arr[i], v);
        remakePQ(eg);
    }
    return v;
}

int main(){
    scanf("%d %d", &n, &q);
    for(int i=0; i<n; i++){
        scanf("%d", &arr[i]);
    }
    for(int i=0; (i+1)*LIM<n; i++) remakePQ(i);
    for(int i=1; i<=q; i++){
        int s, e, v;
        scanf("%d %d %d", &s, &e, &v);
        s--, e--;
        if(s<=e) printf("%d\n", solve(s, e, v));
        else printf("%d\n", solve(0, e, solve(s, n-1, v)));
    }
}

Compilation message

sushi.cpp: In function 'int main()':
sushi.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
sushi.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         scanf("%d", &arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
sushi.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         scanf("%d %d %d", &s, &e, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 352 ms 624 KB Output is correct
2 Correct 375 ms 492 KB Output is correct
3 Correct 354 ms 496 KB Output is correct
4 Correct 341 ms 500 KB Output is correct
5 Correct 357 ms 596 KB Output is correct
6 Correct 346 ms 472 KB Output is correct
7 Correct 144 ms 468 KB Output is correct
8 Correct 142 ms 468 KB Output is correct
9 Correct 339 ms 516 KB Output is correct
10 Correct 370 ms 508 KB Output is correct
11 Correct 330 ms 512 KB Output is correct
12 Correct 344 ms 632 KB Output is correct
13 Correct 385 ms 620 KB Output is correct
14 Correct 437 ms 508 KB Output is correct
15 Correct 457 ms 508 KB Output is correct
16 Correct 167 ms 504 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 436 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4326 ms 79752 KB Output is correct
2 Correct 4295 ms 78524 KB Output is correct
3 Correct 1850 ms 76528 KB Output is correct
4 Correct 4247 ms 80008 KB Output is correct
5 Correct 3491 ms 79888 KB Output is correct
6 Correct 4521 ms 79932 KB Output is correct
7 Correct 4492 ms 79892 KB Output is correct
8 Correct 4452 ms 79916 KB Output is correct
9 Correct 1694 ms 76568 KB Output is correct
10 Correct 3466 ms 78424 KB Output is correct
11 Correct 1826 ms 76432 KB Output is correct
12 Correct 3628 ms 78408 KB Output is correct
13 Correct 4415 ms 79804 KB Output is correct
14 Correct 4419 ms 78396 KB Output is correct
15 Correct 1918 ms 76324 KB Output is correct
16 Correct 4246 ms 79860 KB Output is correct
17 Correct 3439 ms 79912 KB Output is correct
18 Correct 4635 ms 79996 KB Output is correct
19 Correct 4557 ms 80040 KB Output is correct
20 Correct 4579 ms 79940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 352 ms 624 KB Output is correct
2 Correct 375 ms 492 KB Output is correct
3 Correct 354 ms 496 KB Output is correct
4 Correct 341 ms 500 KB Output is correct
5 Correct 357 ms 596 KB Output is correct
6 Correct 346 ms 472 KB Output is correct
7 Correct 144 ms 468 KB Output is correct
8 Correct 142 ms 468 KB Output is correct
9 Correct 339 ms 516 KB Output is correct
10 Correct 370 ms 508 KB Output is correct
11 Correct 330 ms 512 KB Output is correct
12 Correct 344 ms 632 KB Output is correct
13 Correct 385 ms 620 KB Output is correct
14 Correct 437 ms 508 KB Output is correct
15 Correct 457 ms 508 KB Output is correct
16 Correct 167 ms 504 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 436 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 424 KB Output is correct
23 Correct 4326 ms 79752 KB Output is correct
24 Correct 4295 ms 78524 KB Output is correct
25 Correct 1850 ms 76528 KB Output is correct
26 Correct 4247 ms 80008 KB Output is correct
27 Correct 3491 ms 79888 KB Output is correct
28 Correct 4521 ms 79932 KB Output is correct
29 Correct 4492 ms 79892 KB Output is correct
30 Correct 4452 ms 79916 KB Output is correct
31 Correct 1694 ms 76568 KB Output is correct
32 Correct 3466 ms 78424 KB Output is correct
33 Correct 1826 ms 76432 KB Output is correct
34 Correct 3628 ms 78408 KB Output is correct
35 Correct 4415 ms 79804 KB Output is correct
36 Correct 4419 ms 78396 KB Output is correct
37 Correct 1918 ms 76324 KB Output is correct
38 Correct 4246 ms 79860 KB Output is correct
39 Correct 3439 ms 79912 KB Output is correct
40 Correct 4635 ms 79996 KB Output is correct
41 Correct 4557 ms 80040 KB Output is correct
42 Correct 4579 ms 79940 KB Output is correct
43 Correct 7841 ms 12152 KB Output is correct
44 Correct 7623 ms 12064 KB Output is correct
45 Correct 3809 ms 8524 KB Output is correct
46 Correct 7440 ms 12304 KB Output is correct
47 Correct 7425 ms 12372 KB Output is correct
48 Correct 6993 ms 12204 KB Output is correct
49 Correct 7805 ms 12248 KB Output is correct
50 Correct 8180 ms 12032 KB Output is correct
51 Correct 8423 ms 12184 KB Output is correct
52 Correct 10134 ms 18540 KB Output is correct
53 Correct 9557 ms 18020 KB Output is correct
54 Correct 8959 ms 18384 KB Output is correct
55 Correct 10348 ms 18212 KB Output is correct
56 Correct 10227 ms 18176 KB Output is correct
57 Correct 10071 ms 18144 KB Output is correct
58 Correct 5351 ms 14152 KB Output is correct
59 Correct 4617 ms 14188 KB Output is correct
60 Correct 4160 ms 79716 KB Output is correct
61 Correct 4932 ms 79844 KB Output is correct
62 Correct 4809 ms 79720 KB Output is correct
63 Correct 4910 ms 79804 KB Output is correct
64 Correct 2914 ms 8544 KB Output is correct
65 Correct 4118 ms 43792 KB Output is correct
66 Correct 3773 ms 43708 KB Output is correct
67 Correct 8384 ms 66656 KB Output is correct
68 Correct 8798 ms 66544 KB Output is correct
69 Correct 8854 ms 66428 KB Output is correct
70 Correct 8889 ms 66496 KB Output is correct