QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#268717 | #5302. Useful Algorithm | Lynkcat# | RE | 11ms | 129328kb | C++23 | 3.3kb | 2023-11-28 20:11:36 | 2023-11-28 20:11:38 |
Judging History
answer
#include<bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair < int,int >
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
#define sz(x) (int)((x).size())
#define int ll
//#define N
using namespace std;
const int N=100005;
int n,a[N],c[N],d[N];
int q,m;
struct
{
int tr[N<<2];
multiset<int>all[N];
int mx[N];
int len;
priority_queue<pa>q1;
priority_queue<pair<int,pa>>q;
inline int chk(int x,int y)
{
if (mx[x]>mx[y]) return x;
return y;
}
void update(int k,int l,int r,int L,int x)
{
if (l==r)
{
tr[k]=x;
return;
}
int mid=l+(r-l)/2;
if (L<=mid) update(k<<1,l,mid,L,x);
else update(k<<1|1,mid+1,r,L,x);
tr[k]=chk(tr[k<<1],tr[k<<1|1]);
}
int query(int k,int l,int r,int L,int R)
{
if (L>R) return -1;
if (L<=l&&r<=R) return tr[k];
int mid=l+(r-l)/2;
if (R<=mid) return query(k<<1,l,mid,L,R);
if (L>mid) return query(k<<1|1,mid+1,r,L,R);
return chk(query(k<<1,l,mid,L,R),query(k<<1,l,mid,L,R));
}
void upd(int x)
{
if (all[x].empty()) mx[x]=-1;
else
mx[x]=(*all[x].rbegin());
// cout<<"!!!!"<<x<<" "<<(all[x].size())<<endl;
if (all[x].size()>=1&&x+x>=(1<<len))
{
q1.push(mp(mx[x]+mx[x],x));
}
update(1,0,(1<<len)-1,x,x);
if (x==0) return;
{
int y=query(1,0,(1<<len)-1,(1<<len)-x,(1<<len)-1);
// cout<<"!!!"<<len<<" "<<x<<" "<<y<<" "<<mx[x]<<endl;
if (y>0&&mx[x]!=-1&&mx[y]!=-1)
{
q.push(mp(mx[x]+mx[y],mp(x,y)));
}
}
if ((x>>(len-1))&1)
{
int y=query(1,0,(1<<len)-1,(1<<len)-x,(1<<(len-1))-1);
if (y>0&&mx[x]!=-1&&mx[y]!=-1)
{
q.push(mp(mx[x]+mx[y],mp(x,y)));
}
}
}
int qry()
{
while (q.size()&&q.top().fi!=mx[q.top().se.fi]+mx[q.top().se.se]) q.pop();
while (q1.size()&&
(all[q1.top().se].empty()||
q1.top().fi!=mx[q1.top().se]+mx[q1.top().se])
) q1.pop();
if (q.size())
{
if (q1.size()) return max(q.top().fi,q1.top().fi);
return q.top().fi;
}
if (q1.size()) return q1.top().fi;
return 0;
}
}tr[17];
int calc()
{
int ans=0;
for (int i=1;i<=m;i++)
{
ans=max(ans,tr[i].qry()*a[i]);
// cout<<a[i]<<"..."<<tr[i].qry()<<endl;
}
// cout<<ans<<endl;
return ans;
}
void BellaKira()
{
cin>>n>>m>>q;
for (int i=1;i<=m;i++)
cin>>a[i],tr[i].len=i;
for (int i=1;i<=n;i++) cin>>c[i];
for (int i=1;i<=n;i++) cin>>d[i];
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
tr[j].all[c[i]%(1<<j)].insert(d[i]);
}
for (int i=1;i<=m;i++)
{
for (int j=0;j<(1<<i);j++)
{
tr[i].upd(j);
}
for (int j=0;j<(1<<i);j++)
{
tr[i].upd(j);
}
}
int ans=calc();
cout<<ans<<'\n';
while (q--)
{
int x,u,v;
cin>>x>>u>>v;
x^=ans,u^=ans,v^=ans;
// cout<<x<<" "<<u<<" "<<v<<endl;
for (int i=1;i<=m;i++)
tr[i].all[c[x]%(1<<i)].erase(tr[i].all[c[x]%(1<<i)].find(d[x]));
for (int i=1;i<=m;i++)
tr[i].upd(c[x]%(1<<i));
d[x]=v;
c[x]=u;
for (int i=1;i<=m;i++)
tr[i].all[c[x]%(1<<i)].insert(d[x]);
for (int i=1;i<=m;i++)
tr[i].upd(c[x]%(1<<i));
ans=calc();
cout<<ans<<'\n';
}
}
signed main()
{
IOS;
cin.tie(0);
int T=1;
while (T--)
{
BellaKira();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 7ms
memory: 129328kb
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: 0
Accepted
time: 11ms
memory: 128580kb
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...
output:
1786020431157499328 1496424903210009136 981667153012455664 981667153012455664 817082674424719944 1083086338546577104 1186096888772143904 1186096888772143904 1186096888772143904 768437095486384888 848350340146561056
result:
ok 11 numbers
Test #3:
score: -100
Runtime Error
input:
100 5 100 90634477 839424973 368714032 715789796 976912516 14 25 23 26 21 6 18 25 13 16 1 11 6 19 23 30 20 16 9 5 15 14 18 25 20 21 16 20 1 17 5 20 29 21 23 30 14 21 16 25 0 10 30 15 5 18 20 15 16 14 8 13 25 3 19 1 28 25 20 4 25 31 13 22 21 5 4 27 24 0 3 25 14 9 25 27 6 31 23 17 22 0 20 14 20 20 10 ...