답안 #469234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469234 2021-08-31T08:14:51 Z AmirrezaM LIS (INOI20_lis) C++17
20 / 100
4000 ms 67688 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

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];

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

int main(){
  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){
	  set<int>::iterator iter = lit[lis[id]].lower_bound(id);
	  if(iter != lit[lis[id]].begin() and a[*prev(iter)] < a[id]) lis[id]++;
	  else break;
	}
	upd(id);
	cout << ans << endl;
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8652 KB Output is correct
2 Correct 6 ms 8652 KB Output is correct
3 Correct 17 ms 8780 KB Output is correct
4 Correct 14 ms 8780 KB Output is correct
5 Correct 24 ms 8796 KB Output is correct
6 Correct 19 ms 8772 KB Output is correct
7 Correct 17 ms 8780 KB Output is correct
8 Correct 17 ms 8688 KB Output is correct
9 Correct 17 ms 8692 KB Output is correct
10 Correct 16 ms 8764 KB Output is correct
11 Correct 17 ms 8720 KB Output is correct
12 Correct 16 ms 8696 KB Output is correct
13 Correct 18 ms 8688 KB Output is correct
14 Correct 20 ms 8780 KB Output is correct
15 Correct 18 ms 8724 KB Output is correct
16 Correct 18 ms 8748 KB Output is correct
17 Correct 19 ms 8780 KB Output is correct
18 Correct 18 ms 8776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8652 KB Output is correct
2 Correct 6 ms 8652 KB Output is correct
3 Correct 17 ms 8780 KB Output is correct
4 Correct 14 ms 8780 KB Output is correct
5 Correct 24 ms 8796 KB Output is correct
6 Correct 19 ms 8772 KB Output is correct
7 Correct 17 ms 8780 KB Output is correct
8 Correct 17 ms 8688 KB Output is correct
9 Correct 17 ms 8692 KB Output is correct
10 Correct 16 ms 8764 KB Output is correct
11 Correct 17 ms 8720 KB Output is correct
12 Correct 16 ms 8696 KB Output is correct
13 Correct 18 ms 8688 KB Output is correct
14 Correct 20 ms 8780 KB Output is correct
15 Correct 18 ms 8724 KB Output is correct
16 Correct 18 ms 8748 KB Output is correct
17 Correct 19 ms 8780 KB Output is correct
18 Correct 18 ms 8776 KB Output is correct
19 Correct 836 ms 21832 KB Output is correct
20 Correct 795 ms 21928 KB Output is correct
21 Correct 852 ms 21808 KB Output is correct
22 Correct 910 ms 22104 KB Output is correct
23 Correct 864 ms 22044 KB Output is correct
24 Correct 905 ms 21932 KB Output is correct
25 Correct 887 ms 22024 KB Output is correct
26 Correct 855 ms 21888 KB Output is correct
27 Correct 868 ms 21944 KB Output is correct
28 Correct 919 ms 22028 KB Output is correct
29 Correct 890 ms 22020 KB Output is correct
30 Correct 846 ms 21980 KB Output is correct
31 Correct 1043 ms 21884 KB Output is correct
32 Correct 1105 ms 21956 KB Output is correct
33 Correct 1139 ms 21868 KB Output is correct
34 Correct 1056 ms 21956 KB Output is correct
35 Correct 1068 ms 21936 KB Output is correct
36 Correct 1041 ms 21940 KB Output is correct
37 Correct 1121 ms 21924 KB Output is correct
38 Correct 1084 ms 21888 KB Output is correct
39 Correct 1169 ms 22020 KB Output is correct
40 Correct 1042 ms 21964 KB Output is correct
41 Correct 638 ms 19020 KB Output is correct
42 Correct 115 ms 10612 KB Output is correct
43 Correct 648 ms 18956 KB Output is correct
44 Correct 485 ms 15724 KB Output is correct
45 Correct 69 ms 9780 KB Output is correct
46 Correct 19 ms 8800 KB Output is correct
47 Correct 288 ms 13508 KB Output is correct
48 Correct 208 ms 12100 KB Output is correct
49 Correct 50 ms 9376 KB Output is correct
50 Correct 19 ms 8836 KB Output is correct
51 Correct 181 ms 11716 KB Output is correct
52 Correct 520 ms 17268 KB Output is correct
53 Correct 433 ms 15840 KB Output is correct
54 Correct 384 ms 15004 KB Output is correct
55 Correct 92 ms 10220 KB Output is correct
56 Correct 359 ms 13892 KB Output is correct
57 Correct 152 ms 10884 KB Output is correct
58 Correct 133 ms 10648 KB Output is correct
59 Correct 45 ms 9192 KB Output is correct
60 Correct 550 ms 16324 KB Output is correct
61 Correct 13 ms 8732 KB Output is correct
62 Correct 247 ms 12320 KB Output is correct
63 Correct 134 ms 10600 KB Output is correct
64 Correct 372 ms 14272 KB Output is correct
65 Correct 329 ms 13556 KB Output is correct
66 Correct 90 ms 9988 KB Output is correct
67 Correct 261 ms 12580 KB Output is correct
68 Correct 173 ms 11204 KB Output is correct
69 Correct 340 ms 13420 KB Output is correct
70 Correct 96 ms 9796 KB Output is correct
71 Execution timed out 4070 ms 67688 KB Time limit exceeded
72 Halted 0 ms 0 KB -