Submission #744013

# Submission time Handle Problem Language Result Execution time Memory
744013 2023-05-18T07:12:36 Z salmon Weirdtree (RMI21_weirdtree) C++14
5 / 100
208 ms 39172 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);
	
	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);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 69 ms 11028 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 208 ms 39172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 69 ms 11028 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 69 ms 11028 KB Output isn't correct
4 Halted 0 ms 0 KB -