#include "weirdtree.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int NN=3e5+5;
ll n,a[NN];
struct node{
ll mx,sum,idx;
};
node seg[4*NN+5];
node merge(node x,node y){
node z;
z.mx=max(x.mx,y.mx);
z.sum=x.sum+y.sum;
if (x.mx>=y.mx) z.idx=x.idx;
if (x.mx<y.mx) z.idx=y.idx;
return z;
}
void build(int x,int l,int r){
if (l==r){
seg[x]={a[l],a[l],l};
return;
}int mid=(l+r)/2;
build(x*2,l,mid);
build(x*2+1,mid+1,r);
seg[x]=merge(seg[x*2],seg[x*2+1]);
return;
}
void edit(int x,int l,int r,int idx,int d){
if (l==r){
seg[x].mx+=d;
seg[x].sum+=d;
return;
}int mid=(l+r)/2;
if (idx<=mid) edit(x*2,l,mid,idx,d);
else edit(x*2+1,mid+1,r,idx,d);
seg[x]=merge(seg[x*2],seg[x*2+1]);
}
node query(int x,int l,int r,int lx,int rx){
if (l>=lx && r<=rx) return seg[x];
if (l>rx || r<lx) return {LLONG_MIN,0,-1};
int mid=(l+r)/2;
return merge(query(x*2,l,mid,lx,rx),query(x*2+1,mid+1,r,lx,rx));
}
void initialise(int N, int Q, int h[]) {
n=N;
for (int i=1;i<=n;i++) a[i]=h[i];
build(1,1,n);
return;
}
void cut(int l, int r, int k) {
int idx=query(1,1,n,l,r).idx;
if (a[idx]) edit(1,1,n,idx,-1),a[idx]--;
return;
}
void magic(int i, int x) {
edit(1,1,n,i,x-a[i]);
a[i]=x;
return;
}
long long int inspect(int l, int r) {
return query(1,1,n,l,r).sum;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
35 ms |
11604 KB |
Output is correct |
4 |
Correct |
35 ms |
11600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
38336 KB |
Output is correct |
2 |
Correct |
63 ms |
38644 KB |
Output is correct |
3 |
Incorrect |
14 ms |
11100 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
35 ms |
11604 KB |
Output is correct |
4 |
Correct |
35 ms |
11600 KB |
Output is correct |
5 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
35 ms |
11604 KB |
Output is correct |
4 |
Correct |
35 ms |
11600 KB |
Output is correct |
5 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |