답안 #1109145

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1109145 2024-11-06T06:05:02 Z azberjibiou Sushi (JOI16_sushi) C++17
100 / 100
2934 ms 10424 KB
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define lb lower_bound
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
using namespace std;
const int mxN=400400;
const int mxQ=25050;
const int MOD=998244353;
const ll INF=1e18;
const int B=300;
int N, Q;
int A[mxN];
int s[mxQ], e[mxQ], h[mxQ];
int ans[mxQ];
priority_queue <int> pqA[2*B+5], pqH[2*B+5];
void input(){
    cin >> N >> Q;
    for(int i=1;i<=N;i++) cin >> A[i];
    for(int i=1;i<=Q;i++) cin >> s[i] >> e[i] >> h[i];
}
void add(int idx, int &nh){
    int maxi=pqA[idx].top();
    if(maxi<=nh) return;
    pqA[idx].pop();
    pqA[idx].push(nh);
    pqH[idx].push(-nh);
    nh=maxi;
}
void solv(int l, int r){
    vector <int> cr;
    cr.push_back(1); cr.push_back(N+1);
    for(int i=l;i<=r;i++) cr.push_back(s[i]), cr.push_back(e[i]+1);
    sort(all(cr));
    cr.erase(unique(all(cr)), cr.end());
    for(int i=0;i<cr.size()-1;i++){
        for(int j=cr[i];j<cr[i+1];j++) pqA[i].push(A[j]);
    }
    for(int i=l;i<=r;i++){
        int ns=s[i], ne=e[i]+1;
        ns=lower_bound(all(cr), ns)-cr.begin();
        ne=lower_bound(all(cr), ne)-cr.begin();
        if(ns<ne){
            int nh=h[i];
            for(int j=ns;j<ne;j++) add(j, nh);
            ans[i]=nh;
        }
        else{
            int nh=h[i];
            for(int j=ns;j+1<cr.size();j++) add(j, nh);
            for(int j=0;j<ne;j++) add(j, nh);
            ans[i]=nh;
        }
    }
    for(int i=0;i+1<cr.size();i++){
        for(int j=cr[i];j<cr[i+1];j++){
            if(pqH[i].empty()) break;
            int mini=-pqH[i].top();
            if(mini>=A[j]) continue;
            pqH[i].pop();
            pqH[i].push(-A[j]);
            A[j]=mini;
        }
    }

    for(int i=0;i<cr.size();i++) pqH[i]=priority_queue<int>(), pqA[i]=priority_queue<int>();
}
int main(){
    gibon
    input();
    for(int i=1;i<=Q;i+=B){
        solv(i, min(i+B-1, Q));
    }
    for(int i=1;i<=Q;i++) cout << ans[i] << '\n';
}

Compilation message

