답안 #1093252

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093252 2024-09-26T11:04:39 Z ivaziva Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1786 ms 64424 KB
#include <bits/stdc++.h>

using namespace std;

#define MAXN 1000001

int n,m;
int w[MAXN];
int last[MAXN];
stack<pair<int,int>> st;
vector<pair<pair<int,int>,pair<int,int>>> queries;
int seg[MAXN*4];
int ans[MAXN];

void update(int node,int l,int r,int pos,int val)
{
    if (l==r) seg[node]=val;
    else
    {
        int mid=(l+r)/2;
        if (pos<=mid) update(2*node,l,mid,pos,val);
        else update(2*node+1,mid+1,r,pos,val);
        seg[node]=max(seg[2*node],seg[2*node+1]);
    }
}

int query(int node,int l,int r,int a,int b)
{
    if (a>b) return -INT_MAX;
    if (l==a and r==b) return seg[node];
    int mid=(l+r)/2;
    return max(query(2*node,l,mid,a,min(b,mid)),query(2*node+1,mid+1,r,max(a,mid+1),b));
}

int main()
{
    ios_base::sync_with_stdio(false);
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for (int i=1;i<=n;i++) cin>>w[i];
    for (int i=1;i<=n;i++)
    {
        while (st.size()!=0 and st.top().first<=w[i]) st.pop();
        if (st.size()==0) last[i]=-1;
        else last[i]=st.top().second;
        st.push({w[i],i});
    }
    for (int i=0;i<m;i++)
    {
        int l,r,k;cin>>l>>r>>k;
        queries.push_back({{r,l},{k,i}});
    }
    sort(queries.begin(),queries.end());
    int trenr=0;
    for (int i=0;i<m;i++)
    {
        while (trenr<queries[i].first.first)
        {
            trenr++;
            if (last[trenr]==-1) continue;
            update(1,1,n,last[trenr],w[trenr]+w[last[trenr]]);
        }
        int sol=query(1,1,n,queries[i].first.second,queries[i].first.first);
        if (sol<=queries[i].second.first) ans[queries[i].second.second]=1;
        else ans[queries[i].second.second]=0;
    }
    for (int i=0;i<m;i++) cout<<ans[i]<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2488 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2488 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 5 ms 4700 KB Output is correct
12 Correct 4 ms 2540 KB Output is correct
13 Correct 5 ms 2652 KB Output is correct
14 Correct 9 ms 2652 KB Output is correct
15 Correct 8 ms 2652 KB Output is correct
16 Correct 8 ms 2648 KB Output is correct
17 Correct 7 ms 2652 KB Output is correct
18 Correct 7 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1681 ms 39068 KB Output is correct
2 Correct 1698 ms 39072 KB Output is correct
3 Correct 1758 ms 39104 KB Output is correct
4 Correct 1786 ms 39072 KB Output is correct
5 Correct 1571 ms 30680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 169 ms 6084 KB Output is correct
2 Correct 153 ms 6056 KB Output is correct
3 Correct 149 ms 5080 KB Output is correct
4 Correct 145 ms 6724 KB Output is correct
5 Correct 145 ms 5076 KB Output is correct
6 Correct 139 ms 5080 KB Output is correct
7 Correct 142 ms 6864 KB Output is correct
8 Correct 140 ms 6852 KB Output is correct
9 Correct 132 ms 4648 KB Output is correct
10 Correct 142 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2488 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 5 ms 4700 KB Output is correct
12 Correct 4 ms 2540 KB Output is correct
13 Correct 5 ms 2652 KB Output is correct
14 Correct 9 ms 2652 KB Output is correct
15 Correct 8 ms 2652 KB Output is correct
16 Correct 8 ms 2648 KB Output is correct
17 Correct 7 ms 2652 KB Output is correct
18 Correct 7 ms 2648 KB Output is correct
19 Correct 320 ms 9660 KB Output is correct
20 Correct 319 ms 9552 KB Output is correct
21 Correct 327 ms 9664 KB Output is correct
22 Correct 332 ms 9664 KB Output is correct
23 Correct 337 ms 11060 KB Output is correct
24 Correct 301 ms 7592 KB Output is correct
25 Correct 297 ms 7744 KB Output is correct
26 Correct 316 ms 7616 KB Output is correct
27 Correct 300 ms 7616 KB Output is correct
28 Correct 318 ms 7672 KB Output is correct
29 Correct 300 ms 7620 KB Output is correct
30 Correct 307 ms 7608 KB Output is correct
31 Correct 305 ms 7732 KB Output is correct
32 Correct 308 ms 7724 KB Output is correct
33 Correct 316 ms 7616 KB Output is correct
34 Correct 331 ms 7632 KB Output is correct
35 Correct 299 ms 7552 KB Output is correct
36 Correct 302 ms 7616 KB Output is correct
37 Correct 304 ms 8900 KB Output is correct
38 Correct 311 ms 7616 KB Output is correct
39 Correct 300 ms 8380 KB Output is correct
40 Correct 265 ms 9056 KB Output is correct
41 Correct 294 ms 8980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2488 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 5 ms 4700 KB Output is correct
12 Correct 4 ms 2540 KB Output is correct
13 Correct 5 ms 2652 KB Output is correct
14 Correct 9 ms 2652 KB Output is correct
15 Correct 8 ms 2652 KB Output is correct
16 Correct 8 ms 2648 KB Output is correct
17 Correct 7 ms 2652 KB Output is correct
18 Correct 7 ms 2648 KB Output is correct
19 Correct 1681 ms 39068 KB Output is correct
20 Correct 1698 ms 39072 KB Output is correct
21 Correct 1758 ms 39104 KB Output is correct
22 Correct 1786 ms 39072 KB Output is correct
23 Correct 1571 ms 30680 KB Output is correct
24 Correct 169 ms 6084 KB Output is correct
25 Correct 153 ms 6056 KB Output is correct
26 Correct 149 ms 5080 KB Output is correct
27 Correct 145 ms 6724 KB Output is correct
28 Correct 145 ms 5076 KB Output is correct
29 Correct 139 ms 5080 KB Output is correct
30 Correct 142 ms 6864 KB Output is correct
31 Correct 140 ms 6852 KB Output is correct
32 Correct 132 ms 4648 KB Output is correct
33 Correct 142 ms 5076 KB Output is correct
34 Correct 320 ms 9660 KB Output is correct
35 Correct 319 ms 9552 KB Output is correct
36 Correct 327 ms 9664 KB Output is correct
37 Correct 332 ms 9664 KB Output is correct
38 Correct 337 ms 11060 KB Output is correct
39 Correct 301 ms 7592 KB Output is correct
40 Correct 297 ms 7744 KB Output is correct
41 Correct 316 ms 7616 KB Output is correct
42 Correct 300 ms 7616 KB Output is correct
43 Correct 318 ms 7672 KB Output is correct
44 Correct 300 ms 7620 KB Output is correct
45 Correct 307 ms 7608 KB Output is correct
46 Correct 305 ms 7732 KB Output is correct
47 Correct 308 ms 7724 KB Output is correct
48 Correct 316 ms 7616 KB Output is correct
49 Correct 331 ms 7632 KB Output is correct
50 Correct 299 ms 7552 KB Output is correct
51 Correct 302 ms 7616 KB Output is correct
52 Correct 304 ms 8900 KB Output is correct
53 Correct 311 ms 7616 KB Output is correct
54 Correct 300 ms 8380 KB Output is correct
55 Correct 265 ms 9056 KB Output is correct
56 Correct 294 ms 8980 KB Output is correct
57 Correct 1714 ms 39068 KB Output is correct
58 Correct 1695 ms 39204 KB Output is correct
59 Correct 1707 ms 39080 KB Output is correct
60 Correct 1703 ms 39072 KB Output is correct
61 Correct 1721 ms 38916 KB Output is correct
62 Correct 1680 ms 39020 KB Output is correct
63 Correct 1564 ms 30876 KB Output is correct
64 Correct 1539 ms 30900 KB Output is correct
65 Correct 1594 ms 33860 KB Output is correct
66 Correct 1623 ms 64296 KB Output is correct
67 Correct 1583 ms 64252 KB Output is correct
68 Correct 1567 ms 64416 KB Output is correct
69 Correct 1561 ms 64412 KB Output is correct
70 Correct 1648 ms 64300 KB Output is correct
71 Correct 1632 ms 64412 KB Output is correct
72 Correct 1582 ms 64424 KB Output is correct
73 Correct 1579 ms 60824 KB Output is correct
74 Correct 1555 ms 61832 KB Output is correct
75 Correct 1588 ms 60984 KB Output is correct
76 Correct 1529 ms 60828 KB Output is correct
77 Correct 1532 ms 61204 KB Output is correct
78 Correct 1553 ms 61092 KB Output is correct
79 Correct 1392 ms 49740 KB Output is correct
80 Correct 1508 ms 55480 KB Output is correct