Submission #1067953

# Submission time Handle Problem Language Result Execution time Memory
1067953 2024-08-21T06:01:48 Z 김은성(#11126) Weirdtree (RMI21_weirdtree) C++17
13 / 100
2000 ms 37116 KB
#include "weirdtree.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 300'009, SEGSZ = 1<<20;
ll H[MAXN];
int n;
pair<ll, int> mx[1<<20];
ll sum[1<<20];
void settree(int v, int l, int r){
	if(l==r){
		mx[v] = make_pair(H[l], -l);
		sum[v] = H[l];
	}
	else{
		int mid = (l+r)/2;
		settree(2*v, l, mid);
		settree(2*v+1, mid+1, r);
		mx[v] = max(mx[2*v], mx[2*v+1]);
		sum[v] = sum[2*v] + sum[2*v+1];
	}
}

void update(int v, int l, int r, int idx, ll val){
	if(l==r){
		mx[v] = make_pair(val, -l);
		sum[v] = val;
	}
	else{
		int mid = (l+r)/2;
		if(idx <= mid)
			update(2*v, l, mid, idx, val);
		else
			update(2*v+1, mid+1, r, idx, val);
		mx[v] = max(mx[2*v], mx[2*v+1]);
		sum[v] = sum[2*v] + sum[2*v+1];
	}
}

pair<ll, int> maxvalue(int v, int l, int r, int s, int e){
	if(e<l || r<s)
		return make_pair(-1, 0);
	if(s<=l && r<=e)
		return mx[v];
	int mid = (l+r)/2;
	return max(maxvalue(2*v, l, mid, s, e), maxvalue(2*v+1, mid+1, r, s, e));
}

ll rangesum(int v, int l, int r, int s, int e){
	if(e<l || r<s)
		return 0;
	if(s<=l && r<=e)
		return sum[v];
	int mid = (l+r)/2;
	return rangesum(2*v, l, mid, s, e) + rangesum(2*v+1, mid+1, r, s, e);
}

void initialise(int N, int Q, int h[]) {
	int i;
	n = N;
	for(i=1; i<=n; i++)
		H[i] = h[i];
	settree(1, 1, n);
}
void cut(int l, int r, int k) {
	int i;
	for(i=1; i<=k; i++){
		pair<ll, int> temp = maxvalue(1, 1, n, l, r);
		temp.second = -temp.second;
		if(temp.first == 0)
			return;
		update(1, 1, n, temp.second, temp.first-1);
	}
}
void magic(int i, int x) {
	update(1, 1, n, i, x);
}
long long int inspect(int l, int r) {
	return rangesum(1, 1, n, l, r);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 33 ms 13264 KB Output is correct
4 Correct 33 ms 15444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2007 ms 4440 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2007 ms 4440 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 36948 KB Output is correct
2 Correct 73 ms 37116 KB Output is correct
3 Execution timed out 2079 ms 14172 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 33 ms 13264 KB Output is correct
4 Correct 33 ms 15444 KB Output is correct
5 Execution timed out 2007 ms 4440 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 33 ms 13264 KB Output is correct
4 Correct 33 ms 15444 KB Output is correct
5 Execution timed out 2007 ms 4440 KB Time limit exceeded
6 Halted 0 ms 0 KB -