답안 #153619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153619 2019-09-15T04:46:24 Z semiauto Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
1616 ms 262148 KB
#include <bits/stdc++.h>
using namespace std;
int n,m,i,j,l,r,ans;
int mas[1000001],par[1000001],val[1000001],ori[1000001],hey[3000001],pre[1000001][20];
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 a,int b) {
    int c=ori[b-a+1];
    return max(pre[a][c],pre[b-(1<<c)+1][c]);
}
int main() {
    for (i=1;i<20;i++)
        ori[(1<<i)]=i;
    for (i=1;i<1000001;i++)
        if (!ori[i])
            ori[i]=ori[i-1];
    cin>>n>>m;
    for (i=1;i<=n;i++) {
        cin>>mas[i];
        pre[i][0]=mas[i];
    }
    for (j=1;j<20;j++)
        for (i=1;(i+(1<<j)-1)<=n;i++)
            pre[i][j]=max(pre[i][j-1],pre[i+(1<<(j-1))][j-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,par[i]-1);
    /*for (i=1;i<=n;i++)
        cout<<val[i]<<" ";
    cout<<endl;*/
    for (i=0;i<v[0].size();i++)
        dfs(v[0][i]);
    while (cin>>l>>r>>m) {
        if (l==r) {
            cout<<"1"<<endl;
            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,r));
        if (ans>m)
            cout<<"0"<<endl;
        else
            cout<<"1"<<endl;
    }
}

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:48:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<v[0].size();i++)
              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 27768 KB Output is correct
2 Correct 31 ms 27768 KB Output is correct
3 Correct 33 ms 27768 KB Output is correct
4 Correct 34 ms 27896 KB Output is correct
5 Correct 32 ms 27768 KB Output is correct
6 Correct 34 ms 27896 KB Output is correct
7 Correct 34 ms 27868 KB Output is correct
8 Correct 34 ms 27896 KB Output is correct
9 Correct 34 ms 27896 KB Output is correct
10 Correct 33 ms 27900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 27768 KB Output is correct
2 Correct 31 ms 27768 KB Output is correct
3 Correct 33 ms 27768 KB Output is correct
4 Correct 34 ms 27896 KB Output is correct
5 Correct 32 ms 27768 KB Output is correct
6 Correct 34 ms 27896 KB Output is correct
7 Correct 34 ms 27868 KB Output is correct
8 Correct 34 ms 27896 KB Output is correct
9 Correct 34 ms 27896 KB Output is correct
10 Correct 33 ms 27900 KB Output is correct
11 Correct 45 ms 28212 KB Output is correct
12 Correct 48 ms 29092 KB Output is correct
13 Correct 52 ms 29304 KB Output is correct
14 Correct 59 ms 29304 KB Output is correct
15 Correct 59 ms 29324 KB Output is correct
16 Correct 60 ms 29432 KB Output is correct
17 Correct 56 ms 29240 KB Output is correct
18 Correct 92 ms 29304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1294 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 560 ms 56392 KB Output is correct
2 Correct 556 ms 56368 KB Output is correct
3 Correct 668 ms 60980 KB Output is correct
4 Correct 645 ms 61064 KB Output is correct
5 Correct 644 ms 60936 KB Output is correct
6 Correct 565 ms 60376 KB Output is correct
7 Correct 572 ms 60452 KB Output is correct
8 Correct 606 ms 58776 KB Output is correct
9 Correct 440 ms 29556 KB Output is correct
10 Correct 586 ms 58896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 27768 KB Output is correct
2 Correct 31 ms 27768 KB Output is correct
3 Correct 33 ms 27768 KB Output is correct
4 Correct 34 ms 27896 KB Output is correct
5 Correct 32 ms 27768 KB Output is correct
6 Correct 34 ms 27896 KB Output is correct
7 Correct 34 ms 27868 KB Output is correct
8 Correct 34 ms 27896 KB Output is correct
9 Correct 34 ms 27896 KB Output is correct
10 Correct 33 ms 27900 KB Output is correct
11 Correct 45 ms 28212 KB Output is correct
12 Correct 48 ms 29092 KB Output is correct
13 Correct 52 ms 29304 KB Output is correct
14 Correct 59 ms 29304 KB Output is correct
15 Correct 59 ms 29324 KB Output is correct
16 Correct 60 ms 29432 KB Output is correct
17 Correct 56 ms 29240 KB Output is correct
18 Correct 92 ms 29304 KB Output is correct
19 Correct 1307 ms 87496 KB Output is correct
20 Correct 1292 ms 87428 KB Output is correct
21 Correct 1223 ms 87192 KB Output is correct
22 Correct 1292 ms 87344 KB Output is correct
23 Correct 1286 ms 87320 KB Output is correct
24 Correct 1445 ms 96260 KB Output is correct
25 Correct 1577 ms 96360 KB Output is correct
26 Correct 1490 ms 96608 KB Output is correct
27 Correct 1547 ms 96732 KB Output is correct
28 Correct 1524 ms 96624 KB Output is correct
29 Correct 1485 ms 96824 KB Output is correct
30 Correct 1524 ms 96708 KB Output is correct
31 Correct 1569 ms 96724 KB Output is correct
32 Correct 1554 ms 96592 KB Output is correct
33 Correct 1616 ms 96684 KB Output is correct
34 Correct 1280 ms 96480 KB Output is correct
35 Correct 1288 ms 96380 KB Output is correct
36 Correct 1319 ms 96020 KB Output is correct
37 Correct 1303 ms 96088 KB Output is correct
38 Correct 1264 ms 96292 KB Output is correct
39 Correct 1348 ms 92172 KB Output is correct
40 Correct 1164 ms 72200 KB Output is correct
41 Correct 1221 ms 90764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 27768 KB Output is correct
2 Correct 31 ms 27768 KB Output is correct
3 Correct 33 ms 27768 KB Output is correct
4 Correct 34 ms 27896 KB Output is correct
5 Correct 32 ms 27768 KB Output is correct
6 Correct 34 ms 27896 KB Output is correct
7 Correct 34 ms 27868 KB Output is correct
8 Correct 34 ms 27896 KB Output is correct
9 Correct 34 ms 27896 KB Output is correct
10 Correct 33 ms 27900 KB Output is correct
11 Correct 45 ms 28212 KB Output is correct
12 Correct 48 ms 29092 KB Output is correct
13 Correct 52 ms 29304 KB Output is correct
14 Correct 59 ms 29304 KB Output is correct
15 Correct 59 ms 29324 KB Output is correct
16 Correct 60 ms 29432 KB Output is correct
17 Correct 56 ms 29240 KB Output is correct
18 Correct 92 ms 29304 KB Output is correct
19 Runtime error 1294 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
20 Halted 0 ms 0 KB -