sushi.cpp: In function 'void solv(int, int)':
sushi.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=0;i<cr.size()-1;i++){
      |                 ~^~~~~~~~~~~~
sushi.cpp:55:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             for(int j=ns;j+1<cr.size();j++) add(j, nh);
      |                          ~~~^~~~~~~~~~
sushi.cpp:60:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for(int i=0;i+1<cr.size();i++){
      |                 ~~~^~~~~~~~~~
sushi.cpp:71:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(int i=0;i<cr.size();i++) pqH[i]=priority_queue<int>(), pqA[i]=priority_queue<int>();
      |                 ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 592 KB Output is correct
2 Correct 5 ms 592 KB Output is correct
3 Correct 6 ms 592 KB Output is correct
4 Correct 5 ms 592 KB Output is correct
5 Correct 5 ms 592 KB Output is correct
6 Correct 5 ms 592 KB Output is correct
7 Correct 7 ms 592 KB Output is correct
8 Correct 4 ms 592 KB Output is correct
9 Correct 6 ms 592 KB Output is correct
10 Correct 5 ms 612 KB Output is correct
11 Correct 12 ms 848 KB Output is correct
12 Correct 13 ms 848 KB Output is correct
13 Correct 18 ms 848 KB Output is correct
14 Correct 6 ms 592 KB Output is correct
15 Correct 8 ms 644 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 950 ms 6072 KB Output is correct
2 Correct 936 ms 6080 KB Output is correct
3 Correct 536 ms 6112 KB Output is correct
4 Correct 982 ms 6088 KB Output is correct
5 Correct 2246 ms 6064 KB Output is correct
6 Correct 2875 ms 6176 KB Output is correct
7 Correct 2894 ms 6064 KB Output is correct
8 Correct 2914 ms 6056 KB Output is correct
9 Correct 422 ms 7180 KB Output is correct
10 Correct 2548 ms 6128 KB Output is correct
11 Correct 472 ms 6280 KB Output is correct
12 Correct 2471 ms 6064 KB Output is correct
13 Correct 1050 ms 6144 KB Output is correct
14 Correct 1056 ms 6080 KB Output is correct
15 Correct 567 ms 6132 KB Output is correct
16 Correct 1044 ms 6092 KB Output is correct
17 Correct 2175 ms 6076 KB Output is correct
18 Correct 2873 ms 6048 KB Output is correct
19 Correct 2934 ms 10424 KB Output is correct
20 Correct 2804 ms 6068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 592 KB Output is correct
2 Correct 5 ms 592 KB Output is correct
3 Correct 6 ms 592 KB Output is correct
4 Correct 5 ms 592 KB Output is correct
5 Correct 5 ms 592 KB Output is correct
6 Correct 5 ms 592 KB Output is correct
7 Correct 7 ms 592 KB Output is correct
8 Correct 4 ms 592 KB Output is correct
9 Correct 6 ms 592 KB Output is correct
10 Correct 5 ms 612 KB Output is correct
11 Correct 12 ms 848 KB Output is correct
12 Correct 13 ms 848 KB Output is correct
13 Correct 18 ms 848 KB Output is correct
14 Correct 6 ms 592 KB Output is correct
15 Correct 8 ms 644 KB Output is correct
16 Correct 3 ms 592 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 950 ms 6072 KB Output is correct
24 Correct 936 ms 6080 KB Output is correct
25 Correct 536 ms 6112 KB Output is correct
26 Correct 982 ms 6088 KB Output is correct
27 Correct 2246 ms 6064 KB Output is correct
28 Correct 2875 ms 6176 KB Output is correct
29 Correct 2894 ms 6064 KB Output is correct
30 Correct 2914 ms 6056 KB Output is correct
31 Correct 422 ms 7180 KB Output is correct
32 Correct 2548 ms 6128 KB Output is correct
33 Correct 472 ms 6280 KB Output is correct
34 Correct 2471 ms 6064 KB Output is correct
35 Correct 1050 ms 6144 KB Output is correct
36 Correct 1056 ms 6080 KB Output is correct
37 Correct 567 ms 6132 KB Output is correct
38 Correct 1044 ms 6092 KB Output is correct
39 Correct 2175 ms 6076 KB Output is correct
40 Correct 2873 ms 6048 KB Output is correct
41 Correct 2934 ms 10424 KB Output is correct
42 Correct 2804 ms 6068 KB Output is correct
43 Correct 625 ms 4936 KB Output is correct
44 Correct 679 ms 5176 KB Output is correct
45 Correct 359 ms 4848 KB Output is correct
46 Correct 709 ms 4968 KB Output is correct
47 Correct 640 ms 4872 KB Output is correct
48 Correct 1870 ms 9576 KB Output is correct
49 Correct 2244 ms 5228 KB Output is correct
50 Correct 2120 ms 5276 KB Output is correct
51 Correct 2115 ms 5376 KB Output is correct
52 Correct 658 ms 7540 KB Output is correct
53 Correct 680 ms 5020 KB Output is correct
54 Correct 2070 ms 5376 KB Output is correct
55 Correct 2354 ms 5288 KB Output is correct
56 Correct 2270 ms 7896 KB Output is correct
57 Correct 2432 ms 5448 KB Output is correct
58 Correct 1867 ms 5172 KB Output is correct
59 Correct 1795 ms 5252 KB Output is correct
60 Correct 2413 ms 6224 KB Output is correct
61 Correct 2838 ms 6172 KB Output is correct
62 Correct 2811 ms 6996 KB Output is correct
63 Correct 2620 ms 6888 KB Output is correct
64 Correct 186 ms 4688 KB Output is correct
65 Correct 2404 ms 6144 KB Output is correct
66 Correct 2307 ms 6196 KB Output is correct
67 Correct 1632 ms 6708 KB Output is correct
68 Correct 2075 ms 6648 KB Output is correct
69 Correct 2155 ms 6544 KB Output is correct
70 Correct 2111 ms 6476 KB Output is correct