Submission #469212

# Submission time Handle Problem Language Result Execution time Memory
469212 2021-08-31T06:18:19 Z Millad LIS (INOI20_lis) C++14
100 / 100
2802 ms 226392 KB
/// In the name of god
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define F first
#define S second
#define pb push_back
#define debug(x) cerr << #x << " : " << x << '\n'
     
using namespace std;
typedef int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
     
const ll maxn = 1e6 + 5;

ll q, x[maxn], p[maxn], b[maxn], ind[maxn], seg[maxn * 4], dp[maxn], lis;
set <ll> A[maxn], B[maxn];
vector <ll> Qu;
inline ll get_ind(ll id, ll ps = 0, ll v = 1, ll s = 0, ll e = q){
	if(e - s == 1){
		seg[v] = 1;
		return s;
	}
	ll mid = (e + s) >> 1, lc = v << 1, rc = lc | 1, ind;
	if(ps + (mid - s) - seg[lc] < id)ind = get_ind(id, ps + (mid - s) - seg[lc], rc, mid, e);
	else ind = get_ind(id, ps, lc, s, mid);
	seg[v] = seg[lc] + seg[rc];
	return ind;
}
int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> q;
	for(ll i = 0; i < q; i ++)cin >> p[i] >> x[i];
	for(ll i = q - 1; i >= 0; i --){
		ind[i] = get_ind(p[i]);
		b[ind[i]] = x[i];
	}
	set<ll>::iterator pnt;
	for(ll i = 0; i < q; i ++){
		ll id = ind[i], d = 0;
		A[x[i]].insert(id);
		for(ll j = 1; j < x[i]; j ++){
			if(A[j].empty())continue;
			if(*A[j].begin() > id)continue;
			if(*A[j].rbegin() < id){
              d = max(d, dp[*A[j].rbegin()]);
              continue;
            }	
          	pnt = A[j].upper_bound(id);
			pnt --; d = max(d, dp[*pnt]);
		}
      	d ++;
		dp[id] = d; B[d].insert(id);
		Qu.pb(id); lis = max(lis, d);
		while(Qu.size()){
			ll id2 = Qu.back(); Qu.pop_back();
			pnt = B[dp[id2]].lower_bound(id2);
			vector <ll> vec;
			while(true){
				pnt ++;
				if(pnt == B[dp[id2]].end())break;
				if(b[*pnt] < b[id2])break;
				if(b[*pnt] == b[id2])break;
				vec.pb(*pnt);
			}
			for(ll j : vec){
				B[dp[j]].erase(j);
				dp[j] ++; lis = max(lis, dp[j]);
				B[dp[j]].insert(j); Qu.pb(j); 
			}
		}
		cout << lis << '\n';
	}
}	

Compilation message

Main.cpp:4: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    4 | #pragma GCC optimization ("O3")
      | 
Main.cpp:5: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    5 | #pragma GCC optimization ("unroll-loops")
      |
