QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#21544 | #2849. 弗雷兹的玩具商店 | DaBenZhongXiaSongKuaiDi# | WA | 1901ms | 273884kb | C++14 | 2.7kb | 2022-03-07 14:54:08 | 2022-05-08 03:36:55 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k,c[200005],v[200005],q;
struct stree
{
int l,r,add,addv;
int w[61];
}t[550000];
inline void givev(int now,int x)
{
t[now].addv+=x;
for(int i=0;i<m;i++) t[now].w[i]+=x;
}
inline void giveadd(int now,int x)
{
t[now].add+=x;
int b[61]={};
for(int i=0;i<m;i++) b[(i+x)%m]=t[now].w[i];
for(int i=0;i<m;i++) t[now].w[i]=b[i];
}
inline void pd(int now)
{
if(t[now].l==t[now].r) return ;
giveadd(now*2,t[now].add);
giveadd(now*2+1,t[now].add);
giveadd(now*2,t[now].addv);
giveadd(now*2+1,t[now].addv);
t[now].add=0,t[now].addv=0;
}
inline stree mer(stree x,stree y)
{
stree rtn;
rtn.l=x.l,rtn.r=y.r,rtn.add=0,rtn.addv=0;
for(int i=0;i<m;i++) rtn.w[i]=max(x.w[i],y.w[i]);
return rtn;
}
inline void build(int now,int l,int r)
{
t[now].l=l,t[now].r=r,t[now].add=0;
if(l==r)
{
for(int i=0;i<m;i++) t[now].w[i]=-1e18;
t[now].w[c[l]%m]=v[l];
return ;
}
int mid=(l+r)/2;
build(now*2,l,mid),build(now*2+1,mid+1,r);
t[now]=mer(t[now*2],t[now*2+1]);
}
inline void changev(int now,int l,int r,int d)
{
if(t[now].l==l&&t[now].r==r)
{
givev(now,d);
return ;
}
pd(now);
if(t[now*2].r>=r) changev(now*2,l,r,d);
else if(t[now*2+1].l<=l) changev(now*2+1,l,r,d);
else changev(now*2,l,t[now*2].r,d),changev(now*2+1,t[now*2+1].l,r,d);
t[now]=mer(t[now*2],t[now*2+1]);
}
inline void changec(int now,int l,int r,int d)
{
if(t[now].l==l&&t[now].r==r)
{
giveadd(now,d);
return ;
}
pd(now);
if(t[now*2].r>=r) changec(now*2,l,r,d);
else if(t[now*2+1].l<=l) changec(now*2+1,l,r,d);
else changec(now*2,l,t[now*2].r,d),changec(now*2+1,t[now*2+1].l,r,d);
t[now]=mer(t[now*2],t[now*2+1]);
}
inline stree query(int now,int l,int r)
{
if(t[now].l==l&&t[now].r==r) return t[now];
pd(now);
if(t[now*2].r>=r) return query(now*2,l,r);
else if(t[now*2+1].l<=l) return query(now*2+1,l,r);
return mer(query(now*2,l,t[now*2].r),query(now*2+1,t[now*2+1].l,r));
}
signed main(int argc, char** argv) {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for(int i=1;i<=n;i++) cin >> c[i];
for(int i=1;i<=n;i++) cin >> v[i];
build(1,1,n);
cin >> q;
while(q--)
{
int op,l,r,x;
cin >> op >> l >> r;
if(op==3)
{
stree t=query(1,l,r);
/* for(int i=0;i<m;i++)
cout << t.w[i] << " ";
cout << "\n";*/
t.w[m]=t.w[0];
int dp[61]={};
for(int i=1;i<=m;i++)
{
for(int j=0;j+i<=m;j++)
dp[j+i]=max(dp[j+i],dp[j]+t.w[i]);
}
int Sum=0,Xor=0;
for(int i=1;i<=m;i++) Sum+=dp[i],Xor^=dp[i];
cout << Sum << " " << Xor << "\n";
}
else
{
cin >> x;
if(op==1)
changec(1,l,r,x);
else changev(1,l,r,x);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5816kb
input:
4 10 1 6 10 2 100 2333 666 300 7 3 1 4 3 1 3 1 2 4 1 3 1 4 2 2 3 -1000 2 2 3 -600 3 2 4
output:
15165 2865 14165 2169 36630 798 4899 1273
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 1901ms
memory: 273884kb
input:
200000 60 21 16 58 5 26 44 30 40 31 27 50 21 59 50 37 39 26 9 15 14 9 59 40 29 32 5 2 25 57 18 4 9 25 1 13 42 36 34 21 6 53 2 18 51 51 55 29 17 3 36 22 11 26 1 40 58 57 33 22 53 42 26 1 6 18 6 47 54 31 59 51 23 60 1 13 43 55 34 59 49 9 12 51 34 4 22 31 1 47 45 45 28 10 38 34 19 35 12 4 5 11 47 28 2 ...
output:
7420856790 159383868 302725180 6346266 263891804 12270170 206665590 7376160 3170420 3170420 6350166 6350166 298016030 8641780 187482000 7499280 4538258 4538258 302685395 8377169 8876025210 276301312 5312756 5312756 273952510 11264178 0 0 3391399 3391399 0 0 57776184 0 833361126 19186028 11936024940 ...
result:
wrong answer 1st lines differ - expected: '304478979 5965183', found: '7420856790 159383868'