QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#601807 | #5278. Mex and Cards | huaxiamengjin | WA | 0ms | 9784kb | C++14 | 1.5kb | 2024-09-30 13:51:57 | 2024-09-30 13:51:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,a[200100];
int mn[1001001],s[1001001],ls[1001001];
void build(int p,int l,int r,int pre){
if(l==r)return mn[p]=a[l],ls[p]=a[l],s[p]=0,void();
int mid=l+r>>1;
build(p<<1,l,mid,pre);build(p<<1|1,mid+1,r,min(mn[p<<1],pre));
mn[p]=min(mn[p<<1],mn[p<<1|1]);
ls[p]=ls[p<<1];
s[p]=s[p<<1]+s[p<<1|1]+(mid+1)*max(min(pre,mn[p<<1])-ls[p<<1|1],0ll);
// cout<<l<<" "<<r<<" "<<s[p]<<"\n";
}
void push(int p,int l,int r,int x,int pre){
if(l==r){
if(l==x)return mn[p]=a[l],ls[p]=a[l],s[p]=0,void();
else return;
}
int mid=l+r>>1;
// if(x==1)cout<<l<<" "<<r<<" "<<x<<" "<<pre<<"\n";
if(x>=l){
if(x<=mid)push(p<<1,l,mid,x,pre);
else if(pre<=mn[p<<1])s[p<<1]=0;
push(p<<1|1,mid+1,r,x,min(pre,mn[p<<1]));
}else{
if(pre<=mn[p<<1])s[p<<1]=0,push(p<<1|1,mid+1,r,x,pre);
else push(p<<1,l,mid,x,pre);
}
mn[p]=min(mn[p<<1],mn[p<<1|1]);
ls[p]=ls[p<<1];
s[p]=s[p<<1]+s[p<<1|1]+(mid+1)*max(min(pre,mn[p<<1])-ls[p<<1|1],0ll);
// cout<<l<<" "<<r<<" "<<s[p]<<" "<<mn[p]<<" "<<ls[p]<<" "<<s[p<<1]<<" "<<pre<<"\n";
}
signed main(){
cin>>n;
for (int i=0;i<n;i++)
cin>>a[i];
int q;
cin>>q;
build(1,0,n-1,1e9);
cout<<s[1]+mn[1]*n<<"\n";
int op,x;
while(q--){
cin>>op;
if(op==1){
cin>>x;
a[x]++;
push(1,0,n-1,x,1e9);
cout<<s[1]+mn[1]*n<<"\n";
}else {
cin>>x;
a[x]--;
for (int i=0;i<n;i++)cout<<a[i]<<" ";
cout<<"\n";
push(1,0,n-1,x,1e9);
cout<<s[1]+mn[1]*n<<"\n";
}
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 9784kb
input:
5 2 1 3 0 2 6 1 0 1 1 2 4 1 3 2 1 2 1
output:
4 5 7 3 2 3 0 1 7 9 3 1 3 1 1 7 3 0 3 1 1 3
result:
wrong answer 4th numbers differ - expected: '7', found: '3'