답안 #1093251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093251 2024-09-26T11:01:57 Z ivaziva Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
77 / 100
3000 ms 72600 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()
{
    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 1 ms 4444 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 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 2504 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 4444 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 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 2504 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2500 KB Output is correct
11 Correct 7 ms 4700 KB Output is correct
12 Correct 7 ms 2648 KB Output is correct
13 Correct 7 ms 2652 KB Output is correct
14 Correct 11 ms 4956 KB Output is correct
15 Correct 10 ms 2868 KB Output is correct
16 Correct 9 ms 4704 KB Output is correct
17 Correct 9 ms 2652 KB Output is correct
18 Correct 9 ms 2876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2300 ms 70500 KB Output is correct
2 Correct 2434 ms 71316 KB Output is correct
3 Correct 2299 ms 71064 KB Output is correct
4 Correct 2285 ms 71264 KB Output is correct
5 Correct 2165 ms 63128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 8124 KB Output is correct
2 Correct 189 ms 9660 KB Output is correct
3 Correct 182 ms 7100 KB Output is correct
4 Correct 183 ms 7104 KB Output is correct
5 Correct 184 ms 8588 KB Output is correct
6 Correct 179 ms 6852 KB Output is correct
7 Correct 180 ms 6848 KB Output is correct
8 Correct 174 ms 6748 KB Output is correct
9 Correct 149 ms 5952 KB Output is correct
10 Correct 172 ms 8380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 4444 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 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 2504 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2500 KB Output is correct
11 Correct 7 ms 4700 KB Output is correct
12 Correct 7 ms 2648 KB Output is correct
13 Correct 7 ms 2652 KB Output is correct
14 Correct 11 ms 4956 KB Output is correct
15 Correct 10 ms 2868 KB Output is correct
16 Correct 9 ms 4704 KB Output is correct
17 Correct 9 ms 2652 KB Output is correct
18 Correct 9 ms 2876 KB Output is correct
19 Correct 446 ms 16356 KB Output is correct
20 Correct 451 ms 17588 KB Output is correct
21 Correct 439 ms 17336 KB Output is correct
22 Correct 448 ms 15992 KB Output is correct
23 Correct 438 ms 16056 KB Output is correct
24 Correct 414 ms 15124 KB Output is correct
25 Correct 409 ms 15284 KB Output is correct
26 Correct 428 ms 14004 KB Output is correct
27 Correct 419 ms 14184 KB Output is correct
28 Correct 425 ms 15456 KB Output is correct
29 Correct 435 ms 15540 KB Output is correct
30 Correct 429 ms 14180 KB Output is correct
31 Correct 437 ms 15540 KB Output is correct
32 Correct 423 ms 14260 KB Output is correct
33 Correct 433 ms 15356 KB Output is correct
34 Correct 423 ms 15032 KB Output is correct
35 Correct 418 ms 13748 KB Output is correct
36 Correct 416 ms 13700 KB Output is correct
37 Correct 409 ms 14988 KB Output is correct
38 Correct 418 ms 13752 KB Output is correct
39 Correct 396 ms 13492 KB Output is correct
40 Correct 361 ms 11800 KB Output is correct
41 Correct 387 ms 13748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 4444 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 2396 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 2 ms 2504 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2500 KB Output is correct
11 Correct 7 ms 4700 KB Output is correct
12 Correct 7 ms 2648 KB Output is correct
13 Correct 7 ms 2652 KB Output is correct
14 Correct 11 ms 4956 KB Output is correct
15 Correct 10 ms 2868 KB Output is correct
16 Correct 9 ms 4704 KB Output is correct
17 Correct 9 ms 2652 KB Output is correct
18 Correct 9 ms 2876 KB Output is correct
19 Correct 2300 ms 70500 KB Output is correct
20 Correct 2434 ms 71316 KB Output is correct
21 Correct 2299 ms 71064 KB Output is correct
22 Correct 2285 ms 71264 KB Output is correct
23 Correct 2165 ms 63128 KB Output is correct
24 Correct 198 ms 8124 KB Output is correct
25 Correct 189 ms 9660 KB Output is correct
26 Correct 182 ms 7100 KB Output is correct
27 Correct 183 ms 7104 KB Output is correct
28 Correct 184 ms 8588 KB Output is correct
29 Correct 179 ms 6852 KB Output is correct
30 Correct 180 ms 6848 KB Output is correct
31 Correct 174 ms 6748 KB Output is correct
32 Correct 149 ms 5952 KB Output is correct
33 Correct 172 ms 8380 KB Output is correct
34 Correct 446 ms 16356 KB Output is correct
35 Correct 451 ms 17588 KB Output is correct
36 Correct 439 ms 17336 KB Output is correct
37 Correct 448 ms 15992 KB Output is correct
38 Correct 438 ms 16056 KB Output is correct
39 Correct 414 ms 15124 KB Output is correct
40 Correct 409 ms 15284 KB Output is correct
41 Correct 428 ms 14004 KB Output is correct
42 Correct 419 ms 14184 KB Output is correct
43 Correct 425 ms 15456 KB Output is correct
44 Correct 435 ms 15540 KB Output is correct
45 Correct 429 ms 14180 KB Output is correct
46 Correct 437 ms 15540 KB Output is correct
47 Correct 423 ms 14260 KB Output is correct
48 Correct 433 ms 15356 KB Output is correct
49 Correct 423 ms 15032 KB Output is correct
50 Correct 418 ms 13748 KB Output is correct
51 Correct 416 ms 13700 KB Output is correct
52 Correct 409 ms 14988 KB Output is correct
53 Correct 418 ms 13752 KB Output is correct
54 Correct 396 ms 13492 KB Output is correct
55 Correct 361 ms 11800 KB Output is correct
56 Correct 387 ms 13748 KB Output is correct
57 Correct 2305 ms 72576 KB Output is correct
58 Correct 2292 ms 72600 KB Output is correct
59 Correct 2322 ms 72340 KB Output is correct
60 Correct 2302 ms 72300 KB Output is correct
61 Correct 2324 ms 72344 KB Output is correct
62 Correct 2301 ms 72340 KB Output is correct
63 Correct 2189 ms 62360 KB Output is correct
64 Correct 2122 ms 62268 KB Output is correct
65 Execution timed out 3074 ms 53064 KB Time limit exceeded
66 Halted 0 ms 0 KB -