Submission #836455

# Submission time Handle Problem Language Result Execution time Memory
836455 2023-08-24T11:25:52 Z dshfjka Global Warming (CEOI18_glo) C++14
100 / 100
189 ms 14772 KB
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
int main()
{
	LL n,x;
	scanf("%lld %lld",&n,&x);
	LL arr[n+5];
	for(LL a=1;a<=n;a++)
	{
		scanf("%lld",&arr[a]);
	}
	vector<LL>lis,lds;
	LL pref[n+5],suff[n+5];
	for(LL a=1;a<=n;a++)
	{
	//	printf("a=%lld\n",a);
		if(lower_bound(lis.begin(),lis.end(),arr[a])!=lis.end())
		{
			lis[lower_bound(lis.begin(),lis.end(),arr[a])-lis.begin()]=arr[a];
		}
		else
		{
			lis.push_back(arr[a]);
		}
		pref[a]=lower_bound(lis.begin(),lis.end(),arr[a])-lis.begin()+1;
//		printf("pref[%lld]=%lld\n",a,pref[a]);
	}
//	printf("DOR\n");
	for(LL a=n;a>=1;a--)
	{
	//	printf("a=%lld\n",a);
		if(lower_bound(lds.begin(),lds.end(),-arr[a])!=lds.end())
		{
			lds[lower_bound(lds.begin(),lds.end(),-arr[a])-lds.begin()]=-arr[a];
		}
		else
		{
			lds.push_back(-arr[a]);
		}
		suff[a]=lower_bound(lds.begin(),lds.end(),-arr[a])-lds.begin()+1;
		//printf("suff[%lld]=%lld\n",a,suff[a]);
	}
//	for(LL a=1;a<=n;a++)printf("%lld ",pref[a]);
//	printf("\n");
//	for(LL a=n;a>=1;a--)printf("%lld ",suff[a]);
//	printf("\n");
	LL maks=pref[n];
	set<pair<LL,LL>>s;
	// t dan lds nya
	s.insert(mp(arr[n],suff[n]));
	for(LL a=n-1;a>=1;a--)
	{
		// jika t nya lebih besar maka hasilnya semakin kecil
		auto ambil = s.lower_bound(mp(arr[a]-x+1,0));
		if(ambil==s.end())maks=max(maks,pref[a]);
		else
		{
			pair<LL,LL>x=*ambil;
			maks=max(maks,pref[a]+x.se);
		}
		while(s.lower_bound(mp(arr[a],1e9))!=s.begin())
		{
			auto koko=--s.lower_bound(mp(arr[a],1e9));
			pair<LL,LL>jeje=*koko;
			if(jeje.second<=suff[a])
			{
				s.erase(jeje);
			}else break;
		}
		auto jeje=*s.lower_bound(mp(arr[a]-1,1e9));
		if(!s.empty() && s.lower_bound(mp(arr[a]-1,1e9))!=s.end() && jeje.second>=suff[a])
		{
			
		}else s.insert(mp(arr[a],suff[a]));
	}
	printf("%lld\n",maks);
}

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  scanf("%lld %lld",&n,&x);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
glo.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%lld",&arr[a]);
      |   ~~~~~^~~~~~~~~~~~~~~~
# 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 0 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 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 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 0 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 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 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 0 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 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 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 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 5032 KB Output is correct
2 Correct 181 ms 5032 KB Output is correct
3 Correct 170 ms 4980 KB Output is correct
4 Correct 189 ms 4988 KB Output is correct
5 Correct 138 ms 12756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 1484 KB Output is correct
2 Correct 38 ms 1468 KB Output is correct
3 Correct 43 ms 1452 KB Output is correct
4 Correct 30 ms 3368 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 28 ms 3428 KB Output is correct
7 Correct 28 ms 1476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 2660 KB Output is correct
2 Correct 81 ms 2648 KB Output is correct
3 Correct 175 ms 4984 KB Output is correct
4 Correct 144 ms 12800 KB Output is correct
5 Correct 64 ms 6468 KB Output is correct
6 Correct 70 ms 12180 KB Output is correct
7 Correct 98 ms 12076 KB Output is correct
8 Correct 58 ms 2712 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 0 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 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 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 1 ms 212 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 174 ms 5032 KB Output is correct
28 Correct 181 ms 5032 KB Output is correct
29 Correct 170 ms 4980 KB Output is correct
30 Correct 189 ms 4988 KB Output is correct
31 Correct 138 ms 12756 KB Output is correct
32 Correct 38 ms 1484 KB Output is correct
33 Correct 38 ms 1468 KB Output is correct
34 Correct 43 ms 1452 KB Output is correct
35 Correct 30 ms 3368 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 28 ms 3428 KB Output is correct
38 Correct 28 ms 1476 KB Output is correct
39 Correct 83 ms 2660 KB Output is correct
40 Correct 81 ms 2648 KB Output is correct
41 Correct 175 ms 4984 KB Output is correct
42 Correct 144 ms 12800 KB Output is correct
43 Correct 64 ms 6468 KB Output is correct
44 Correct 70 ms 12180 KB Output is correct
45 Correct 98 ms 12076 KB Output is correct
46 Correct 58 ms 2712 KB Output is correct
47 Correct 81 ms 3624 KB Output is correct
48 Correct 81 ms 3624 KB Output is correct
49 Correct 183 ms 6944 KB Output is correct
50 Correct 138 ms 13944 KB Output is correct
51 Correct 110 ms 12508 KB Output is correct
52 Correct 138 ms 14076 KB Output is correct
53 Correct 75 ms 13976 KB Output is correct
54 Correct 108 ms 14772 KB Output is correct
55 Correct 127 ms 6956 KB Output is correct