답안 #770543

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
770543 2023-07-01T12:55:53 Z parsadox2 LIS (INOI20_lis) C++11
100 / 100
1917 ms 163516 KB
#include <bits/stdc++.h>
#define pb 		push_back
#define F		first
#define S 		second
#define debug(x)    cout << #x << "= " << x << ", "
#define ll 		long long
#define fast 		ios::sync_with_stdio(false), cin.tie(0),  cout.tie(0)
#define SZ(x)         (int) x.size()
#define wall 		cout << endl;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 1e6 + 10;
int q , ar[maxn] , val[maxn] , ans , fbi[maxn];
vector <pair<int , int>> query;
set <int> st[maxn];
struct nod{
	pair<int , int> mn;
	int lzy;
} tree[maxn << 2];

void Build(int node = 1 , int nl = 0 , int nr = q)
{
	tree[node].lzy = 0;
	if(nl + 1 == nr)
	{
		tree[node].mn.F = ar[nl];  tree[node].mn.S = -nl;
		return;
	}
	int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
	Build(lc , nl , mid);  Build(rc , mid , nr);
	tree[node].mn = min(tree[lc].mn , tree[rc].mn);
}

void uplzy(int node , int lc , int rc)
{
	if(tree[node].lzy == 0)  return;
	tree[lc].lzy += tree[node].lzy;  tree[rc].lzy += tree[node].lzy;
	tree[lc].mn.F += tree[node].lzy;  tree[rc].mn.F += tree[node].lzy;
	tree[node].lzy = 0;
}

void Rem(int pos , int node = 1 , int nl = 0 , int nr = q)
{
	if(nl + 1 == nr)
	{
		tree[node].mn.F = maxn;
		return;
	}
	int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
	uplzy(node , lc , rc);
	if(pos < mid)  Rem(pos , lc , nl , mid);
	else Rem(pos , rc , mid , nr);
	tree[node].mn = min(tree[lc].mn , tree[rc].mn);
}

void Add(int pos , int node = 1 , int nl = 0 , int nr = q)
{
	if(nr <= pos)  return;
	if(nl >= pos)
	{
		tree[node].mn.F--;
		tree[node].lzy--;
		return;
	}
	int mid = (nl + nr) >> 1 , lc = node << 1 , rc = lc | 1;
	Add(pos , lc , nl , mid);  Add(pos , rc , mid , nr);
	tree[node].mn = min(tree[rc].mn , tree[lc].mn);
}

void add(int pos , int ind)
{
	if(st[ind].empty())
	{
		st[ind].insert(pos);
		ans = ind;
		return;
	}
	auto it = st[ind].end();  it--;
	if(*st[ind].begin() < pos)
	{
		if(*it > pos)
		{
			it = st[ind].upper_bound(pos);
			it--;
		}
		if(ar[*it] < ar[pos])
		{
			add(pos , ind + 1);
			return;
		}
		it++;
	}
	else
	{
		it = st[ind].begin();
	}
	vector <int> vec;
	while(it != st[ind].end())
	{
		int now = *it;
		if(ar[now] <= ar[pos])  break;
		it++;
		vec.pb(now);
	}
	for(auto u : vec)
	{
		st[ind].erase(u);
		add(u , ind + 1);
	}
	st[ind].insert(pos);
}

