QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#75840 | #5302. Useful Algorithm | 275307894a | RE | 28ms | 110544kb | C++14 | 2.0kb | 2023-02-06 12:50:01 | 2023-02-06 12:50:02 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define PB push_back
using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned ll;
using namespace std;const int N=1e5+5,M=16+5,K=2e3+5,mod=924844033,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(time(0));
int n,m,q,W[N],C[N],D[N],P1[M],P2[M][N],Xi[M][N],P3[M][N];ll x,y,z,LA;
ll GA(){LA=0;for(int i=1;i<=m;i++) LA=max(LA,1ll*P1[i]*W[i]);return LA;}
multiset<int> f[M][N];
void CG(int p,int x){
int i,j,B=(1<<(p+1)/2),S=1<<p;
Xi[p][x]=-INF;for(i=0;i<B;i++) if(!f[p][x*B+i].empty())Xi[p][x]=max(Xi[p][x],*f[p][x*B+i].rbegin());
P3[p][x]=-INF;for(i=0;i<B;i++) if(f[p][i+x*B].size()>=2&&(i+x*B)*2>=S) P3[p][x]=max(P3[p][x],*f[p][i+x*B].rbegin()+*(++f[p][i+x*B].rbegin()));
if(x>=S/B/2) x=S/B-1-x;
P2[p][x]=0;int Mx=-INF;for(i=1;i<B;i++) {
if(!f[p][(S/B-1-x)*B+B-i].empty()) Mx=max(Mx,*f[p][(S/B-1-x)*B+B-i].rbegin());
if(!f[p][i+x*B].empty()) P2[p][x]=max(P2[p][x],Mx+*f[p][i+x*B].rbegin());
}
P1[p]=0;for(i=0;i<S/B/2;i++) P1[p]=max(P1[p],P2[p][i]);for(i=0;i<S/B;i++) P1[p]=max(P1[p],P3[p][i]);
Mx=-INF;
for(i=1;i<S/B;i++){
Mx=max(Mx,Xi[p][S/B-i]);
P1[p]=max(P1[p],Mx+Xi[p][i]);
}
}
void Ins(int p,int x,int y){f[p][x].insert(y);CG(p,x>>(p+1)/2);}
void Del(int p,int x,int y){f[p][x].erase(f[p][x].LB(y));CG(p,x>>(p+1)/2);}
int main(){
int i,j;scanf("%d%d%d",&n,&m,&q);for(i=1;i<=m;i++) scanf("%d",&W[i]);for(i=1;i<=n;i++) scanf("%d",&C[i]);for(i=1;i<=n;i++) scanf("%d",&D[i]);
Me(Xi,-0x3f);for(j=1;j<=m;j++) for(i=1;i<=n;i++) Ins(j,C[i]&((1<<j)-1),D[i]);
printf("%lld\n",GA());
while(q--) {
scanf("%lld%lld%lld",&x,&y,&z);x^=LA;y^=LA;z^=LA;
for(i=1;i<=m;i++) Del(i,C[x]&((1<<i)-1),D[x]);C[x]=y;D[x]=z;for(i=1;i<=m;i++) Ins(i,C[x]&((1<<i)-1),D[x]);
printf("%lld\n",GA());
}
}
详细
Test #1:
score: 100
Accepted
time: 28ms
memory: 110544kb
input:
5 3 3 1 2 4 0 0 1 2 7 10 10 5 3 1 27 24 29 20 16 19 13 8 9
output:
24 16 8 0
result:
ok 4 number(s): "24 16 8 0"
Test #2:
score: -100
Runtime Error
input:
10 3 10 927067928 939794644 439925712 4 7 6 2 4 2 0 7 0 7 207761141 796144622 434713413 101162902 804840394 950218456 666995722 154361380 192946720 522277478 1786020431157499334 1786020431157499335 1786020431397722754 1496424903210009138 1496424903210009136 1496424902707960940 981667153012455665 981...