Submission #580480

# Submission time Handle Problem Language Result Execution time Memory
580480 2022-06-21T10:24:10 Z temporary_juggernaut Global Warming (CEOI18_glo) C++14
100 / 100
403 ms 107888 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef juggernaut
    #define printl(args...) printf(args)
#else
    #define printl(args...) 0
#endif
int n,x;
int a[200005];
int inf=1e9+5;
struct node{
	int l,r,val;
	node(){
		l=r=val=0;
	}
};
struct SegmentTree{
	vector<node>tree;
	void build(){
		tree.clear();
		tree.push_back(node());
		tree.push_back(node());
	}
	int get(int v,int l,int r,int ql,int qr){
		if(qr<l||r<ql)return 0;
		if(!v)return 0;
		if(ql<=l&&r<=qr)return tree[v].val;
		int mid=(l+r)>>1;
		return max(get(tree[v].l,l,mid,ql,qr),get(tree[v].r,mid+1,r,ql,qr));
	}
	void update(int v,int l,int r,int pos,int val){
		umax(tree[v].val,val);
		int mid=(l+r)>>1;
		if(l==r)return;
		if(pos<=mid){
			if(!tree[v].l){
				tree[v].l=(int)tree.size();
				tree.push_back(node());
			}
			update(tree[v].l,l,mid,pos,val);
		}else{
			if(!tree[v].r){
				tree[v].r=(int)tree.size();
				tree.push_back(node());
			}
			update(tree[v].r,mid+1,r,pos,val);
		}
	}
}dp[2];
int pref[200005];
int suff[200005];
int main(){
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	int ans=0;
	dp[1].build();
	for(int i=n;i>0;i--){
		int cur=1;
		umax(cur,dp[1].get(1,0,inf,a[i]+1,inf)+1);
		dp[1].update(1,0,inf,a[i],cur);
		suff[i]=cur;
	}
	ans=suff[1];
  dp[0].build();
	for(int i=1;i<=n;i++){
		int cur=1;
		umax(cur,dp[0].get(1,0,inf,0,a[i]-1)+1);
		dp[0].update(1,0,inf,a[i],cur);
		pref[i]=cur;
		umax(ans,suff[i+1]+dp[0].get(1,0,inf,0,min(a[i+1]-1+x,inf)));
	}
	cout<<ans;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |  scanf("%d%d",&n,&x);
      |  ~~~~~^~~~~~~~~~~~~~
glo.cpp:66:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |  for(int i=1;i<=n;i++)scanf("%d",&a[i]);
      |                       ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 2 ms 1104 KB Output is correct
20 Correct 2 ms 1104 KB Output is correct
21 Correct 2 ms 1104 KB Output is correct
22 Correct 2 ms 1104 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 373 ms 107848 KB Output is correct
2 Correct 362 ms 107732 KB Output is correct
3 Correct 393 ms 107824 KB Output is correct
4 Correct 364 ms 107888 KB Output is correct
5 Correct 211 ms 56280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 28240 KB Output is correct
2 Correct 79 ms 28320 KB Output is correct
3 Correct 77 ms 28300 KB Output is correct
4 Correct 55 ms 14776 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 46 ms 4016 KB Output is correct
7 Correct 74 ms 25788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 156 ms 55232 KB Output is correct
2 Correct 156 ms 55180 KB Output is correct
3 Correct 330 ms 107788 KB Output is correct
4 Correct 178 ms 56232 KB Output is correct
5 Correct 79 ms 8308 KB Output is correct
6 Correct 138 ms 15896 KB Output is correct
7 Correct 144 ms 15916 KB Output is correct
8 Correct 121 ms 31832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 2 ms 1104 KB Output is correct
20 Correct 2 ms 1104 KB Output is correct
21 Correct 2 ms 1104 KB Output is correct
22 Correct 2 ms 1104 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 2 ms 724 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 373 ms 107848 KB Output is correct
28 Correct 362 ms 107732 KB Output is correct
29 Correct 393 ms 107824 KB Output is correct
30 Correct 364 ms 107888 KB Output is correct
31 Correct 211 ms 56280 KB Output is correct
32 Correct 81 ms 28240 KB Output is correct
33 Correct 79 ms 28320 KB Output is correct
34 Correct 77 ms 28300 KB Output is correct
35 Correct 55 ms 14776 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 46 ms 4016 KB Output is correct
38 Correct 74 ms 25788 KB Output is correct
39 Correct 156 ms 55232 KB Output is correct
40 Correct 156 ms 55180 KB Output is correct
41 Correct 330 ms 107788 KB Output is correct
42 Correct 178 ms 56232 KB Output is correct
43 Correct 79 ms 8308 KB Output is correct
44 Correct 138 ms 15896 KB Output is correct
45 Correct 144 ms 15916 KB Output is correct
46 Correct 121 ms 31832 KB Output is correct
47 Correct 167 ms 55228 KB Output is correct
48 Correct 170 ms 55200 KB Output is correct
49 Correct 403 ms 107784 KB Output is correct
50 Correct 200 ms 56192 KB Output is correct
51 Correct 119 ms 8912 KB Output is correct
52 Correct 210 ms 16224 KB Output is correct
53 Correct 159 ms 16248 KB Output is correct
54 Correct 150 ms 16304 KB Output is correct
55 Correct 260 ms 61832 KB Output is correct