QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#601702 | #5278. Mex and Cards | huaxiamengjin# | WA | 1ms | 9788kb | C++14 | 1.3kb | 2024-09-30 11:10:40 | 2024-09-30 11:10:40 |
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);
}
void push(int p,int l,int r,int x,int pre){
if(l==r)return mn[p]=a[l],ls[p]=a[l],s[p]=0,void();
int mid=l+r>>1;
if(x>=l){
if(x<=mid)push(p<<1,l,mid,x,pre);
push(p<<1|1,mid+1,r,x,min(pre,mn[p<<1]));
}
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);
// if(x==7)cout<<l<<" "<<r<<" "<<mid<<" "<<pre<<" "<<s[p]<<" "<<mn[p<<1]<<" "<<ls[p<<1|1]<<" "<<ls[p]<<" "<<ls[p<<1|1]<<" "<<mn[p]<<"****\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]--;
push(1,0,n-1,x,1e9);
cout<<s[1]+mn[1]*n<<"\n";
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9780kb
input:
5 2 1 3 0 2 6 1 0 1 1 2 4 1 3 2 1 2 1
output:
4 5 7 7 9 7 3
result:
ok 7 numbers
Test #2:
score: 0
Accepted
time: 1ms
memory: 7740kb
input:
1 0 0
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 9756kb
input:
10 3 8 1 4 10 3 10 9 7 10 20 2 5 1 4 1 2 1 4 1 3 1 3 1 0 2 8 1 5 1 4 1 0 1 3 1 8 1 6 1 4 1 1 1 5 1 9 1 6 2 7
output:
14 14 14 22 22 22 22 24 24 24 24 26 26 26 26 26 26 26 26 26 26
result:
ok 21 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 9788kb
input:
10 9 8 7 5 5 4 3 2 1 1 20 2 4 1 8 2 6 1 2 1 2 2 5 2 2 1 0 1 6 1 6 2 9 1 2 2 7 2 8 2 3 1 9 1 7 1 4 2 6 1 7
output:
45 44 45 44 45 45 44 44 45 46 46 45 45 43 43 42 43 44 44 44 45
result:
ok 21 numbers
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 7808kb
input:
100 969 519 608 546 957 82 670 100 92 581 974 529 970 54 639 216 238 620 966 162 430 10 446 884 895 292 450 180 619 389 943 855 204 605 514 997 325 98 643 915 744 249 333 431 160 434 714 976 168 573 682 69 873 285 668 561 159 858 864 683 266 564 350 214 461 421 213 568 279 624 749 433 735 437 978 95...
output:
4923 4923 4923 4923 4923 4923 4923 4923 4923 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4922 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 4921 ...
result:
wrong answer 10th numbers differ - expected: '4927', found: '4922'