QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#197973 | #3850. DJ Darko | Forever_Young# | WA | 431ms | 25944kb | C++23 | 4.0kb | 2023-10-02 22:59:21 | 2023-10-02 22:59:22 |
Judging History
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,sum,set;
}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);
st[t].sum=st[2*t].sum+st[2*t+1].sum;
}
void build(int t,int l,int r)
{
st[t].set=inf;
if (l==r)
{
st[t].max=st[t].min=st[t].sum=a[l]-a[l-1];
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)return;
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].set=st[2*t+1].set=st[t].set;
st[t].set=inf;
}
void modify(int t,int l,int r,int k,long long p)
{
if (l==r)
{
st[t].sum=st[t].sum+p;
st[t].max=st[t].max+p;
st[t].min=st[t].min+p;
return;
}
pushdown(t);
int mid=(l+r)/2;
if (k<=mid)modify(2*t,l,mid,k,p);
else modify(2*t+1,mid+1,r,k,p);
update(t);
}
void assign(int t,int l,int r,int a,int b,long long p)
{
if (a<=l && r<=b)
{
st[t].set=st[t].max=st[t].min=p;
st[t].sum=1ll*(r-l+1)*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 getsum(int t,int l,int r,int a,int b)
{
if (a>b)return 0;
if (a<=l && r<=b)return st[t].sum;
pushdown(t);
int mid=(l+r)/2;
long long ret=0;
if (a<=mid)ret+=getsum(2*t,l,mid,a,b);
if (b>mid)ret+=getsum(2*t+1,mid+1,r,a,b);
return ret;
}
int get(int t,int l,int r,int a,int b)
{
if (a>b)return -1;
if (st[t].min==0 && st[t].max==0)return -1;
if (l==r)return l;
pushdown(t);
int mid=(l+r)/2;
int ret=-1;
if (a<=mid)ret=get(2*t,l,mid,a,b);
if (ret!=-1)return ret;
if (b>mid)ret=get(2*t+1,mid+1,r,a,b);
return ret;
}
long long work(int l,int r)
{
//cout<<"fuck: "<<l<<" "<<r<<endl;
static vector<pair<long long,long long> > q; q.clear();
for(int i=l;i<=r;)
{
int j=get(1,1,n,i+1,r);
if (j==-1)j=r+1;
j--;
//cout<<i<<" "<<j<<endl;
q.pb(mp(getsum(1,1,n,1,i),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);
//for(int i=1;i<=n;i++)cout<<getsum(1,1,n,i,i)<<" "; puts("");
rep(ii,q)
{
//cout<<ii<<": "<<endl;
int opt; scanf("%d",&opt);
if (opt==1)
{
int l,r,x; scanf("%d%d%d",&l,&r,&x);
modify(1,1,n,l,x);
if (r<n)modify(1,1,n,r+1,-x);
}
else
{
int l,r; long long x; scanf("%d%d",&l,&r);
x=work(l,r);
printf("%lld\n",x);
int pre=getsum(1,1,n,1,l-1);
int nxt=getsum(1,1,n,1,r+1);
assign(1,1,n,l,l,x-pre);
if (r<n)assign(1,1,n,r+1,r+1,nxt-x);
if (l<r)assign(1,1,n,l+1,r,0);
}
//for(int i=1;i<=n;i++)cout<<getsum(1,1,n,i,i)<<" "; puts("");
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 431ms
memory: 25944kb
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 2004962967 467651597 922119932 -649970457 922119932 -806180820 1195126585 186817718 -1084354168 -567867887 -747586917 -1935090723 255982211 970036764 904077773 1468981958 -1356992612 164149384 -1083722685 888881144 -3434536437 888881144 -7601572803 522060283 2268118927 553098877...
result:
wrong answer 3rd lines differ - expected: '1749348519', found: '2004962967'