답안 #153679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153679 2019-09-15T06:16:30 Z semiauto Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
2084 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;
int n,m,i,j,l,r,ans,N=1024*1024;
int mas[1000001],par[1000001],val[1000001],hey[1000001],tree[2048*1024];
pair <int,int> p[1000001][20];
vector <int> v[1000001];
void dfs(int u) {
    int i;
    p[u][0]={par[u],val[u]};
    for (i=1;i<20;i++)
        if (p[p[u][i-1].first][i-1].first)
            p[u][i]={p[p[u][i-1].first][i-1].first,max(p[u][i-1].second,p[p[u][i-1].first][i-1].second)};
    for (i=0;i<(v[u].size());i++)
        dfs(v[u][i]);
}
int solve(int x,int y,int p,int l,int r) {
    if (l>y || x>r)
        return 0;
    if (l>=x && r<=y)
        return tree[p];
    return max(solve(x,y,2*p,l,(l+r)/2),solve(x,y,2*p+1,(l+r)/2+1,r));
}
void build_tree(int p) {
    if (p>=N) {
        if ((p-N+1)<=n)
            tree[p]=mas[p-N+1];
        return;
    }
    build_tree(2*p);
    build_tree(2*p+1);
    tree[p]=max(tree[2*p],tree[2*p+1]);
}
int main() {
    for (i=0;i<=1000000;i++)
        for (j=0;j<=19;j++)
    p[i][j]={0,0};
    cin>>n>>m;
    for (i=1;i<=n;i++)
        scanf("%d",&(mas[i]));
    build_tree(1);
    for (i=n;i>0;i--) {
        for (;r>0;r--)
            if (mas[hey[r]]>=mas[i])
                break;
        par[i]=hey[r];
        v[hey[r]].push_back(i);
        hey[++r]=i;
    }
    for (i=1;i<=n;i++)
        if (par[i]>(i+1))
            val[i]=mas[i]+solve(i+1+N-1,par[i]-1+N-1,1,N,2*N-1);
    for (i=0;i<(v[0].size());i++)
        dfs(v[0][i]);
    for (mas[0]=1;mas[0]<=m;mas[0]++) {
        scanf("%d %d %d",&l,&r,&j);
        if (l==r) {
            printf("1\n");
            continue;
        }
        ans=0;
        for (i=19;i>=0;i--)
            if (p[l][i].first && p[l][i].first<=r) {
                ans=max(ans,p[l][i].second);
                l=p[l][i].first;
            }
        if (r>l)
            ans=max(ans,mas[l]+solve(l+1+N-1,r+N-1,1,N,2*N-1));
        if (ans>j)
            printf("0\n");
        else
            printf("1\n");
    }
}

Compilation message

sortbooks.cpp: In function 'void dfs(int)':
sortbooks.cpp:13:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<(v[u].size());i++)
              ~^~~~~~~~~~~~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:52:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<(v[0].size());i++)
              ~^~~~~~~~~~~~~~
sortbooks.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&(mas[i]));
         ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&l,&r,&j);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 184508 KB Output is correct
