Submission #1008124

# Submission time Handle Problem Language Result Execution time Memory
1008124 2024-06-26T07:50:01 Z vjudge1 Global Warming (CEOI18_glo) C++17
75 / 100
510 ms 36180 KB
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=(1<<(int)log2(200000)+1);
int Tree[N*3+1],ans[200001],ans2[200001],arr[200001];
int l,r;
map <int,int> mp;

int find(int l1,int r1,int i){
    if(l1>r||r1<l) return 0;
    if(l1>=l&&r1<=r) return Tree[i];
    int mid=(l1+r1)/2;
    return max(find(l1,mid,i*2),find(mid+1,r1,i*2+1));
} 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,x;
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        mp[arr[i]]++;
        mp[arr[i]+x]++;
    }
    int k=1;
    for(auto [i,j]:mp){
        mp[i]=k;
        k++;
    }
    for(int i=n-1;i>=0;i--){
        l=mp[arr[i]]+1,r=k;
        ans[i]=find(0,N-1,1)+1;
        
        int indx=mp[arr[i]]+N;
        Tree[indx]=ans[i];
        indx/=2;
        while(indx!=0){
            Tree[indx]=max(Tree[indx*2],Tree[indx*2+1]);
            indx/=2;
        }
    }
    memset(Tree,0,sizeof Tree);
    for(int i=0;i<n;i++){
        l=1,r=mp[arr[i]+x]-1;
        ans2[i]=find(0,N-1,1)+1;
        
        l=1,r=mp[arr[i]]-1;
        int num=find(0,N-1,1)+1;
        
        int indx=mp[arr[i]]+N;
        Tree[indx]=num;
        indx/=2;
        while(indx!=0){
            Tree[indx]=max(Tree[indx*2],Tree[indx*2+1]);
            indx/=2;
        }    
    }
    // for(int i=0;i<n;i++) cout<<ans[i]<<" ";
    // cout<<endl;
    // for(int i=0;i<n;i++) cout<<ans2[i]<<" ";
    int mx=0;
    for(int i=0;i<n;i++) mx=max(mx,ans[i]+ans2[i]-1);
    cout<<mx<<endl;
    
    return 0;
}

Compilation message

glo.cpp:12:34: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   12 | const int N=(1<<(int)log2(200000)+1);
      |                 ~~~~~~~~~~~~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10584 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Correct 2 ms 11100 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 10600 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10584 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Correct 2 ms 11100 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 10600 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 3 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 3 ms 10588 KB Output is correct
15 Correct 2 ms 10716 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 4 ms 10840 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10584 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Correct 2 ms 11100 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 10600 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 3 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 3 ms 10588 KB Output is correct
15 Correct 2 ms 10716 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 4 ms 10840 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 4 ms 10844 KB Output is correct
20 Correct 4 ms 10840 KB Output is correct
21 Correct 4 ms 10844 KB Output is correct
22 Correct 3 ms 10584 KB Output is correct
23 Correct 3 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 3 ms 10588 KB Output is correct
26 Correct 3 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 457 ms 23968 KB Output is correct
2 Correct 396 ms 23660 KB Output is correct
3 Correct 414 ms 23632 KB Output is correct
4 Correct 426 ms 23812 KB Output is correct
5 Correct 231 ms 17488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 16920 KB Output is correct
2 Correct 106 ms 16948 KB Output is correct
3 Correct 103 ms 17128 KB Output is correct
4 Correct 56 ms 13904 KB Output is correct
5 Correct 2 ms 10584 KB Output is correct
6 Correct 65 ms 13900 KB Output is correct
7 Correct 85 ms 15952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 249 ms 23348 KB Output is correct
2 Correct 235 ms 23376 KB Output is correct
3 Correct 510 ms 36180 KB Output is correct
4 Correct 269 ms 23632 KB Output is correct
5 Correct 195 ms 23376 KB Output is correct
6 Correct 323 ms 34876 KB Output is correct
7 Correct 301 ms 35008 KB Output is correct
8 Correct 227 ms 23616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10584 KB Output is correct
2 Correct 3 ms 10588 KB Output is correct
3 Correct 2 ms 11100 KB Output is correct
4 Correct 2 ms 10588 KB Output is correct
5 Correct 2 ms 10588 KB Output is correct
6 Correct 2 ms 11100 KB Output is correct
7 Correct 2 ms 10600 KB Output is correct
8 Correct 2 ms 10588 KB Output is correct
9 Correct 2 ms 10588 KB Output is correct
10 Correct 2 ms 10588 KB Output is correct
11 Correct 2 ms 10588 KB Output is correct
12 Correct 3 ms 10588 KB Output is correct
13 Correct 2 ms 10588 KB Output is correct
14 Correct 3 ms 10588 KB Output is correct
15 Correct 2 ms 10716 KB Output is correct
16 Correct 2 ms 10588 KB Output is correct
17 Correct 4 ms 10840 KB Output is correct
18 Correct 2 ms 10584 KB Output is correct
19 Correct 4 ms 10844 KB Output is correct
20 Correct 4 ms 10840 KB Output is correct
21 Correct 4 ms 10844 KB Output is correct
22 Correct 3 ms 10584 KB Output is correct
23 Correct 3 ms 10588 KB Output is correct
24 Correct 2 ms 10588 KB Output is correct
25 Correct 3 ms 10588 KB Output is correct
26 Correct 3 ms 10588 KB Output is correct
27 Correct 457 ms 23968 KB Output is correct
28 Correct 396 ms 23660 KB Output is correct
29 Correct 414 ms 23632 KB Output is correct
30 Correct 426 ms 23812 KB Output is correct
31 Correct 231 ms 17488 KB Output is correct
32 Correct 99 ms 16920 KB Output is correct
33 Correct 106 ms 16948 KB Output is correct
34 Correct 103 ms 17128 KB Output is correct
35 Correct 56 ms 13904 KB Output is correct
36 Correct 2 ms 10584 KB Output is correct
37 Correct 65 ms 13900 KB Output is correct
38 Correct 85 ms 15952 KB Output is correct
39 Correct 249 ms 23348 KB Output is correct
40 Correct 235 ms 23376 KB Output is correct
41 Correct 510 ms 36180 KB Output is correct
42 Correct 269 ms 23632 KB Output is correct
43 Correct 195 ms 23376 KB Output is correct
44 Correct 323 ms 34876 KB Output is correct
45 Correct 301 ms 35008 KB Output is correct
46 Correct 227 ms 23616 KB Output is correct
47 Correct 228 ms 23264 KB Output is correct
48 Correct 232 ms 23380 KB Output is correct
49 Incorrect 485 ms 36176 KB Output isn't correct
50 Halted 0 ms 0 KB -