답안 #1096445

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096445 2024-10-04T12:59:48 Z quangnamoiracvl_ralaidecu Global Warming (CEOI18_glo) C++14
22 / 100
331 ms 25792 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5, mod = 1e9;
 
int n,k,a[N],st[4*N], dp[N], dpv[N],l[N], b[N]; map<int,int> s;
 
void update(int id, int l, int r, int pos, int val){
    if(pos < l || pos > r) return;
    if(l == r){
       st[id] = val ;
       return;
    }
    int mid = (l+r)/2;
    update(id*2, l, mid, pos, val);
    update(id*2+1, mid+1, r, pos, val);
    st[id] = max(st[id*2] , st[id*2+1]) ;
}
 
int get(int id, int l, int r, int u, int v){
    if(r < u || l > v) return 0;
    if(l >= u && r <= v) return st[id];
 
    int mid = (l+r)/2;
    return max(get(id*2, l, mid, u, v) , get(id*2+1, mid+1, r, u, v)) ;
}
 
signed main()   
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0); 
    cin >> n >> k; for ( int i = 1; i <= n; i++ ) 
      {
        cin >> a[i]; 
        s[a[i]] = 1;
      }
      s[k]++;
    int d = 0; 
    for ( auto v : s ) {
        d++;
        s[v.first] = d;
    }
    k = s[k];
    for ( int i = 1; i <= n; i++ ) {
        a[i] = s[a[i]];
        // yêu thảo nguyên vl
    }
    int ans = -1;
    for ( int i = 1; i <= n; i++ ) {
        dp[i] = get(1,1,d,1,a[i] - 1) + 1;
        update(1,1,d,a[i],dp[i]);
    }
   // for ( int i = 1; i <= n; i++ ) cout << dp[i] << " "; cout << endl;
    for ( int i = 1; i <= 4 * N; i++ ) st[i] = 0;
    for ( int i = n; i >= 1; i-- )
        {
            dpv[i] = get( 1,1,n,a[i] + 1, n) + 1;
            ans = max( ans, dp[i] + get( 1, 1, n, a[i] - k + 1, n ) );
            update( 1, 1, n, a[i] , dpv[i] );
            
        }
       // for ( int i = 1; i <= n; i++ ) cout << dpv[i] << " "; cout << endl;
    cout << ans;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:54:46: warning: iteration 800019 invokes undefined behavior [-Waggressive-loop-optimizations]
   54 |     for ( int i = 1; i <= 4 * N; i++ ) st[i] = 0;
      |                                        ~~~~~~^~~
glo.cpp:54:24: note: within this loop
   54 |     for ( int i = 1; i <= 4 * N; i++ ) st[i] = 0;
      |                      ~~^~~~~~~~
glo.cpp:54:46: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [6400160, 6400167] is out of the bounds [0, 6400160] of object 'st' with type 'long long int [800020]' [-Warray-bounds]
   54 |     for ( int i = 1; i <= 4 * N; i++ ) st[i] = 0;
      |                                        ~~~~~~^~~
glo.cpp:6:14: note: 'st' declared here
    6 | int n,k,a[N],st[4*N], dp[N], dpv[N],l[N], b[N]; map<int,int> s;
      |              ^~
glo.cpp:54:46: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [6400160, 6400167] is out of the bounds [0, 6400160] of object 'st' with type 'long long int [800020]' [-Warray-bounds]
   54 |     for ( int i = 1; i <= 4 * N; i++ ) st[i] = 0;
      |                                        ~~~~~~^~~
glo.cpp:6:14: note: 'st' declared here
    6 | int n,k,a[N],st[4*N], dp[N], dpv[N],l[N], b[N]; map<int,int> s;
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6604 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 3 ms 6748 KB Output is correct
6 Correct 3 ms 6744 KB Output is correct
7 Correct 3 ms 6628 KB Output is correct
8 Correct 3 ms 6604 KB Output is correct
9 Correct 3 ms 6748 KB Output is correct
10 Correct 3 ms 6604 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6604 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 3 ms 6748 KB Output is correct
6 Correct 3 ms 6744 KB Output is correct
7 Correct 3 ms 6628 KB Output is correct
8 Correct 3 ms 6604 KB Output is correct
9 Correct 3 ms 6748 KB Output is correct
10 Correct 3 ms 6604 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 3 ms 6492 KB Output is correct
13 Incorrect 3 ms 6492 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6604 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 3 ms 6748 KB Output is correct
6 Correct 3 ms 6744 KB Output is correct
7 Correct 3 ms 6628 KB Output is correct
8 Correct 3 ms 6604 KB Output is correct
9 Correct 3 ms 6748 KB Output is correct
10 Correct 3 ms 6604 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 3 ms 6492 KB Output is correct
13 Incorrect 3 ms 6492 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 331 ms 25680 KB Output is correct
2 Correct 298 ms 25680 KB Output is correct
3 Correct 292 ms 25684 KB Output is correct
4 Correct 295 ms 25792 KB Output is correct
5 Incorrect 153 ms 18636 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 11352 KB Output is correct
2 Correct 59 ms 11388 KB Output is correct
3 Correct 59 ms 11316 KB Output is correct
4 Correct 31 ms 9552 KB Output is correct
5 Correct 3 ms 6488 KB Output is correct
6 Correct 35 ms 9736 KB Output is correct
7 Incorrect 49 ms 11600 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 16208 KB Output is correct
2 Correct 128 ms 16212 KB Output is correct
3 Correct 290 ms 25684 KB Output is correct
4 Correct 132 ms 18680 KB Output is correct
5 Correct 91 ms 15784 KB Output is correct
6 Correct 159 ms 24148 KB Output is correct
7 Correct 175 ms 24912 KB Output is correct
8 Correct 103 ms 16208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6492 KB Output is correct
2 Correct 3 ms 6604 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 3 ms 6492 KB Output is correct
5 Correct 3 ms 6748 KB Output is correct
6 Correct 3 ms 6744 KB Output is correct
7 Correct 3 ms 6628 KB Output is correct
8 Correct 3 ms 6604 KB Output is correct
9 Correct 3 ms 6748 KB Output is correct
10 Correct 3 ms 6604 KB Output is correct
11 Correct 3 ms 6748 KB Output is correct
12 Correct 3 ms 6492 KB Output is correct
13 Incorrect 3 ms 6492 KB Output isn't correct
14 Halted 0 ms 0 KB -