답안 #744019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
744019 2023-05-18T07:16:36 Z salmon Weirdtree (RMI21_weirdtree) C++14
5 / 100
201 ms 39548 KB
#include "weirdtree.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> lst;

struct node{
	
	node *l,*r;
	int s,e,m;
	long long int v;
	pair<int,int> small;
	
	node(int S,int E){
		s = S;
		e = E;
		m = (s + e)/2;
		
		if(s == e){
			v = lst[s];
			small = make_pair(lst[s],-s); 
		}
		else{
			l = new node(s,m);
			r = new node(m + 1, e);
			
			small = max(l -> small, r -> small);
			v = l -> v + (long long int) r -> v; 
		}
	}
	
	long long int query(int S, int E){
		if(S <= s && e <= E){
			return v;
		}
		
		long long int V = 0;
		
		if(S <= m){
			V += l -> query(S,E);
		}
		if(m < E){
			V += r -> query(S,E);
		}
		
		return V;
	}
	
	pair<int,int> rmin(int S, int E){
		if(S <= s && e <= E){
			return small;
		}
		
		pair<int,int> V = make_pair(-1,0);
		
		if(S <= m) V = max(V,l -> rmin(S,E));
		if(m < E) V = max(V,r -> rmin(S,E));
		
		return V;
	}
	
	void update(int i, int k){
		if(s == e){
			v = k;
			small = make_pair(k,-s);
			return;
		}
		
		
		if(i <= m) l -> update(i,k);
		else r -> update(i,k);
			
		small = max(l -> small, r -> small);
		v = l -> v + (long long int) r -> v; 
		
	
	}
}*root;

void initialise(int N, int Q, int h[]) {
	for(int i = 0; i < N; i++){
		lst.push_back(h[i]);
	}
	
	root = new node(0,N - 1);
}
void cut(int l, int r, int k) {
	pair<int,int> ii = root -> rmin(l,r);
	
	if(ii.first == 0){
		return;
	}
	
	root -> update(-ii.second,ii.first - 1);
}
void magic(int i, int x) {
	root -> update(i,x);
}
long long int inspect(int l, int r) {
	return root -> query(l,r);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Incorrect 69 ms 11344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 201 ms 39548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Incorrect 69 ms 11344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Incorrect 69 ms 11344 KB Output isn't correct
4 Halted 0 ms 0 KB -