# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1068142 |
2024-08-21T08:01:07 Z |
정희우(#11129) |
Weirdtree (RMI21_weirdtree) |
C++17 |
|
2000 ms |
41516 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)
{
if(s>=r || e<=l)return;
if(l<=s && e<=r)
{
seg[i].sum-=seg[i].c*h;
seg[i].fv-=h;
update_second(i,s,e);
return;
}
update_lazy(i);
update_cut(i<<1,s,(s+e)>>1,l,r,h);
update_cut(i<<1|1,(s+e)>>1,e,l,r,h);
merge_(seg[i],seg[i<<1],seg[i<<1|1]);
}
int 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 0;
if(l<=s && e<=r && seg[i].c<=c)
{
seg[i].sum-=seg[i].c;
seg[i].fv--;
update_second(i,s,e);
return seg[i].c;
}
update_lazy(i);
int u=update_left(i<<1,s,(s+e)>>1,l,r,h,c);
u+=update_left(i<<1|1,(s+e)>>1,e,l,r,h,c-u);
merge_(seg[i],seg[i<<1],seg[i<<1|1]);
return u;
}
Seg find_(int i,int s,int e,int l,int r)
{
if(s>=r || e<=l)return {0,-1,-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)
{
k-=(v.fv-v.sv)*v.c;
update_cut(1,0,n,l-1,r,v.fv-v.sv);
}
else
{
update_cut(1,0,n,l-1,r,k/v.c);
update_left(1,0,n,l-1,r,v.fv-k/v.c,k%v.c);
break;
}
}
}
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 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2048 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2048 ms |
348 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
159 ms |
41516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |