답안 #1114333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114333 2024-11-18T15:16:51 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1132 ms 104144 KB
#include <bits/stdc++.h>
using namespace std;
vector<int>st,v,res;
void update(int i,int l,int r,int x,int k)
{
    if(l==r)
    {
        st[i]=k;
        return;
    }
    int m=(l+r)/2;
    if(x<=m)update(i*2,l,m,x,k);
    else update(i*2+1,m+1,r,x,k);
    st[i]=max(st[2*i],st[2*i+1]);
}
int gsum(int i,int l,int r,int tl,int tr)
{
    if(l>tr||tl>r||l>r)return 0;
    if(tl<=l&&r<=tr)return st[i];
    int m=(l+r)/2;
    return max(gsum(2*i,l,m,tl,tr),gsum(i*2+1,m+1,r,tl,tr));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m,a,b,c;
    cin>>n>>m;
    vector<pair<int,pair<int,int>>>q[n];
    res.resize(m);
    st.resize(4*n+1);
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v.push_back(a);
    }
    for(int i=0;i<m;i++)
    {
        cin>>a>>b>>c;
        q[b-1].push_back({i,{a-1,c}});
    }
    stack<int>s;
    for(int i=0;i<n;i++)
    {
        while(!s.empty())
        {
            if(v[s.top()]<=v[i])s.pop();
            else break;
        }
        if(!s.empty())update(1,0,n-1,s.top(),v[s.top()]+v[i]);
        s.push(i);
        for(int j=0;j<q[i].size();j++)
        {
            if(gsum(1,0,n-1,q[i][j].second.first,i)<=q[i][j].second.second)res[q[i][j].first]=1;
            else res[q[i][j].first]=0;
        }
    }
    for(int i=0;i<m;i++)
    {
        cout<<res[i]<<"\n";
    }
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int j=0;j<q[i].size();j++)
      |                     ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 848 KB Output is correct
12 Correct 3 ms 848 KB Output is correct
13 Correct 3 ms 848 KB Output is correct
14 Correct 4 ms 1016 KB Output is correct
15 Correct 4 ms 848 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 3 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1103 ms 102932 KB Output is correct
2 Correct 1132 ms 104144 KB Output is correct
3 Correct 963 ms 103800 KB Output is correct
4 Correct 1110 ms 103800 KB Output is correct
5 Correct 1074 ms 104000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 9232 KB Output is correct
2 Correct 68 ms 8972 KB Output is correct
3 Correct 70 ms 9200 KB Output is correct
4 Correct 71 ms 9416 KB Output is correct
5 Correct 65 ms 9420 KB Output is correct
6 Correct 53 ms 8816 KB Output is correct
7 Correct 55 ms 8720 KB Output is correct
8 Correct 55 ms 8968 KB Output is correct
9 Correct 26 ms 3676 KB Output is correct
10 Correct 55 ms 8904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 848 KB Output is correct
12 Correct 3 ms 848 KB Output is correct
13 Correct 3 ms 848 KB Output is correct
14 Correct 4 ms 1016 KB Output is correct
15 Correct 4 ms 848 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 3 ms 848 KB Output is correct
19 Correct 190 ms 20836 KB Output is correct
20 Correct 185 ms 20932 KB Output is correct
21 Correct 164 ms 20264 KB Output is correct
22 Correct 151 ms 20164 KB Output is correct
23 Correct 138 ms 20164 KB Output is correct
24 Correct 119 ms 20244 KB Output is correct
25 Correct 120 ms 20164 KB Output is correct
26 Correct 129 ms 20416 KB Output is correct
27 Correct 139 ms 20420 KB Output is correct
28 Correct 137 ms 20676 KB Output is correct
29 Correct 141 ms 20932 KB Output is correct
30 Correct 144 ms 20932 KB Output is correct
31 Correct 139 ms 21016 KB Output is correct
32 Correct 158 ms 21012 KB Output is correct
33 Correct 162 ms 20932 KB Output is correct
34 Correct 117 ms 19720 KB Output is correct
35 Correct 133 ms 19648 KB Output is correct
36 Correct 110 ms 19396 KB Output is correct
37 Correct 107 ms 19396 KB Output is correct
38 Correct 108 ms 19588 KB Output is correct
39 Correct 132 ms 19140 KB Output is correct
40 Correct 102 ms 15168 KB Output is correct
41 Correct 122 ms 19140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 848 KB Output is correct
12 Correct 3 ms 848 KB Output is correct
13 Correct 3 ms 848 KB Output is correct
14 Correct 4 ms 1016 KB Output is correct
15 Correct 4 ms 848 KB Output is correct
16 Correct 3 ms 728 KB Output is correct
17 Correct 4 ms 848 KB Output is correct
18 Correct 3 ms 848 KB Output is correct
19 Correct 1103 ms 102932 KB Output is correct
20 Correct 1132 ms 104144 KB Output is correct
21 Correct 963 ms 103800 KB Output is correct
22 Correct 1110 ms 103800 KB Output is correct
23 Correct 1074 ms 104000 KB Output is correct
24 Correct 77 ms 9232 KB Output is correct
25 Correct 68 ms 8972 KB Output is correct
26 Correct 70 ms 9200 KB Output is correct
27 Correct 71 ms 9416 KB Output is correct
28 Correct 65 ms 9420 KB Output is correct
29 Correct 53 ms 8816 KB Output is correct
30 Correct 55 ms 8720 KB Output is correct
31 Correct 55 ms 8968 KB Output is correct
32 Correct 26 ms 3676 KB Output is correct
33 Correct 55 ms 8904 KB Output is correct
34 Correct 190 ms 20836 KB Output is correct
35 Correct 185 ms 20932 KB Output is correct
36 Correct 164 ms 20264 KB Output is correct
37 Correct 151 ms 20164 KB Output is correct
38 Correct 138 ms 20164 KB Output is correct
39 Correct 119 ms 20244 KB Output is correct
40 Correct 120 ms 20164 KB Output is correct
41 Correct 129 ms 20416 KB Output is correct
42 Correct 139 ms 20420 KB Output is correct
43 Correct 137 ms 20676 KB Output is correct
44 Correct 141 ms 20932 KB Output is correct
45 Correct 144 ms 20932 KB Output is correct
46 Correct 139 ms 21016 KB Output is correct
47 Correct 158 ms 21012 KB Output is correct
48 Correct 162 ms 20932 KB Output is correct
49 Correct 117 ms 19720 KB Output is correct
50 Correct 133 ms 19648 KB Output is correct
51 Correct 110 ms 19396 KB Output is correct
52 Correct 107 ms 19396 KB Output is correct
53 Correct 108 ms 19588 KB Output is correct
54 Correct 132 ms 19140 KB Output is correct
55 Correct 102 ms 15168 KB Output is correct
56 Correct 122 ms 19140 KB Output is correct
57 Correct 1075 ms 104116 KB Output is correct
58 Correct 1065 ms 103952 KB Output is correct
59 Correct 1027 ms 102548 KB Output is correct
60 Correct 1031 ms 102584 KB Output is correct
61 Correct 964 ms 102328 KB Output is correct
62 Correct 924 ms 102380 KB Output is correct
63 Correct 666 ms 99432 KB Output is correct
64 Correct 630 ms 99144 KB Output is correct
65 Correct 855 ms 102580 KB Output is correct
66 Correct 751 ms 102232 KB Output is correct
67 Correct 876 ms 102324 KB Output is correct
68 Correct 875 ms 104112 KB Output is correct
69 Correct 905 ms 104120 KB Output is correct
70 Correct 859 ms 103860 KB Output is correct
71 Correct 990 ms 103812 KB Output is correct
72 Correct 941 ms 103860 KB Output is correct
73 Correct 576 ms 95164 KB Output is correct
74 Correct 573 ms 96160 KB Output is correct
75 Correct 546 ms 95452 KB Output is correct
76 Correct 600 ms 95416 KB Output is correct
77 Correct 588 ms 95160 KB Output is correct
78 Correct 767 ms 96084 KB Output is correct
79 Correct 595 ms 68788 KB Output is correct
80 Correct 835 ms 93268 KB Output is correct