답안 #469233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469233 2021-08-31T08:14:09 Z AmirrezaM LIS (INOI20_lis) C++17
0 / 100
3 ms 588 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 << 3 , 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 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Runtime error 3 ms 588 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Runtime error 3 ms 588 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -