#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);
// }
// subtask 3
vector<pair<int, int>> V;
for (int i=l;i<=r;i++) V.emplace_back(a[i], i);
sort(V.begin(), V.end(), greater<pair<int, int>>());
ll sum = 0;
for (int i=0;i<(int)V.size();i++){
sum += V[i].first;
int nxt = ((i+1)<(int)V.size())?V[i+1].first:0;
if (i==(int)V.size()-1 && sum < k) k = sum;
if (sum - (ll)nxt * (i+1) < k) continue;
ll q = (sum-k) / (i+1) + (!!((sum-k) % (i+1)));
ll r = (k - (sum - q*(i+1)));
assert(r < i+1);
vector<int> I;
for (int j=0;j<=i;j++) I.push_back(V[j].second);
sort(I.begin(), I.end());
for (int j=0;j<r;j++) a[I[j]] = q-1;
for (int j=r;j<(int)I.size();j++) a[I[j]] = q;
// printf("ok i = %d / q = %lld / r = %lld\n", i, q, r);
// for (int j=1;j<=n;j++) printf("%d ", a[j]);
// printf("\n");
return;
}
assert(0);
}
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);
ll ret = 0;
for (int i=l;i<=r;i++) ret += a[i];
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8916 KB |
Output is correct |
2 |
Correct |
10 ms |
8916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8916 KB |
Output is correct |
2 |
Correct |
10 ms |
8916 KB |
Output is correct |
3 |
Execution timed out |
2082 ms |
11200 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
9008 KB |
Output is correct |
2 |
Correct |
10 ms |
9032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
9008 KB |
Output is correct |
2 |
Correct |
10 ms |
9032 KB |
Output is correct |
3 |
Execution timed out |
2059 ms |
17920 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2079 ms |
17532 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8916 KB |
Output is correct |
2 |
Correct |
10 ms |
8916 KB |
Output is correct |
3 |
Execution timed out |
2082 ms |
11200 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8916 KB |
Output is correct |
2 |
Correct |
10 ms |
8916 KB |
Output is correct |
3 |
Execution timed out |
2082 ms |
11200 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |