답안 #92358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
92358 2019-01-02T15:17:24 Z Pajaraja Global Warming (CEOI18_glo) C++17
100 / 100
676 ms 19160 KB
#include <bits/stdc++.h>
#define MAXN 2000007
using namespace std;
int a[MAXN],v[MAXN],seg[2][4*MAXN],dp[2][MAXN];
map<int,int> m;
void upd(int k,int l,int r,int val,int pos,int ind)
{
    if(l==r) {seg[k][ind]=val; return;}
    int s=(l+r)/2;
    if(pos<=s) upd(k,l,s,val,pos,2*ind);
    else upd(k,s+1,r,val,pos,2*ind+1);
    seg[k][ind]=max(seg[k][2*ind],seg[k][2*ind+1]);
}
int nmax(int k,int l,int r,int lt,int rt,int ind)
{
    if(l>rt || r<lt) return 0;
    if(l>=lt && r<=rt) return seg[k][ind];
    int s=(l+r)/2;
    return max(nmax(k,l,s,lt,rt,2*ind),nmax(k,s+1,r,lt,rt,2*ind+1));
}
int binarna(int l,int r,int val)
{
    if(l==r) return l+1;
    int s=(l+r+1)/2;
    if(v[s]>=val) return binarna(l,s-1,val);
    return binarna(s,r,val);
}
int main() 
{
    int n,x;
    scanf("%d%d",&n,&x);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    for(int i=0;i<n;i++) v[i]=a[i];
    sort(v,v+n);
    for(int i=0;i<n;i++) m[v[i]]=i+1;
    for(int i=0;i<n;i++)
    {
        dp[1][i]=max(nmax(1,0,n,0,m[a[i]]-1,1),nmax(0,0,n,0,binarna(0,n-1,a[i]+x),1))+1;
        dp[0][i]=nmax(0,0,n,0,m[a[i]]-1,1)+1;
        upd(0,0,n,dp[0][i],m[a[i]],1);
        upd(1,0,n,dp[1][i],m[a[i]],1);
        if(i>0) dp[1][i]=max(dp[1][i],dp[1][i-1]);
    }
    printf("%d",dp[1][n-1]);
    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&x);
     ~~~~~^~~~~~~~~~~~~~
glo.cpp:32:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0;i<n;i++) scanf("%d",&a[i]);
                          ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 650 ms 19160 KB Output is correct
2 Correct 637 ms 19024 KB Output is correct
3 Correct 624 ms 19092 KB Output is correct
4 Correct 592 ms 19064 KB Output is correct
5 Correct 253 ms 11644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 4984 KB Output is correct
2 Correct 105 ms 5112 KB Output is correct
3 Correct 107 ms 5112 KB Output is correct
4 Correct 49 ms 3320 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 57 ms 3576 KB Output is correct
7 Correct 90 ms 4984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 245 ms 9684 KB Output is correct
2 Correct 245 ms 9720 KB Output is correct
3 Correct 581 ms 19144 KB Output is correct
4 Correct 211 ms 11640 KB Output is correct
5 Correct 142 ms 9268 KB Output is correct
6 Correct 269 ms 17812 KB Output is correct
7 Correct 274 ms 18296 KB Output is correct
8 Correct 169 ms 9720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 650 ms 19160 KB Output is correct
28 Correct 637 ms 19024 KB Output is correct
29 Correct 624 ms 19092 KB Output is correct
30 Correct 592 ms 19064 KB Output is correct
31 Correct 253 ms 11644 KB Output is correct
32 Correct 105 ms 4984 KB Output is correct
33 Correct 105 ms 5112 KB Output is correct
34 Correct 107 ms 5112 KB Output is correct
35 Correct 49 ms 3320 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 57 ms 3576 KB Output is correct
38 Correct 90 ms 4984 KB Output is correct
39 Correct 245 ms 9684 KB Output is correct
40 Correct 245 ms 9720 KB Output is correct
41 Correct 581 ms 19144 KB Output is correct
42 Correct 211 ms 11640 KB Output is correct
43 Correct 142 ms 9268 KB Output is correct
44 Correct 269 ms 17812 KB Output is correct
45 Correct 274 ms 18296 KB Output is correct
46 Correct 169 ms 9720 KB Output is correct
47 Correct 252 ms 9616 KB Output is correct
48 Correct 247 ms 9720 KB Output is correct
49 Correct 676 ms 19064 KB Output is correct
50 Correct 227 ms 11640 KB Output is correct
51 Correct 207 ms 12408 KB Output is correct
52 Correct 335 ms 18384 KB Output is correct
53 Correct 293 ms 18336 KB Output is correct
54 Correct 296 ms 18952 KB Output is correct
55 Correct 499 ms 19136 KB Output is correct