답안 #430634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430634 2021-06-16T17:42:02 Z Runtime_error_ Global Warming (CEOI18_glo) C++14
100 / 100
1504 ms 29736 KB
#include <bits/stdc++.h>
#define ll long long
#define le node+node
#define ri node+node+1
#define mid (l+r)/2
using namespace std;
const int inf = 4e5+9;
int n,k,a[inf],cnt,tree[inf<<2],lis[inf],lds[inf];
map<int,int> mp;

void update(int node,int l,int r,int idx,int val){
    if(l == r)
        return void(tree[node] = max(tree[node],val));
    if(idx <= mid)
        update(le,l,mid,idx,val);
    else
        update(ri,mid+1,r,idx,val);
    tree[node] = max(tree[le],tree[ri]);
}

int query(int node,int l,int r,int x,int y){
    if(l>r || r<x || l>y || x>y)
        return 0;
    if(l>=x && r<=y)
        return tree[node];
    return max(query(le,l,mid,x,y),query(ri,mid+1,r,x,y));
}


int main(){

    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",a+i),mp[a[i]],mp[a[i]-k+1];

    for(auto &o:mp)
        o.second = ++cnt;

    for(int i=1;i<=n;i++){
        lis[i]  = 1 + query(1,1,cnt,1,mp[a[i]]-1);
        update(1,1,cnt,mp[a[i]],lis[i]);
        //cout<<lis[i]<<" ";
    }
    memset(tree,0,sizeof(tree));

    for(int i=n;i>=1;i--){
        lds[i] = 1 + query(1,1,cnt,mp[a[i]]+1,cnt);
        update(1,1,cnt,mp[a[i]],lds[i]);
    }
    int ans = 0;
    memset(tree,0,sizeof(tree));
    for(int i=n;i>=1;i--)
        ans = max(ans,lis[i] + query(1,1,cnt,mp[a[i]-k+1],mp[a[i]])),update(1,1,cnt,mp[a[i]],lds[i]);

    cout<<ans<<endl;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d%d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~
glo.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%d",a+i),mp[a[i]],mp[a[i]-k+1];
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6476 KB Output is correct
2 Correct 5 ms 6556 KB Output is correct
3 Correct 5 ms 6476 KB Output is correct
4 Correct 5 ms 6476 KB Output is correct
5 Correct 6 ms 6468 KB Output is correct
6 Correct 5 ms 6476 KB Output is correct
7 Correct 6 ms 6476 KB Output is correct
8 Correct 5 ms 6476 KB Output is correct
9 Correct 6 ms 6476 KB Output is correct
10 Correct 5 ms 6476 KB Output is correct
11 Correct 5 ms 6476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6476 KB Output is correct
2 Correct 5 ms 6556 KB Output is correct
3 Correct 5 ms 6476 KB Output is correct
4 Correct 5 ms 6476 KB Output is correct
5 Correct 6 ms 6468 KB Output is correct
6 Correct 5 ms 6476 KB Output is correct
7 Correct 6 ms 6476 KB Output is correct
8 Correct 5 ms 6476 KB Output is correct
9 Correct 6 ms 6476 KB Output is correct
10 Correct 5 ms 6476 KB Output is correct
11 Correct 5 ms 6476 KB Output is correct
12 Correct 5 ms 6556 KB Output is correct
13 Correct 5 ms 6476 KB Output is correct
14 Correct 5 ms 6576 KB Output is correct
15 Correct 5 ms 6572 KB Output is correct
16 Correct 6 ms 6476 KB Output is correct
17 Correct 5 ms 6476 KB Output is correct
18 Correct 6 ms 6476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6476 KB Output is correct
2 Correct 5 ms 6556 KB Output is correct
3 Correct 5 ms 6476 KB Output is correct
4 Correct 5 ms 6476 KB Output is correct
5 Correct 6 ms 6468 KB Output is correct
6 Correct 5 ms 6476 KB Output is correct
7 Correct 6 ms 6476 KB Output is correct
8 Correct 5 ms 6476 KB Output is correct
9 Correct 6 ms 6476 KB Output is correct
10 Correct 5 ms 6476 KB Output is correct
11 Correct 5 ms 6476 KB Output is correct
12 Correct 5 ms 6556 KB Output is correct
13 Correct 5 ms 6476 KB Output is correct
14 Correct 5 ms 6576 KB Output is correct
15 Correct 5 ms 6572 KB Output is correct
16 Correct 6 ms 6476 KB Output is correct
17 Correct 5 ms 6476 KB Output is correct
18 Correct 6 ms 6476 KB Output is correct
19 Correct 9 ms 6648 KB Output is correct
20 Correct 7 ms 6604 KB Output is correct
21 Correct 7 ms 6604 KB Output is correct
22 Correct 7 ms 6604 KB Output is correct
23 Correct 6 ms 6652 KB Output is correct
24 Correct 6 ms 6604 KB Output is correct
25 Correct 6 ms 6640 KB Output is correct
26 Correct 6 ms 6568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1285 ms 27652 KB Output is correct
2 Correct 1354 ms 29612 KB Output is correct
3 Correct 1311 ms 29712 KB Output is correct
4 Correct 1303 ms 29588 KB Output is correct
5 Correct 378 ms 19528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 207 ms 11840 KB Output is correct
2 Correct 219 ms 12332 KB Output is correct
3 Correct 272 ms 12328 KB Output is correct
4 Correct 96 ms 9824 KB Output is correct
5 Correct 6 ms 6476 KB Output is correct
6 Correct 93 ms 8488 KB Output is correct
7 Correct 169 ms 11544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 539 ms 17120 KB Output is correct
2 Correct 619 ms 17136 KB Output is correct
3 Correct 1504 ms 27684 KB Output is correct
4 Correct 548 ms 18272 KB Output is correct
5 Correct 294 ms 17256 KB Output is correct
6 Correct 549 ms 26624 KB Output is correct
7 Correct 553 ms 26624 KB Output is correct
8 Correct 392 ms 17120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 6476 KB Output is correct
2 Correct 5 ms 6556 KB Output is correct
3 Correct 5 ms 6476 KB Output is correct
4 Correct 5 ms 6476 KB Output is correct
5 Correct 6 ms 6468 KB Output is correct
6 Correct 5 ms 6476 KB Output is correct
7 Correct 6 ms 6476 KB Output is correct
8 Correct 5 ms 6476 KB Output is correct
9 Correct 6 ms 6476 KB Output is correct
10 Correct 5 ms 6476 KB Output is correct
11 Correct 5 ms 6476 KB Output is correct
12 Correct 5 ms 6556 KB Output is correct
13 Correct 5 ms 6476 KB Output is correct
14 Correct 5 ms 6576 KB Output is correct
15 Correct 5 ms 6572 KB Output is correct
16 Correct 6 ms 6476 KB Output is correct
17 Correct 5 ms 6476 KB Output is correct
18 Correct 6 ms 6476 KB Output is correct
19 Correct 9 ms 6648 KB Output is correct
20 Correct 7 ms 6604 KB Output is correct
21 Correct 7 ms 6604 KB Output is correct
22 Correct 7 ms 6604 KB Output is correct
23 Correct 6 ms 6652 KB Output is correct
24 Correct 6 ms 6604 KB Output is correct
25 Correct 6 ms 6640 KB Output is correct
26 Correct 6 ms 6568 KB Output is correct
27 Correct 1285 ms 27652 KB Output is correct
28 Correct 1354 ms 29612 KB Output is correct
29 Correct 1311 ms 29712 KB Output is correct
30 Correct 1303 ms 29588 KB Output is correct
31 Correct 378 ms 19528 KB Output is correct
32 Correct 207 ms 11840 KB Output is correct
33 Correct 219 ms 12332 KB Output is correct
34 Correct 272 ms 12328 KB Output is correct
35 Correct 96 ms 9824 KB Output is correct
36 Correct 6 ms 6476 KB Output is correct
37 Correct 93 ms 8488 KB Output is correct
38 Correct 169 ms 11544 KB Output is correct
39 Correct 539 ms 17120 KB Output is correct
40 Correct 619 ms 17136 KB Output is correct
41 Correct 1504 ms 27684 KB Output is correct
42 Correct 548 ms 18272 KB Output is correct
43 Correct 294 ms 17256 KB Output is correct
44 Correct 549 ms 26624 KB Output is correct
45 Correct 553 ms 26624 KB Output is correct
46 Correct 392 ms 17120 KB Output is correct
47 Correct 522 ms 18036 KB Output is correct
48 Correct 599 ms 18204 KB Output is correct
49 Correct 1468 ms 29736 KB Output is correct
50 Correct 351 ms 19548 KB Output is correct
51 Correct 375 ms 16124 KB Output is correct
52 Correct 525 ms 19720 KB Output is correct
53 Correct 670 ms 28996 KB Output is correct
54 Correct 665 ms 29692 KB Output is correct
55 Correct 805 ms 26588 KB Output is correct