Submission #744128

# Submission time Handle Problem Language Result Execution time Memory
744128 2023-05-18T08:25:33 Z hmm789 Weirdtree (RMI21_weirdtree) C++14
13 / 100
2000 ms 3924 KB
#include "weirdtree.h"
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000001
#define int long long
int a[300000], n;
#undef int

void initialise(int N, int Q, int h[]) {
	n = N;
	for(int i = 0; i < n; i++) {
		a[i] = h[i+1];
	}
}
void cut(int l, int r, int k) {
	#define int long long
	l--; r--;
	int L = 0, R = INF, M, cnt = 0;
	for(int i = l; i <= r; i++) cnt += a[i];
	if(k >= cnt) {
		for(int i = l; i <= r; i++) a[i] = 0;
		return;
	}
	while(L < R) {
		M = (L+R)/2;
		cnt = 0;
		for(int i = l; i <= r; i++) cnt += max(a[i]-M, 0LL);
		if(cnt < k) R = M;
		else L = M+1;
	}
	cnt = 0;
	for(int i = l; i <= r; i++) cnt += max(a[i]-L, 0LL);
	cnt = k-cnt;
	for(int i = l; i <= r; i++) {
		if(a[i] >= L) {
			a[i] = L;
			if(cnt) {
				a[i]--;
				cnt--;
			}
		}
	}
	#undef int
}
void magic(int i, int x) {
	i--;
	a[i] = x;
}
long long int inspect(int l, int r) {
	l--; r--;
	long long ans = 0;
	for(int i = l; i <= r; i++) ans += a[i];
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 4 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 4 ms 356 KB Output is correct
3 Execution timed out 2044 ms 1416 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 5 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 5 ms 340 KB Output is correct
3 Execution timed out 2058 ms 3924 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2072 ms 3648 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 4 ms 356 KB Output is correct
3 Execution timed out 2044 ms 1416 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 340 KB Output is correct
2 Correct 4 ms 356 KB Output is correct
3 Execution timed out 2044 ms 1416 KB Time limit exceeded
4 Halted 0 ms 0 KB -