# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1068358 |
2024-08-21T09:27:34 Z |
정희우(#11129) |
Weirdtree (RMI21_weirdtree) |
C++17 |
|
145 ms |
69436 KB |
#include "weirdtree.h"
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using lint = long long;
using vint = vector<int>;
using pii = pair<int,int>;
const int MAX_N=300010;
struct Seg
{
lint sum,fv,sv,c;
void setv(int h)
{
sum=fv=h;
sv=-1;c=1;
}
};
int n,q;
Seg seg[MAX_N<<2];
void merge_(Seg &p,const Seg &l,const Seg &r)
{
p.sum=l.sum+r.sum;
p.fv=max(l.fv,r.fv);
p.sv=max(l.sv,r.sv);
if(p.fv!=l.fv)p.sv=max(p.sv,l.fv);
if(p.fv!=r.fv)p.sv=max(p.sv,r.fv);
p.c=l.c*(p.fv==l.fv)+r.c*(p.fv==r.fv);
}
void update_down(const Seg &p,Seg &c)
{
if(c.fv<=p.fv)return;
c.sum-=(c.fv-p.fv)*c.c;
c.fv=p.fv;
}
void update_lazy(int i)
{
update_down(seg[i],seg[i<<1]);
update_down(seg[i],seg[i<<1|1]);
}
void update_one(int i,int s,int e,int x,int h)
{
if(s>x || e<=x)return;
if(s==x && x+1==e)
{
seg[i].setv(h);
return;
}
update_lazy(i);
update_one(i<<1,s,(s+e)>>1,x,h);
update_one(i<<1|1,(s+e)>>1,e,x,h);
merge_(seg[i],seg[i<<1],seg[i<<1|1]);
}
void update_second(int i,int s,int e)
{
if(seg[i].fv>seg[i].sv)return;
update_lazy(i);
update_second(i<<1,s,(s+e)>>1);
update_second(i<<1|1,(s+e)>>1,e);
merge_(seg[i],seg[i<<1],seg[i<<1|1]);
}
void update_cut(int i,int s,int e,int l,int r,int h,int dh)
{
if(s>=r || e<=l || seg[i].fv<h)return;
if(l<=s && e<=r)
{
seg[i].sum-=seg[i].c*dh;
seg[i].fv-=dh;
update_second(i,s,e);
return;
}
update_lazy(i);
update_cut(i<<1,s,(s+e)>>1,l,r,h,dh);
update_cut(i<<1|1,(s+e)>>1,e,l,r,h,dh);
merge_(seg[i],seg[i<<1],seg[i<<1|1]);
}
void update_left(int i,int s,int e,int l,int r,int h,int &c)
{
if(s>=r || e<=l || seg[i].fv<h || c==0)return;
if(l<=s && e<=r && seg[i].c<=c)
{
seg[i].sum-=seg[i].c;
seg[i].fv--;
update_second(i,s,e);
c-=seg[i].c;
return;
}
update_lazy(i);
update_left(i<<1,s,(s+e)>>1,l,r,h,c);
update_left(i<<1|1,(s+e)>>1,e,l,r,h,c);
merge_(seg[i],seg[i<<1],seg[i<<1|1]);
return;
}
Seg find_(int i,int s,int e,int l,int r)
{
if(s>=r || e<=l)return {0,0,-1,0};
if(l<=s && e<=r)return seg[i];
update_lazy(i);
Seg lv=find_(i<<1,s,(s+e)>>1,l,r);
Seg rv=find_(i<<1|1,(s+e)>>1,e,l,r);
Seg p;
merge_(p,lv,rv);
return p;
}
void initialise(int N, int Q, int h[])
{
n=N,q=Q;
for(int i=0;i<n;i++)
update_one(1,0,n,i,h[i+1]);
}
void cut(int l, int r, int k)
{
while(1)
{
Seg v=find_(1,0,n,l-1,r);
v.sv=max(v.sv,0LL);
if(v.fv==0)break;
if((v.fv-v.sv)*v.c>k)
{
update_cut(1,0,n,l-1,r,v.fv,k/v.c);
int leftc=k%v.c;
update_left(1,0,n,l-1,r,v.fv-k/v.c,leftc);
break;
}
k-=(v.fv-v.sv)*v.c;
update_cut(1,0,n,l-1,r,v.fv,v.fv-v.sv);
}
}
void magic(int i, int x)
{
update_one(1,0,n,i-1,x);
}
lint inspect(int l, int r)
{
Seg v=find_(1,0,n,l-1,r);
return v.sum;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
82 ms |
9272 KB |
Output is correct |
4 |
Incorrect |
87 ms |
9476 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Runtime error |
119 ms |
69436 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
145 ms |
38224 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
82 ms |
9272 KB |
Output is correct |
4 |
Incorrect |
87 ms |
9476 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
82 ms |
9272 KB |
Output is correct |
4 |
Incorrect |
87 ms |
9476 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |