답안 #469241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469241 2021-08-31T08:35:02 Z AmirrezaM LIS (INOI20_lis) C++17
20 / 100
4000 ms 75700 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

#define vc vector
#define pb push_back
#define fr first
#define sc second

#define Heh ios::sync_with_stdio(false) , cin.tie(0)

#pragma GCC optimize ("Ofast" , "O2" , "unroll-loops")

const int MAXN = 1e6 + 16 , s = 1 << 20 , sq = 1.5e3 + 15.3;

int n , b[MAXN] , a[MAXN] , it[MAXN] , lis[MAXN] , ans;
set<int> lit[sq];
set<int>::iterator iter;

int segTree[s<<1] , lazy[s<<1];

void shift(int v){
  segTree[v<<1] += lazy[v];
  segTree[(v<<1)^1] += lazy[v];
  lazy[v<<1] += lazy[v];
  lazy[(v<<1)^1] += lazy[v];
  lazy[v] = 0;
}
int get(int v , int tl , int tr){
  if(tl == tr) return tl;
  shift(v);
  int mid = (tl + tr) >> 1;
  if(segTree[(v<<1)^1] == 0) return get((v<<1)^1 , mid+1 , tr);
  return get((v<<1) , tl , mid);
}
void upd(int v , int tl , int tr , int l , int r , int x){
  if(l > tr or r < tl) return;
  if(l <= tl and r >= tr){
	segTree[v] += x;
	lazy[v] += x;
	return;
  }
  shift(v);
  int mid = (tl + tr) >> 1;
  upd(v<<1 , tl , mid , l , r , x);
  upd((v<<1)^1 , mid+1 , tr , l , r , x);
  segTree[v] = min(segTree[v<<1] , segTree[(v<<1)^1]);
}

void upd(int id){
  set<int>::iterator iter = lit[lis[id]].lower_bound(id);
  while(1){
	if(iter != lit[lis[id]].end() and a[*iter] > a[id]){
	  int jd = *iter;
	  iter++;
	  lit[lis[id]].erase(jd);
	  lis[jd]++;
	  upd(jd);
	}
	else break;
  }
  lit[lis[id]].insert(id);
  ans = max(ans , lis[id]);
}

