QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#197918 | #3850. DJ Darko | Forever_Young# | TL | 0ms | 0kb | C++23 | 3.4kb | 2023-10-02 21:45:01 | 2023-10-02 21:45:01 |
answer
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;++i)
#define per(i,n) for(int i=n;i>=1;--i)
#define pb push_back
#define mp make_pair
#define N 210000
#define inf 2147483647
int n,q;
int a[N];
long long b[N];
struct node
{
long long max,min,set,add;
}st[4*N];
//first set, then add
void update(int t)
{
st[t].max=max(st[2*t].max,st[2*t+1].max);
st[t].min=min(st[2*t].min,st[2*t+1].min);
}
void build(int t,int l,int r)
{
st[t].set=inf;
st[t].add=0;
if (l==r)
{
st[t].max=st[t].min=a[l];
return;
}
int mid=(l+r)/2;
build(2*t,l,mid);
build(2*t+1,mid+1,r);
update(t);
}
void pushdown(int t)
{
if (st[t].set!=inf)
{
st[2*t].max=st[2*t+1].max=st[t].set;
st[2*t].min=st[2*t+1].min=st[t].set;
st[2*t].add=st[2*t+1].add=0;
st[2*t].set=st[2*t+1].set=st[t].set;
st[t].set=inf;
}
if (st[t].add!=0)
{
st[2*t].max=st[2*t].max+st[t].add;
st[2*t+1].max=st[2*t+1].max+st[t].add;
st[2*t].min=st[2*t].min+st[t].add;
st[2*t+1].min=st[2*t+1].min+st[t].add;
st[2*t].add=st[2*t].add+st[t].add;
st[2*t+1].add=st[2*t+1].add+st[t].add;
st[t].add=0;
}
}
void modify(int t,int l,int r,int a,int b,int p)
{
if (a<=l && r<=b)
{
st[t].add=st[t].add+p;
st[t].max=st[t].max+p;
st[t].min=st[t].min+p;
return;
}
pushdown(t);
int mid=(l+r)/2;
if (a<=mid)modify(2*t,l,mid,a,b,p);
if (b>mid)modify(2*t+1,mid+1,r,a,b,p);
update(t);
}
void assign(int t,int l,int r,int a,int b,int p)
{
if (a<=l && r<=b)
{
st[t].add=0;
st[t].set=p;
st[t].max=p;
st[t].min=p;
return;
}
pushdown(t);
int mid=(l+r)/2;
if (a<=mid)assign(2*t,l,mid,a,b,p);
if (b>mid)assign(2*t+1,mid+1,r,a,b,p);
update(t);
}
long long getmax(int t,int l,int r,int a,int b)
{
if (a<=l && r<=b)return st[t].max;
pushdown(t);
int mid=(l+r)/2;
long long ret=-2147483647ll*10000000ll;
if (a<=mid)ret=max(ret,getmax(2*t,l,mid,a,b));
if (b>mid)ret=max(ret,getmax(2*t+1,mid+1,r,a,b));
return ret;
}
long long getmin(int t,int l,int r,int a,int b)
{
if (a<=l && r<=b)return st[t].min;
pushdown(t);
int mid=(l+r)/2;
long long ret=2147483647ll*10000000ll;
if (a<=mid)ret=min(ret,getmin(2*t,l,mid,a,b));
if (b>mid)ret=min(ret,getmin(2*t+1,mid+1,r,a,b));
return ret;
}
long long work(int l,int r)
{
static vector<pair<long long,long long> > q; q.clear();
for(int i=l;i<=r;)
{
int le=i,ri=r;
while (le<ri)
{
int mid=(le+ri)/2 + 1;
//cout<<mid<<endl;
if (getmax(1,1,n,i,mid)==getmin(1,1,n,i,mid))le=mid;
else ri=mid-1;
}
int j=le;
q.pb(mp(getmax(1,1,n,i,j),b[j]-b[i-1]));
i=j+1;
}
sort(q.begin(),q.end());
//puts("fuck");
//for(auto p:q)cout<<p.first<<" "<<p.second<<endl;
long long sum=0;
for(auto p:q)sum+=p.second;
long long now=0;
for(auto p:q)
{
now+=p.second;
if (now*2>=sum)return p.first;
}
return inf;
}
int main()
{
//freopen("1.in","r",stdin);
cin>>n>>q;
rep(i,n)scanf("%d",&a[i]);
rep(i,n)scanf("%lld",&b[i]);
rep(i,n)b[i]+=b[i-1];
build(1,1,n);
while (q--)
{
int opt; scanf("%d",&opt);
if (opt==1)
{
int l,r,x; scanf("%d%d%d",&l,&r,&x);
modify(1,1,n,l,r,x);
}
else
{
int l,r; long long x; scanf("%d%d",&l,&r);
x=work(l,r);
printf("%lld\n",x);
assign(1,1,n,l,r,x);
}
}
return 0;
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
200000 200000 185413631 745038744 881479208 394948467 101727403 796960399 284541402 80768155 286582974 546327406 197495962 552359542 727479505 437895671 143092948 7626834 741609268 540494577 298656274 548860413 41137417 210529949 658779847 161355446 486548926 602900245 119414972 310187428 238177860 ...
output:
462406736 1749348519 1749348519 467651597 874061694 874061694 874061694 874061694 -1521749 874061694 -893932302 -425504259 -425504259 332034115 332034115 86195778 86195778 86195778 86195778 86195778 -425504259 -165776398 -165776398 -165776398 -916781043 -254293799 -254293799 -254293799 -254293799 -8...