2 Correct 168 ms 184444 KB Output is correct
3 Correct 166 ms 184544 KB Output is correct
4 Correct 167 ms 184440 KB Output is correct
5 Correct 170 ms 184696 KB Output is correct
6 Correct 166 ms 184440 KB Output is correct
7 Correct 167 ms 184496 KB Output is correct
8 Correct 167 ms 184568 KB Output is correct
9 Correct 166 ms 184568 KB Output is correct
10 Correct 167 ms 184520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 184508 KB Output is correct
2 Correct 168 ms 184444 KB Output is correct
3 Correct 166 ms 184544 KB Output is correct
4 Correct 167 ms 184440 KB Output is correct
5 Correct 170 ms 184696 KB Output is correct
6 Correct 166 ms 184440 KB Output is correct
7 Correct 167 ms 184496 KB Output is correct
8 Correct 167 ms 184568 KB Output is correct
9 Correct 166 ms 184568 KB Output is correct
10 Correct 167 ms 184520 KB Output is correct
11 Correct 197 ms 184556 KB Output is correct
12 Correct 171 ms 184672 KB Output is correct
13 Correct 173 ms 184792 KB Output is correct
14 Correct 172 ms 184700 KB Output is correct
15 Correct 172 ms 184696 KB Output is correct
16 Correct 172 ms 184824 KB Output is correct
17 Correct 174 ms 184784 KB Output is correct
18 Correct 172 ms 184824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1988 ms 218424 KB Output is correct
2 Correct 2033 ms 218464 KB Output is correct
3 Correct 2075 ms 218460 KB Output is correct
4 Correct 2084 ms 218620 KB Output is correct
5 Runtime error 868 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 312 ms 187896 KB Output is correct
2 Correct 298 ms 187904 KB Output is correct
3 Correct 367 ms 192740 KB Output is correct
4 Correct 376 ms 192596 KB Output is correct
5 Correct 346 ms 192440 KB Output is correct
6 Correct 276 ms 192248 KB Output is correct
7 Correct 272 ms 192316 KB Output is correct
8 Correct 308 ms 190556 KB Output is correct
9 Correct 213 ms 184676 KB Output is correct
10 Correct 305 ms 190784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 184508 KB Output is correct
2 Correct 168 ms 184444 KB Output is correct
3 Correct 166 ms 184544 KB Output is correct
4 Correct 167 ms 184440 KB Output is correct
5 Correct 170 ms 184696 KB Output is correct
6 Correct 166 ms 184440 KB Output is correct
7 Correct 167 ms 184496 KB Output is correct
8 Correct 167 ms 184568 KB Output is correct
9 Correct 166 ms 184568 KB Output is correct
10 Correct 167 ms 184520 KB Output is correct
11 Correct 197 ms 184556 KB Output is correct
12 Correct 171 ms 184672 KB Output is correct
13 Correct 173 ms 184792 KB Output is correct
14 Correct 172 ms 184700 KB Output is correct
15 Correct 172 ms 184696 KB Output is correct
16 Correct 172 ms 184824 KB Output is correct
17 Correct 174 ms 184784 KB Output is correct
18 Correct 172 ms 184824 KB Output is correct
19 Correct 514 ms 191244 KB Output is correct
20 Correct 507 ms 191376 KB Output is correct
21 Correct 457 ms 191320 KB Output is correct
22 Correct 460 ms 191352 KB Output is correct
23 Correct 452 ms 191388 KB Output is correct
24 Correct 514 ms 200480 KB Output is correct
25 Correct 499 ms 200568 KB Output is correct
26 Correct 559 ms 200572 KB Output is correct
27 Correct 620 ms 200540 KB Output is correct
28 Correct 609 ms 200604 KB Output is correct
29 Correct 588 ms 200520 KB Output is correct
30 Correct 593 ms 200496 KB Output is correct
31 Correct 608 ms 200812 KB Output is correct
32 Correct 668 ms 200776 KB Output is correct
33 Correct 614 ms 200696 KB Output is correct
34 Correct 417 ms 200544 KB Output is correct
35 Correct 411 ms 200696 KB Output is correct
36 Correct 432 ms 200720 KB Output is correct
37 Correct 408 ms 200664 KB Output is correct
38 Correct 431 ms 200612 KB Output is correct
39 Correct 525 ms 197472 KB Output is correct
40 Correct 425 ms 193984 KB Output is correct
41 Correct 486 ms 196728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 184508 KB Output is correct
2 Correct 168 ms 184444 KB Output is correct
3 Correct 166 ms 184544 KB Output is correct
4 Correct 167 ms 184440 KB Output is correct
5 Correct 170 ms 184696 KB Output is correct
6 Correct 166 ms 184440 KB Output is correct
7 Correct 167 ms 184496 KB Output is correct
8 Correct 167 ms 184568 KB Output is correct
9 Correct 166 ms 184568 KB Output is correct
10 Correct 167 ms 184520 KB Output is correct
11 Correct 197 ms 184556 KB Output is correct
12 Correct 171 ms 184672 KB Output is correct
13 Correct 173 ms 184792 KB Output is correct
14 Correct 172 ms 184700 KB Output is correct
15 Correct 172 ms 184696 KB Output is correct
16 Correct 172 ms 184824 KB Output is correct
17 Correct 174 ms 184784 KB Output is correct
18 Correct 172 ms 184824 KB Output is correct
19 Correct 1988 ms 218424 KB Output is correct
20 Correct 2033 ms 218464 KB Output is correct
21 Correct 2075 ms 218460 KB Output is correct
22 Correct 2084 ms 218620 KB Output is correct
23 Runtime error 868 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)