QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#180745 | #6856. Easy problem I | masterhuang | WA | 1534ms | 123720kb | C++20 | 4.3kb | 2023-09-16 11:13:50 | 2023-09-16 11:13:51 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define int LL
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
namespace IO
{
const int _Pu=2e7+5,_d=32;
char buf[_Pu],obuf[_Pu],*p1=buf+_Pu,*p2=buf+_Pu,*p3=obuf,*p4=obuf+_Pu-_d;
inline void fin()
{
memmove(buf,p1,p2-p1);
int rlen=fread(buf+(p2-p1),1,p1-buf,stdin);
if(p1-rlen>buf) buf[p2-p1+rlen]=EOF;p1=buf;
}
inline void fout(){fwrite(obuf,p3-obuf,1,stdout),p3=obuf;}
inline int rd()
{
if(p1+_d>p2) fin();int isne=0,x=0;
for(;!isdigit(*p1);++p1) isne=(*p1=='-');x=(*p1++-'0');
for(;isdigit(*p1);++p1) x=x*10+(*p1-'0');
if(isne) x=-x;return x;
}
inline void wr(LL x,char end='\n')
{
if(!x) return *p3++='0',*p3++=end,void();
if(x<0) *p3++='-',x=-x;
char sta[20],*top=sta;
do{*top++=(x%10)+'0';x/=10;}while(x);
do{*p3++=*--top;}while(top!=sta);(*p3++)=end;
}
}using IO::rd;using IO::wr;
const int N=2e5+5;
struct node{int l,r,x;}q[N],Q[N];
int T,n,m,a[N],t,b[N],c[N];
vector<int>g[N];
#define ls (wz<<1)
#define rs (wz<<1|1)
namespace SGT1
{
struct node{int x;LL lt,s;}a[N<<2];
inline void pushup(int wz){a[wz].x=a[ls].x+a[rs].x,a[wz].s=a[ls].s+a[rs].s;}
inline void upd(int wz,int x){a[wz].lt+=x;a[wz].s-=x*a[wz].x;}
inline void pushdown(int wz){LL t=a[wz].lt;upd(ls,t);upd(rs,t);a[wz].lt=0;}
void build(int l,int r,int wz)
{
if(l==r) return a[wz]={1,0,::a[l]},void();
int mid=(l+r)>>1;build(l,mid,ls);build(mid+1,r,rs);
pushup(wz);
}
void updata(int l,int r,int wz,int L,int R,int x)
{
if(L<=l&&r<=R) return upd(wz,x);
int mid=(l+r)>>1;pushdown(wz);
if(L<=mid) updata(l,mid,ls,L,R,x);
if(mid<R) updata(mid+1,r,rs,L,R,x);pushup(wz);
}
void del(int l,int r,int wz,int x)
{
if(l==r) return a[wz]={0,0,0},void();
int mid=(l+r)>>1;pushdown(wz);
if(x<=mid) del(l,mid,ls,x);else del(mid+1,r,rs,x);
pushup(wz);
}
LL query(int l,int r,int wz,int L,int R)
{
if(L<=l&&r<=R) return a[wz].s;
int mid=(l+r)>>1;LL ans=0;pushdown(wz);
if(L<=mid) ans+=query(l,mid,ls,L,R);
if(mid<R) ans+=query(mid+1,r,rs,L,R);return ans;
}
}
namespace SGT2
{
struct node1{LL s;int x,y,z;}a[N<<2];//x加法,y乘法,z是个数
inline void init(){for(int i=1;i<=(n<<2);i++) a[i]={0,0,1,0};}
inline void pushup(int wz){a[wz].z=a[ls].z+a[rs].z,a[wz].s=a[ls].s+a[rs].s;}
inline void upd(int wz,int x){a[wz].x+=x;a[wz].s+=x*a[wz].z;}
inline void upd1(int wz,int x){a[wz].x*=x;a[wz].y*=x,a[wz].s*=x;}
inline void pushdown(int wz){LL t=a[wz].x,t1=a[wz].y;upd1(ls,t1);upd1(rs,t1);upd(ls,t);upd(rs,t);a[wz].x=0,a[wz].y=1;}
void updata(int l,int r,int wz,int L,int R,int x)
{
if(L<=l&&r<=R) return upd1(wz,-1),upd(wz,x);
int mid=(l+r)>>1;pushdown(wz);
if(L<=mid) updata(l,mid,ls,L,R,x);
if(mid<R) updata(mid+1,r,rs,L,R,x);pushup(wz);
}
void add(int l,int r,int wz,int p,int x)
{
if(l==r) return a[wz]={x,0,1,1},void();
int mid=(l+r)>>1;pushdown(wz);
if(p<=mid) add(l,mid,ls,p,x);else add(mid+1,r,rs,p,x);
pushup(wz);
}
LL query(int l,int r,int wz,int L,int R)
{
if(L<=l&&r<=R) return a[wz].s;
int mid=(l+r)>>1;LL ans=0;pushdown(wz);
if(L<=mid) ans+=query(l,mid,ls,L,R);
if(mid<R) ans+=query(mid+1,r,rs,L,R);return ans;
}
}
inline LL que(int l,int r){return SGT1::query(1,n,1,l,r)+SGT2::query(1,n,1,l,r);}
void sol(int l,int r,vector<int>V,LL s)
{
if(!V.size()) return;
if(l==r){for(int i:V) if(a[i]<=s+Q[l].x) g[b[l]].push_back(i),c[i]=a[i]-s;return;}
int mid=(l+r)>>1;LL S=s;vector<int>V1,V2;
for(int i=l;i<=mid;i++) S+=Q[i].x;
for(int i:V) (a[i]<=S)?V1.push_back(i):V2.push_back(i);
sol(l,mid,V1,s);sol(mid+1,r,V2,S);
}
signed main()
{
T=rd();
while(T--)
{
n=rd(),m=rd();for(int i=1;i<=n;i++) a[i]=rd();
for(int i=1,o,l,r,x;i<=m;i++) o=rd(),l=rd(),r=rd(),q[i]={l,r,(o==1)?rd():-1},g[i].clear();
t=0;for(int i=1;i<=m;i++) if(q[i].x!=-1) Q[++t]=q[i],b[t]=i;
vector<int>V;for(int i=1;i<=n;i++) V.push_back(i);sol(1,t,V,0);SGT1::build(1,n,1);
for(int i=1;i<=m;i++)
{
if(q[i].x==-1){wr(que(q[i].l,q[i].r));continue;}
for(int j:g[i]) SGT1::del(1,n,1,j),SGT2::add(1,n,1,j,c[j]);
SGT1::updata(1,n,1,q[i].l,q[i].r,q[i].x);SGT2::updata(1,n,1,q[i].l,q[i].r,q[i].x);
}
}
return IO::fout(),0;
}
/*
1
5 5
1 2 3 4 5
1 1 5 3
2 1 2
2 2 4
1 2 3 5
2 1 5
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1534ms
memory: 123720kb
input:
5 200000 200000 3709648 4995492 5495456 501056 4601940 1825635 6147030 7689408 143360 9147335 2417120 2793752 9916480 8197760 7882880 7267650 2321280 1451104 8753832 7068854 6171460 1619388 5223842 4450688 2700644 5887820 4425750 6152896 6689900 5465982 9139756 5472040 6425220 9986528 4223363 938070...
output:
367859591959 341355592681 180239954362 125106478765 799473701501 12540914494 113658177169 439855267098 593351571892 206765988098 198000313371 528837895899 159199669236 16199163797 485076055527 171497193223 298594266318 775543704410 113775003661 262345595573 473858669554 686338586089 239945373429 130...
result:
wrong answer 32nd lines differ - expected: '647277390358', found: '647277386060'