# Verdict Execution time Memory Grader output
1 Correct 59 ms 94152 KB Output is correct
2 Correct 51 ms 94212 KB Output is correct
3 Correct 59 ms 94420 KB Output is correct
4 Correct 56 ms 94520 KB Output is correct
5 Correct 76 ms 94528 KB Output is correct
6 Correct 70 ms 94504 KB Output is correct
7 Correct 63 ms 94528 KB Output is correct
8 Correct 70 ms 94456 KB Output is correct
9 Correct 68 ms 94532 KB Output is correct
10 Correct 59 ms 94416 KB Output is correct
11 Correct 62 ms 94428 KB Output is correct
12 Correct 64 ms 94416 KB Output is correct
13 Correct 61 ms 94508 KB Output is correct
14 Correct 73 ms 94424 KB Output is correct
15 Correct 70 ms 94620 KB Output is correct
16 Correct 70 ms 94488 KB Output is correct
17 Correct 63 ms 94488 KB Output is correct
18 Correct 59 ms 94472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 94152 KB Output is correct
2 Correct 51 ms 94212 KB Output is correct
3 Correct 59 ms 94420 KB Output is correct
4 Correct 56 ms 94520 KB Output is correct
5 Correct 76 ms 94528 KB Output is correct
6 Correct 70 ms 94504 KB Output is correct
7 Correct 63 ms 94528 KB Output is correct
8 Correct 70 ms 94456 KB Output is correct
9 Correct 68 ms 94532 KB Output is correct
10 Correct 59 ms 94416 KB Output is correct
11 Correct 62 ms 94428 KB Output is correct
12 Correct 64 ms 94416 KB Output is correct
13 Correct 61 ms 94508 KB Output is correct
14 Correct 73 ms 94424 KB Output is correct
15 Correct 70 ms 94620 KB Output is correct
16 Correct 70 ms 94488 KB Output is correct
17 Correct 63 ms 94488 KB Output is correct
18 Correct 59 ms 94472 KB Output is correct
19 Correct 216 ms 117364 KB Output is correct
20 Correct 285 ms 117464 KB Output is correct
21 Correct 486 ms 117752 KB Output is correct
22 Correct 590 ms 117412 KB Output is correct
23 Correct 386 ms 117576 KB Output is correct
24 Correct 371 ms 117480 KB Output is correct
25 Correct 383 ms 117536 KB Output is correct
26 Correct 403 ms 117528 KB Output is correct
27 Correct 464 ms 117360 KB Output is correct
28 Correct 409 ms 117420 KB Output is correct
29 Correct 400 ms 117436 KB Output is correct
30 Correct 396 ms 117404 KB Output is correct
31 Correct 791 ms 117520 KB Output is correct
32 Correct 788 ms 117572 KB Output is correct
33 Correct 856 ms 117484 KB Output is correct
34 Correct 665 ms 117552 KB Output is correct
35 Correct 752 ms 117556 KB Output is correct
36 Correct 840 ms 117364 KB Output is correct
37 Correct 780 ms 117656 KB Output is correct
38 Correct 761 ms 117380 KB Output is correct
39 Correct 783 ms 117484 KB Output is correct
40 Correct 817 ms 117568 KB Output is correct
41 Correct 254 ms 112952 KB Output is correct
42 Correct 82 ms 97812 KB Output is correct
43 Correct 413 ms 112696 KB Output is correct
44 Correct 349 ms 106644 KB Output is correct
45 Correct 78 ms 96120 KB Output is correct
46 Correct 80 ms 94652 KB Output is correct
47 Correct 164 ms 103036 KB Output is correct
48 Correct 135 ms 100284 KB Output is correct
49 Correct 74 ms 95624 KB Output is correct
50 Correct 59 ms 94688 KB Output is correct
51 Correct 116 ms 99684 KB Output is correct
52 Correct 294 ms 108976 KB Output is correct
53 Correct 253 ms 106848 KB Output is correct
54 Correct 221 ms 105516 KB Output is correct
55 Correct 85 ms 97032 KB Output is correct
56 Correct 231 ms 103688 KB Output is correct
57 Correct 114 ms 98228 KB Output is correct
58 Correct 125 ms 97832 KB Output is correct
59 Correct 70 ms 95184 KB Output is correct
60 Correct 334 ms 107648 KB Output is correct
61 Correct 53 ms 94404 KB Output is correct
62 Correct 213 ms 100676 KB Output is correct
63 Correct 109 ms 97836 KB Output is correct
64 Correct 234 ms 104152 KB Output is correct
65 Correct 207 ms 103236 KB Output is correct
66 Correct 85 ms 96664 KB Output is correct
67 Correct 173 ms 101004 KB Output is correct
68 Correct 134 ms 98908 KB Output is correct
69 Correct 230 ms 103056 KB Output is correct
70 Correct 81 ms 96196 KB Output is correct
71 Correct 2544 ms 217844 KB Output is correct
72 Correct 2495 ms 226392 KB Output is correct
73 Correct 2586 ms 226348 KB Output is correct
74 Correct 2503 ms 226272 KB Output is correct
75 Correct 2802 ms 226276 KB Output is correct
76 Correct 2504 ms 226260 KB Output is correct