Submission #1087428

# Submission time Handle Problem Language Result Execution time Memory
1087428 2024-09-12T17:12:05 Z Nika533 Global Warming (CEOI18_glo) C++14
100 / 100
439 ms 29384 KB
#pragma gcc diagnostic "-std=c++1z"
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
#define pii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
using namespace std;

const int N=2e5+5;
int n,m,T,k,x,dp0[N],dp1[N],big=1e18;

struct segmentTree {
     int t[N*4];
     void build(int v, int tl, int tr) {
          if (tl==tr) {
               t[v]=0; return;
          }
          int mid=(tl+tr)/2;
          build(v*2,tl,mid); build(v*2+1,mid+1,tr);
     }
     void update(int v, int tl, int tr, int ind, int val) {
          if (tl==tr) {
               t[v]=max(t[v],val); return;
          }
          int mid=(tl+tr)/2;
          if (ind<=mid) update(v*2,tl,mid,ind,val); 
          else update(v*2+1,mid+1,tr,ind,val);
          t[v]=max(t[v*2],t[v*2+1]);
     }
     int query(int v, int tl, int tr, int l, int r) {
          if (l>r) return 0;
          if (tl==l && tr==r) return t[v];
          int mid=(tl+tr)/2;
          return max(query(v*2,tl,mid,l,min(r,mid)),query(v*2+1,mid+1,tr,max(l,mid+1),r));
     }
} segtree0,segtree1;

void test_case() {
     cin>>n>>x;
     int arr[n+1]; vector<int> v; v.pb(0);
     for (int i=1; i<=n; i++) {
          cin>>arr[i]; v.pb(arr[i]);
     }
     sort(all(v));
     map<int,int> ind;
     for (int i=1; i<=n; i++) {
          if (ind[v[i]]==0) ind[v[i]]=i;
     }
     segtree0.build(1,1,n); segtree1.build(1,1,n);
     for (int i=1; i<=n; i++) {
          int val1=segtree0.query(1,1,n,1,ind[arr[i]]-1);
          int val2=segtree1.query(1,1,n,1,ind[arr[i]]-1);
          int l=1,r=n,idx=0;
          while (l<=r) {
               int mid=(l+r)/2;
               if (v[mid]<arr[i]+x) {
                    idx=mid; l=mid+1;
               }
               else {
                    r=mid-1;
               }
          }
          int val3=segtree0.query(1,1,n,1,idx);
          dp0[i]=val1+1; dp1[i]=max(val2+1,val3+1);
          segtree0.update(1,1,n,ind[arr[i]],dp0[i]);
          segtree1.update(1,1,n,ind[arr[i]],dp1[i]);
     }
     cout<<segtree1.query(1,1,n,1,n)<<endl;
}
main () {
	ios :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	T=1; 
	while (T--) test_case();
}

Compilation message

glo.cpp:1: warning: ignoring '#pragma gcc diagnostic' [-Wunknown-pragmas]
    1 | #pragma gcc diagnostic "-std=c++1z"
      | 
glo.cpp:74:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   74 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2512 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2512 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2512 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 439 ms 29328 KB Output is correct
2 Correct 412 ms 29380 KB Output is correct
3 Correct 426 ms 29216 KB Output is correct
4 Correct 427 ms 29384 KB Output is correct
5 Correct 159 ms 21740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 8560 KB Output is correct
2 Correct 80 ms 8660 KB Output is correct
3 Correct 83 ms 8656 KB Output is correct
4 Correct 34 ms 6876 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 39 ms 6796 KB Output is correct
7 Correct 64 ms 8660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 14868 KB Output is correct
2 Correct 153 ms 14908 KB Output is correct
3 Correct 364 ms 29380 KB Output is correct
4 Correct 143 ms 21700 KB Output is correct
5 Correct 104 ms 14468 KB Output is correct
6 Correct 184 ms 27588 KB Output is correct
7 Correct 190 ms 28204 KB Output is correct
8 Correct 126 ms 14796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 0 ms 2512 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2652 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 1 ms 2648 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 439 ms 29328 KB Output is correct
28 Correct 412 ms 29380 KB Output is correct
29 Correct 426 ms 29216 KB Output is correct
30 Correct 427 ms 29384 KB Output is correct
31 Correct 159 ms 21740 KB Output is correct
32 Correct 81 ms 8560 KB Output is correct
33 Correct 80 ms 8660 KB Output is correct
34 Correct 83 ms 8656 KB Output is correct
35 Correct 34 ms 6876 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 39 ms 6796 KB Output is correct
38 Correct 64 ms 8660 KB Output is correct
39 Correct 155 ms 14868 KB Output is correct
40 Correct 153 ms 14908 KB Output is correct
41 Correct 364 ms 29380 KB Output is correct
42 Correct 143 ms 21700 KB Output is correct
43 Correct 104 ms 14468 KB Output is correct
44 Correct 184 ms 27588 KB Output is correct
45 Correct 190 ms 28204 KB Output is correct
46 Correct 126 ms 14796 KB Output is correct
47 Correct 187 ms 14796 KB Output is correct
48 Correct 176 ms 14792 KB Output is correct
49 Correct 419 ms 29212 KB Output is correct
50 Correct 154 ms 21700 KB Output is correct
51 Correct 149 ms 20472 KB Output is correct
52 Correct 234 ms 28616 KB Output is correct
53 Correct 195 ms 28616 KB Output is correct
54 Correct 201 ms 29384 KB Output is correct
55 Correct 312 ms 29384 KB Output is correct