Submission #99094

# Submission time Handle Problem Language Result Execution time Memory
99094 2019-02-28T14:27:30 Z nishkarsh Global Warming (CEOI18_glo) C++14
100 / 100
634 ms 9848 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
#define fr(x,a,b,c) for(int x = a; x <= b; x+=c)
using namespace std;
ll powmod(ll base,ll exponent,ll mod){
	ll ans=1;base%=mod;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 2e5+1;
const int mod = 1e9+7;
struct data{
	int ind,val;
};
bool cmp(data a,data b){
	if(a.val==b.val) return(a.ind>b.ind);
	return (a.val<b.val);
}
data arr[upperlimit];
int ans[upperlimit];
int indices[upperlimit];
int temp[upperlimit];
int segtree[4*upperlimit];
int segtree2[4*upperlimit];
void update(int node,int i,int j,int ind,int val){
	if(i==j){
		segtree[node]=val;
		return;
	}
	int mid=(i+j)/2;
	if(ind<=mid) update(2*node,i,mid,ind,val);
	else update(2*node+1,mid+1,j,ind,val);
	segtree[node]=max(segtree[2*node],segtree[2*node+1]);
}
int query(int node,int i,int j,int l,int r){
	if((i>r)||(l>j)||(i>j)||(l>r)) return 0;
	if((i>=l)&&(j<=r)) return segtree[node];
	int mid=(i+j)/2;
	return max(query(2*node,i,mid,l,r),query(2*node+1,mid+1,j,l,r));
}
void update2(int node,int i,int j,int ind,int val){
	if(i==j){
		segtree2[node]=val;
		return;
	}
	int mid=(i+j)/2;
	if(ind<=mid) update2(2*node,i,mid,ind,val);
	else update2(2*node+1,mid+1,j,ind,val);
	segtree2[node]=max(segtree2[2*node],segtree2[2*node+1]);
}
int query2(int node,int i,int j,int l,int r){
	if((i>r)||(l>j)||(i>j)||(l>r)) return 0;
	if((i>=l)&&(j<=r)) return segtree2[node];
	int mid=(i+j)/2;
	return max(query2(2*node,i,mid,l,r),query2(2*node+1,mid+1,j,l,r));
}
int main(){
	int n,x;
	sd(n);sd(x);
	for(int i = 1; i <= n; i++){
		sd(arr[i].val);arr[i].ind=i;
	}
	temp[0]=INF;
	int mlen=0;
	for(int i = n; i >= 1; i--){
		if(temp[mlen]>arr[i].val){
			mlen++;
			temp[mlen]=arr[i].val;
			ans[i]=mlen;
			continue;
		}
		int l=0,r=mlen;
		while(r-l>1){
			int mid=(l+r)/2;
			if(temp[mid]<=arr[i].val) r=mid;
			else l=mid;
		}
		temp[r]=arr[i].val;
		ans[i]=r;
	}
	sort(arr+1,arr+n+1,cmp);
	for(int i = 1; i <= n; i++){
		int k=query(1,1,n,1,arr[i].ind);
		k++;
		update(1,1,n,arr[i].ind,k);
		update2(1,1,n,i,k);
		indices[arr[i].ind]=i;
	}
	int ans2=0;
	for(int i = n; i >= 1; i--){
		int l=indices[i],r=n+1;
		int k=arr[indices[i]].val;k+=x;
		update2(1,1,n,indices[i],0);
		while(r-l>1){
			int mid=(l+r)/2;
			if(arr[mid].val>=k) r=mid;
			else l=mid;
		}
		ans2=max(ans2,query2(1,1,n,1,l)+ans[i]);
	}
	pd(ans2);
	return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define sd(x) scanf("%d",&x)
               ~~~~~^~~~~~~~~
glo.cpp:86:2: note: in expansion of macro 'sd'
  sd(n);sd(x);
  ^~
glo.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define sd(x) scanf("%d",&x)
               ~~~~~^~~~~~~~~
glo.cpp:86:8: note: in expansion of macro 'sd'
  sd(n);sd(x);
        ^~
glo.cpp:12:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define sd(x) scanf("%d",&x)
               ~~~~~^~~~~~~~~
glo.cpp:88:3: note: in expansion of macro 'sd'
   sd(arr[i].val);arr[i].ind=i;
   ^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 3 ms 408 KB Output is correct
13 Correct 2 ms 408 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 3 ms 408 KB Output is correct
13 Correct 2 ms 408 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 634 ms 7720 KB Output is correct
2 Correct 552 ms 9700 KB Output is correct
3 Correct 545 ms 9640 KB Output is correct
4 Correct 536 ms 9596 KB Output is correct
5 Correct 239 ms 9160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 2192 KB Output is correct
2 Correct 70 ms 2624 KB Output is correct
3 Correct 77 ms 2680 KB Output is correct
4 Correct 52 ms 2552 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 41 ms 2660 KB Output is correct
7 Correct 67 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 165 ms 4012 KB Output is correct
2 Correct 174 ms 3932 KB Output is correct
3 Correct 360 ms 7608 KB Output is correct
4 Correct 203 ms 8056 KB Output is correct
5 Correct 82 ms 4344 KB Output is correct
6 Correct 149 ms 7728 KB Output is correct
7 Correct 157 ms 7864 KB Output is correct
8 Correct 104 ms 4004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 4 ms 384 KB Output is correct
12 Correct 3 ms 408 KB Output is correct
13 Correct 2 ms 408 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 5 ms 512 KB Output is correct
20 Correct 4 ms 384 KB Output is correct
21 Correct 4 ms 384 KB Output is correct
22 Correct 3 ms 384 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 3 ms 384 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 634 ms 7720 KB Output is correct
28 Correct 552 ms 9700 KB Output is correct
29 Correct 545 ms 9640 KB Output is correct
30 Correct 536 ms 9596 KB Output is correct
31 Correct 239 ms 9160 KB Output is correct
32 Correct 73 ms 2192 KB Output is correct
33 Correct 70 ms 2624 KB Output is correct
34 Correct 77 ms 2680 KB Output is correct
35 Correct 52 ms 2552 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 41 ms 2660 KB Output is correct
38 Correct 67 ms 2680 KB Output is correct
39 Correct 165 ms 4012 KB Output is correct
40 Correct 174 ms 3932 KB Output is correct
41 Correct 360 ms 7608 KB Output is correct
42 Correct 203 ms 8056 KB Output is correct
43 Correct 82 ms 4344 KB Output is correct
44 Correct 149 ms 7728 KB Output is correct
45 Correct 157 ms 7864 KB Output is correct
46 Correct 104 ms 4004 KB Output is correct
47 Correct 168 ms 4988 KB Output is correct
48 Correct 187 ms 4948 KB Output is correct
49 Correct 404 ms 9592 KB Output is correct
50 Correct 203 ms 9208 KB Output is correct
51 Correct 154 ms 8060 KB Output is correct
52 Correct 224 ms 9220 KB Output is correct
53 Correct 185 ms 9252 KB Output is correct
54 Correct 177 ms 9848 KB Output is correct
55 Correct 301 ms 9648 KB Output is correct