int main(){
  Heh;
  for(int i = 0 ; i < (s<<1) ; i++) segTree[i] = MAXN;
  
  cin >> n;
  for(int i = 0 ; i < n ; i++){
	int id;
	cin >> id >> b[i];
	id--;
	segTree[s+i] = i-id;
  }
  for(int i = s-1 ; i >= 1 ; i--){
	segTree[i] = min(segTree[i<<1] , segTree[(i<<1)^1]);
  }

  for(int i = 0 ; i < n ; i++){
	int id = get(1 , 0 , s-1);
	a[n-i-1] = b[id];
	it[id] = n-i-1;
	upd(1 , 0 , s-1 , id , n-1 , -1);
	upd(1 , 0 , s-1 , id , id , MAXN);
  }
  
  for(int i = 0 ; i < n ; i++){
	int id = it[i];
	lis[id] = 1;
	while(1){
	  iter = lit[lis[id]].lower_bound(id);
	  if(iter != lit[lis[id]].begin() and a[*(--iter)] < a[id]) lis[id]++;
	  else break;
	}
	upd(id);
	cout << ans << endl;
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8652 KB Output is correct
2 Correct 8 ms 8588 KB Output is correct
3 Correct 14 ms 8752 KB Output is correct
4 Correct 14 ms 8724 KB Output is correct
5 Correct 30 ms 8804 KB Output is correct
6 Correct 19 ms 8804 KB Output is correct
7 Correct 17 ms 8728 KB Output is correct
8 Correct 19 ms 8780 KB Output is correct
9 Correct 16 ms 8732 KB Output is correct
10 Correct 16 ms 8772 KB Output is correct
11 Correct 19 ms 8764 KB Output is correct
12 Correct 16 ms 8756 KB Output is correct
13 Correct 18 ms 8712 KB Output is correct
14 Correct 18 ms 8780 KB Output is correct
15 Correct 16 ms 8780 KB Output is correct
16 Correct 17 ms 8724 KB Output is correct
17 Correct 22 ms 8780 KB Output is correct
18 Correct 19 ms 8756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 8652 KB Output is correct
2 Correct 8 ms 8588 KB Output is correct
3 Correct 14 ms 8752 KB Output is correct
4 Correct 14 ms 8724 KB Output is correct
5 Correct 30 ms 8804 KB Output is correct
6 Correct 19 ms 8804 KB Output is correct
7 Correct 17 ms 8728 KB Output is correct
8 Correct 19 ms 8780 KB Output is correct
9 Correct 16 ms 8732 KB Output is correct
10 Correct 16 ms 8772 KB Output is correct
11 Correct 19 ms 8764 KB Output is correct
12 Correct 16 ms 8756 KB Output is correct
13 Correct 18 ms 8712 KB Output is correct
14 Correct 18 ms 8780 KB Output is correct
15 Correct 16 ms 8780 KB Output is correct
16 Correct 17 ms 8724 KB Output is correct
17 Correct 22 ms 8780 KB Output is correct
18 Correct 19 ms 8756 KB Output is correct
19 Correct 762 ms 21828 KB Output is correct
20 Correct 729 ms 22024 KB Output is correct
21 Correct 855 ms 21856 KB Output is correct
22 Correct 895 ms 22084 KB Output is correct
23 Correct 816 ms 21912 KB Output is correct
24 Correct 830 ms 22000 KB Output is correct
25 Correct 805 ms 22056 KB Output is correct
26 Correct 835 ms 22004 KB Output is correct
27 Correct 788 ms 21944 KB Output is correct
28 Correct 797 ms 21956 KB Output is correct
29 Correct 761 ms 21992 KB Output is correct
30 Correct 814 ms 22012 KB Output is correct
31 Correct 1000 ms 21964 KB Output is correct
32 Correct 1032 ms 22004 KB Output is correct
33 Correct 945 ms 22004 KB Output is correct
34 Correct 1022 ms 21940 KB Output is correct
35 Correct 962 ms 22064 KB Output is correct
36 Correct 964 ms 22004 KB Output is correct
37 Correct 950 ms 21928 KB Output is correct
38 Correct 1008 ms 22116 KB Output is correct
39 Correct 997 ms 21996 KB Output is correct
40 Correct 1104 ms 22024 KB Output is correct
41 Correct 607 ms 19040 KB Output is correct
42 Correct 109 ms 10692 KB Output is correct
43 Correct 637 ms 18880 KB Output is correct
44 Correct 513 ms 15744 KB Output is correct
45 Correct 64 ms 9752 KB Output is correct
46 Correct 19 ms 8852 KB Output is correct
47 Correct 305 ms 13492 KB Output is correct
48 Correct 200 ms 12104 KB Output is correct
49 Correct 53 ms 9372 KB Output is correct
50 Correct 19 ms 8908 KB Output is correct
51 Correct 174 ms 11764 KB Output is correct
52 Correct 518 ms 17316 KB Output is correct
53 Correct 429 ms 15856 KB Output is correct
54 Correct 436 ms 15132 KB Output is correct
55 Correct 93 ms 10236 KB Output is correct
56 Correct 346 ms 13848 KB Output is correct
57 Correct 168 ms 10988 KB Output is correct
58 Correct 125 ms 10720 KB Output is correct
59 Correct 37 ms 9200 KB Output is correct
60 Correct 531 ms 16400 KB Output is correct
61 Correct 13 ms 8708 KB Output is correct
62 Correct 232 ms 12440 KB Output is correct
63 Correct 124 ms 10852 KB Output is correct
64 Correct 371 ms 14208 KB Output is correct
65 Correct 334 ms 13760 KB Output is correct
66 Correct 84 ms 9992 KB Output is correct
67 Correct 257 ms 12588 KB Output is correct
68 Correct 160 ms 11292 KB Output is correct
69 Correct 308 ms 13636 KB Output is correct
70 Correct 75 ms 9796 KB Output is correct
71 Execution timed out 4094 ms 75700 KB Time limit exceeded
72 Halted 0 ms 0 KB -