답안 #921818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
921818 2024-02-04T10:53:12 Z StefanSebez Global Warming (CEOI18_glo) C++14
100 / 100
715 ms 36976 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=6*1e6+50;
const ll inf=1e9+50;
int root,nc,maks[N],lc[N],rc[N];
int pref[200050],suf[200050];
ll a[200050];
void Update(int &c,ll ss,ll se,int qind,int qval)
{
	if(!c) c=++nc;
	if(ss==se) {maks[c]=max(maks[c],qval);return;}
	ll mid=(ss+se)/2;if(ss+se<0) mid--;
	if(qind<=mid) Update(lc[c],ss,mid,qind,qval);
	else Update(rc[c],mid+1,se,qind,qval);
	maks[c]=max(maks[lc[c]],maks[rc[c]]);
}
int Get(int c,ll ss,ll se,ll qs,ll qe)
{
	if(qs>qe || !c) return 0;
	if(qs<=ss && se<=qe) return maks[c];
	if(qe<ss || se<qs) return 0;
	ll mid=(ss+se)/2;if(ss+se<0) mid--;
	return max(Get(lc[c],ss,mid,qs,qe),Get(rc[c],mid+1,se,qs,qe));
}
void CLEAR(){
	for(int i=0;i<=nc;i++) maks[i]=lc[i]=rc[i]=0;
	root=nc=0;
}
int main()
{
    int n;ll x;scanf("%i%lld",&n,&x);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++)
	{
		pref[i]=1+Get(root,0,inf,0,a[i]-1);
		Update(root,0,inf,a[i],pref[i]);
	}
	CLEAR();
	for(int i=n;i>=1;i--)
	{
		suf[i]=1+Get(root,0,inf,a[i]+1,inf);
		Update(root,0,inf,a[i],suf[i]);
	}
	CLEAR();
	/*for(int i=1;i<=n;i++) printf("%i ",pref[i]);
	printf("\n");
	for(int i=1;i<=n;i++) printf("%i ",suf[i]);
	printf("\n");*/
	int res=0;
	for(int i=1;i<=n;i++)
	{
		res=max(res,Get(root,0,2*inf,0,a[i]+x-1)+suf[i]);
		Update(root,0,2*inf,a[i],pref[i]);
		//printf("%i %i\n",i,res);
	}
	CLEAR();
	for(int i=n;i>=1;i--)
	{
		res=max(res,pref[i]+Get(root,0,2*inf,a[i]+1,2*inf));
		Update(root,0,2*inf,a[i]+x,suf[i]);
	}
	printf("%i\n",res);
    return 0;
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:32:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     int n;ll x;scanf("%i%lld",&n,&x);
      |                ~~~~~^~~~~~~~~~~~~~~~
glo.cpp:33:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
      |                           ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 3 ms 4700 KB Output is correct
20 Correct 3 ms 4744 KB Output is correct
21 Correct 3 ms 4700 KB Output is correct
22 Correct 3 ms 4696 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 2 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 620 ms 36968 KB Output is correct
2 Correct 624 ms 36944 KB Output is correct
3 Correct 641 ms 36976 KB Output is correct
4 Correct 642 ms 36976 KB Output is correct
5 Correct 300 ms 21420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 13088 KB Output is correct
2 Correct 108 ms 12880 KB Output is correct
3 Correct 107 ms 12884 KB Output is correct
4 Correct 74 ms 8532 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 75 ms 5592 KB Output is correct
7 Correct 92 ms 10384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 238 ms 21332 KB Output is correct
2 Correct 255 ms 21444 KB Output is correct
3 Correct 556 ms 36948 KB Output is correct
4 Correct 259 ms 21656 KB Output is correct
5 Correct 135 ms 6780 KB Output is correct
6 Correct 218 ms 9044 KB Output is correct
7 Correct 231 ms 9648 KB Output is correct
8 Correct 161 ms 16472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 3 ms 4700 KB Output is correct
20 Correct 3 ms 4744 KB Output is correct
21 Correct 3 ms 4700 KB Output is correct
22 Correct 3 ms 4696 KB Output is correct
23 Correct 2 ms 4444 KB Output is correct
24 Correct 2 ms 4444 KB Output is correct
25 Correct 2 ms 4444 KB Output is correct
26 Correct 2 ms 4444 KB Output is correct
27 Correct 620 ms 36968 KB Output is correct
28 Correct 624 ms 36944 KB Output is correct
29 Correct 641 ms 36976 KB Output is correct
30 Correct 642 ms 36976 KB Output is correct
31 Correct 300 ms 21420 KB Output is correct
32 Correct 120 ms 13088 KB Output is correct
33 Correct 108 ms 12880 KB Output is correct
34 Correct 107 ms 12884 KB Output is correct
35 Correct 74 ms 8532 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 75 ms 5592 KB Output is correct
38 Correct 92 ms 10384 KB Output is correct
39 Correct 238 ms 21332 KB Output is correct
40 Correct 255 ms 21444 KB Output is correct
41 Correct 556 ms 36948 KB Output is correct
42 Correct 259 ms 21656 KB Output is correct
43 Correct 135 ms 6780 KB Output is correct
44 Correct 218 ms 9044 KB Output is correct
45 Correct 231 ms 9648 KB Output is correct
46 Correct 161 ms 16472 KB Output is correct
47 Correct 256 ms 21324 KB Output is correct
48 Correct 261 ms 21452 KB Output is correct
49 Correct 715 ms 36968 KB Output is correct
50 Correct 310 ms 21648 KB Output is correct
51 Correct 192 ms 6928 KB Output is correct
52 Correct 290 ms 9552 KB Output is correct
53 Correct 228 ms 9296 KB Output is correct
54 Correct 246 ms 10320 KB Output is correct
55 Correct 410 ms 28104 KB Output is correct