int32_t main()
{
	fast;
	cin >> q;
	for(int i = 0 ; i < q ; i++)  cin >> ar[i] >> val[i];
	Build();
	for(int i = 1 ; i <= q ; i++)
	{
		int pos = -tree[1].mn.S;
		fbi[pos] = i;
		ar[i] = val[pos];
		Rem(pos);
		Add(pos);
	}
	st[0].insert(0);
	for(int i = 0 ; i < q ; i++) 
	{
		add(fbi[i] , 1);
		cout << ans << '\n';
	}
	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 94164 KB Output is correct
2 Correct 40 ms 94160 KB Output is correct
3 Correct 42 ms 94424 KB Output is correct
4 Correct 41 ms 94368 KB Output is correct
5 Correct 50 ms 94404 KB Output is correct
6 Correct 47 ms 94408 KB Output is correct
7 Correct 47 ms 94340 KB Output is correct
8 Correct 44 ms 94360 KB Output is correct
9 Correct 49 ms 94388 KB Output is correct
10 Correct 49 ms 94388 KB Output is correct
11 Correct 52 ms 94440 KB Output is correct
12 Correct 45 ms 94412 KB Output is correct
13 Correct 49 ms 94424 KB Output is correct
14 Correct 46 ms 94300 KB Output is correct
15 Correct 45 ms 94408 KB Output is correct
16 Correct 46 ms 94308 KB Output is correct
17 Correct 46 ms 94304 KB Output is correct
18 Correct 46 ms 94420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 94164 KB Output is correct
2 Correct 40 ms 94160 KB Output is correct
3 Correct 42 ms 94424 KB Output is correct
4 Correct 41 ms 94368 KB Output is correct
5 Correct 50 ms 94404 KB Output is correct
6 Correct 47 ms 94408 KB Output is correct
7 Correct 47 ms 94340 KB Output is correct
8 Correct 44 ms 94360 KB Output is correct
9 Correct 49 ms 94388 KB Output is correct
10 Correct 49 ms 94388 KB Output is correct
11 Correct 52 ms 94440 KB Output is correct
12 Correct 45 ms 94412 KB Output is correct
13 Correct 49 ms 94424 KB Output is correct
14 Correct 46 ms 94300 KB Output is correct
15 Correct 45 ms 94408 KB Output is correct
16 Correct 46 ms 94308 KB Output is correct
17 Correct 46 ms 94304 KB Output is correct
18 Correct 46 ms 94420 KB Output is correct
19 Correct 156 ms 106872 KB Output is correct
20 Correct 163 ms 106900 KB Output is correct
21 Correct 280 ms 106100 KB Output is correct
22 Correct 336 ms 106292 KB Output is correct
23 Correct 261 ms 106828 KB Output is correct
24 Correct 247 ms 106908 KB Output is correct
25 Correct 286 ms 106864 KB Output is correct
26 Correct 246 ms 106856 KB Output is correct
27 Correct 257 ms 106932 KB Output is correct
28 Correct 250 ms 106884 KB Output is correct
29 Correct 258 ms 106816 KB Output is correct
30 Correct 257 ms 106904 KB Output is correct
31 Correct 372 ms 106908 KB Output is correct
32 Correct 369 ms 106956 KB Output is correct
33 Correct 360 ms 106776 KB Output is correct
34 Correct 368 ms 106956 KB Output is correct
35 Correct 366 ms 106920 KB Output is correct
36 Correct 383 ms 106848 KB Output is correct
37 Correct 375 ms 106836 KB Output is correct
38 Correct 371 ms 106844 KB Output is correct
39 Correct 369 ms 106796 KB Output is correct
40 Correct 391 ms 106940 KB Output is correct
41 Correct 130 ms 104156 KB Output is correct
42 Correct 57 ms 96172 KB Output is correct
43 Correct 226 ms 103576 KB Output is correct
44 Correct 215 ms 100556 KB Output is correct
45 Correct 57 ms 95308 KB Output is correct
46 Correct 44 ms 94504 KB Output is correct
47 Correct 109 ms 98892 KB Output is correct
48 Correct 88 ms 97472 KB Output is correct
49 Correct 51 ms 94924 KB Output is correct
50 Correct 44 ms 94400 KB Output is correct
51 Correct 83 ms 97128 KB Output is correct
52 Correct 185 ms 102432 KB Output is correct
53 Correct 148 ms 101124 KB Output is correct
54 Correct 134 ms 100344 KB Output is correct
55 Correct 62 ms 95704 KB Output is correct
56 Correct 152 ms 99432 KB Output is correct
57 Correct 83 ms 96460 KB Output is correct
58 Correct 78 ms 96132 KB Output is correct
59 Correct 50 ms 94800 KB Output is correct
60 Correct 210 ms 101536 KB Output is correct
61 Correct 42 ms 94288 KB Output is correct
62 Correct 114 ms 97724 KB Output is correct
63 Correct 80 ms 96212 KB Output is correct
64 Correct 156 ms 99484 KB Output is correct
65 Correct 147 ms 99000 KB Output is correct
66 Correct 65 ms 95564 KB Output is correct
67 Correct 117 ms 97856 KB Output is correct
68 Correct 90 ms 96716 KB Output is correct
69 Correct 139 ms 98764 KB Output is correct
70 Correct 64 ms 95368 KB Output is correct
71 Correct 1833 ms 163304 KB Output is correct
72 Correct 1841 ms 163448 KB Output is correct
73 Correct 1917 ms 163392 KB Output is correct
74 Correct 1826 ms 163392 KB Output is correct
75 Correct 1855 ms 163392 KB Output is correct
76 Correct 1841 ms 163516 KB Output is correct