답안 #786487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
786487 2023-07-18T08:19:16 Z 박상훈(#10027) Weirdtree (RMI21_weirdtree) C++17
13 / 100
2000 ms 21312 KB
#include "weirdtree.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int n;
int a[300300];

struct Seg{
	pair<int, int> tree1[1101000];
	ll tree2[1101000];

	void init(int i, int l, int r){
		if (l==r){
			tree1[i] = {a[l], -l};
			tree2[i] = a[l];
			return;
		}

		int m = (l+r)>>1;
		init(i<<1, l, m); init(i<<1|1, m+1, r);
		tree1[i] = max(tree1[i<<1], tree1[i<<1|1]);
		tree2[i] = tree2[i<<1] + tree2[i<<1|1];
	}

	void update(int i, int l, int r, int p){
		if (r<p || p<l) return;
		if (l==r){
			tree1[i] = {a[l], -l};
			tree2[i] = a[l];
			return;
		}

		int m = (l+r)>>1;
		update(i<<1, l, m, p); update(i<<1|1, m+1, r, p);
		tree1[i] = max(tree1[i<<1], tree1[i<<1|1]);
		tree2[i] = tree2[i<<1] + tree2[i<<1|1];
	}

	pair<int, int> querymax(int i, int l, int r, int s, int e){
		if (r<s || e<l) return {-1, 0};
		if (s<=l && r<=e) return tree1[i];

		int m = (l+r)>>1;
		return max(querymax(i<<1, l, m, s, e), querymax(i<<1|1, m+1, r, s, e));
	}

	ll sum(int i, int l, int r, int s, int e){
		if (r<s || e<l) return 0;
		if (s<=l && r<=e) return tree2[i];

		int m = (l+r)>>1;
		return sum(i<<1, l, m, s, e) + sum(i<<1|1, m+1, r, s, e);
	}
}tree;

void initialise(int N, int Q, int h[]) {
	n = N;
	for (int i=1;i<=n;i++) a[i] = h[i];
	tree.init(1, 1, n);
}

void cut(int l, int r, int k) {
	for (int z=1;z<=k;z++){
		int idx = -tree.querymax(1, 1, n, l, r).second;
		if (a[idx]==0) break;
		a[idx]--;
		tree.update(1, 1, n, idx);
	}
}

void magic(int i, int x) {
	a[i] = x;
	tree.update(1, 1, n, i);
}

long long int inspect(int l, int r) {
	return tree.sum(1, 1, n, l, r);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8916 KB Output is correct
2 Correct 4 ms 8968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8916 KB Output is correct
2 Correct 4 ms 8968 KB Output is correct
3 Correct 37 ms 12280 KB Output is correct
4 Correct 43 ms 12256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2065 ms 8916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2065 ms 8916 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 21292 KB Output is correct
2 Correct 87 ms 21312 KB Output is correct
3 Execution timed out 2069 ms 11776 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8916 KB Output is correct
2 Correct 4 ms 8968 KB Output is correct
3 Correct 37 ms 12280 KB Output is correct
4 Correct 43 ms 12256 KB Output is correct
5 Execution timed out 2065 ms 8916 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8916 KB Output is correct
2 Correct 4 ms 8968 KB Output is correct
3 Correct 37 ms 12280 KB Output is correct
4 Correct 43 ms 12256 KB Output is correct
5 Execution timed out 2065 ms 8916 KB Time limit exceeded
6 Halted 0 ms 0 KB -