답안 #118163

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118163 2019-06-18T09:38:13 Z davitmarg Global Warming (CEOI18_glo) C++17
100 / 100
1018 ms 31468 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <ctype.h>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;

struct item
{
	int val, key, mxval;
	LL prior;
	item* l;
	item* r;
	item(int v = 0, int k = 0, LL p = (rand() << 16) + rand())
	{
		mxval = val = v;
		key = k;
		prior = p;
		l = r = NULL;
	}
};

typedef item* pitem;

int getVal(pitem t)
{
	return (!t) ? 0 : t->mxval;
}

void update(pitem t)
{
	if (!t)
		return;
	t->mxval = max(t->val, max(getVal(t->l), getVal(t->r)));
}

void split(pitem t, int key, pitem& l, pitem& r)
{
	if (!t)
		l = r = NULL;
	else if (t->key > key)
	{
		split(t->l, key, l, t->l);
		r = t;
	}
	else
	{
		split(t->r, key, t->r, r);
		l = t;
	}
	update(t);
}

void insert(pitem& t, pitem it)
{
	if (!t)
		t = it;
	else if (it->prior > t->prior)
	{
		split(t, it->key, it->l, it->r);
		t = it;
	}
	else
		insert((it->key < t->key) ? t->l : t->r, it);
	update(t);
}

void merge(pitem& t, pitem l, pitem r)
{
	if (!l || !r)
		t = l ? l : r;
	else if (l->prior > r->prior)
	{
		merge(l->r, l->r, r);
		t = l;
	}
	else
	{
		merge(r->l, l, r->l);
		t = r;
	}
	update(t);
}

int get(pitem t,int key)
{
	pitem l, r;
	split(t, key, l, r);
	int res = getVal(l);
	merge(t, l, r);
	return res;
}

pitem t, tx;


int n, x, mx, a[200005];


int main()
{
	t = tx = NULL;
	cin >> n >> x;
	for (int i = 1; i <= n; i++)
		scanf("%d", a + i);
	for (int i = 1; i <= n; i++)
	{
		insert(tx, new item(get(tx, a[i] + x - 1) + 1, a[i] + x));
		insert(tx, new item(get(t, a[i] + x - 1) + 1, a[i] + x));
		insert(t, new item(get(t, a[i] - 1) + 1, a[i]));

		//add(1, 0, mx, a[i] + x, get(1, 0, mx, a[i] + x - 1) + 1);
		//add(1, 0, mx, a[i] + x, get(0, 0, mx, a[i] + x - 1) + 1);
		//add(0, 0, mx, a[i], get(0, 0, mx, a[i] - 1) + 1);
	}

	cout << getVal(tx) << endl;

	return 0;
}


/*

3 1
1 1 3

*/

Compilation message

glo.cpp: In function 'int main()':
glo.cpp:124:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a + i);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 512 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 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 512 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 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 992 ms 29420 KB Output is correct
2 Correct 985 ms 29432 KB Output is correct
3 Correct 890 ms 29404 KB Output is correct
4 Correct 945 ms 29340 KB Output is correct
5 Correct 250 ms 29288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 7512 KB Output is correct
2 Correct 148 ms 7544 KB Output is correct
3 Correct 170 ms 7544 KB Output is correct
4 Correct 60 ms 7544 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 52 ms 7544 KB Output is correct
7 Correct 98 ms 7544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 362 ms 14852 KB Output is correct
2 Correct 379 ms 14840 KB Output is correct
3 Correct 917 ms 29304 KB Output is correct
4 Correct 246 ms 29304 KB Output is correct
5 Correct 111 ms 14840 KB Output is correct
6 Correct 159 ms 27912 KB Output is correct
7 Correct 236 ms 27812 KB Output is correct
8 Correct 208 ms 14840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 512 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 2 ms 256 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 4 ms 512 KB Output is correct
23 Correct 3 ms 512 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 3 ms 384 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 992 ms 29420 KB Output is correct
28 Correct 985 ms 29432 KB Output is correct
29 Correct 890 ms 29404 KB Output is correct
30 Correct 945 ms 29340 KB Output is correct
31 Correct 250 ms 29288 KB Output is correct
32 Correct 155 ms 7512 KB Output is correct
33 Correct 148 ms 7544 KB Output is correct
34 Correct 170 ms 7544 KB Output is correct
35 Correct 60 ms 7544 KB Output is correct
36 Correct 2 ms 256 KB Output is correct
37 Correct 52 ms 7544 KB Output is correct
38 Correct 98 ms 7544 KB Output is correct
39 Correct 362 ms 14852 KB Output is correct
40 Correct 379 ms 14840 KB Output is correct
41 Correct 917 ms 29304 KB Output is correct
42 Correct 246 ms 29304 KB Output is correct
43 Correct 111 ms 14840 KB Output is correct
44 Correct 159 ms 27912 KB Output is correct
45 Correct 236 ms 27812 KB Output is correct
46 Correct 208 ms 14840 KB Output is correct
47 Correct 390 ms 15800 KB Output is correct
48 Correct 416 ms 15736 KB Output is correct
49 Correct 1018 ms 31468 KB Output is correct
50 Correct 257 ms 30460 KB Output is correct
51 Correct 172 ms 22904 KB Output is correct
52 Correct 238 ms 30724 KB Output is correct
53 Correct 159 ms 30584 KB Output is correct
54 Correct 217 ms 31224 KB Output is correct
55 Correct 513 ms 31364 KB Output is correct