QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#78505 | #5278. Mex and Cards | Yanagi_Origami | WA | 2ms | 5860kb | C++14 | 2.5kb | 2023-02-19 10:49:09 | 2023-02-19 10:49:11 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cmath>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=2e5+5;
typedef long long ll;
int n,a[N],b[N];
struct node{
int Min,l,r,tag;
ll sum;
}seg[N<<2];
ll calc(int l,int r,int w){
return 1ll*(r-l+1)*w;
}
void pushdown(int p){
if(seg[p].tag==-1) return ;
seg[p<<1].tag=seg[p].tag;
seg[p<<1|1].tag=seg[p].tag;
seg[p<<1].sum=calc(seg[p<<1].l,seg[p<<1].r,seg[p].tag);
seg[p<<1|1].sum=calc(seg[p<<1|1].l,seg[p<<1|1].r,seg[p].tag);
seg[p].tag=-1;
}
void upd(int p){
seg[p].Min=min(seg[p<<1].Min,seg[p<<1|1].Min);
seg[p].sum=seg[p<<1].sum+seg[p<<1|1].sum;
}
int queryless(int p,int l,int r,int x){
if(l==r){
return seg[p].Min<=x?l:(n+1);
}
pushdown(p);
int mid=(l+r)>>1;
if(seg[p<<1].Min<=x) return queryless(p<<1,l,mid,x);
else return queryless(p<<1|1,mid+1,r,x);
}
int querypre(int p,int l,int r,int R){
if(r<=R){
return seg[p].Min;
}
if(l>R) return n+1;
pushdown(p);
int mid=(l+r)>>1;
return min(querypre(p<<1,l,mid,R),querypre(p<<1|1,mid+1,r,R));
}
void build(int p,int l,int r){
if(l==r){
seg[p].tag=-1;
seg[p].Min=a[l];
seg[p].sum=b[l];
seg[p].l=l; seg[p].r=r;
return ;
}
seg[p].tag=-1;
int mid=(l+r)>>1;
build(p<<1,l,mid),build(p<<1|1,mid+1,r);
upd(p);
}
void modify(int p,int l,int r,int L,int R,int x){
if(L==l&&r==R){
seg[p].tag=x;
seg[p].sum=calc(l,r,x);
return ;
}
pushdown(p);
int mid=(l+r)>>1;
if(R<=mid) modify(p<<1,l,mid,L,R,x); else
if(L>mid) modify(p<<1|1,mid+1,r,L,R,x); else
modify(p<<1,l,mid,L,mid,x),modify(p<<1|1,mid+1,r,mid+1,R,x);
upd(p);
}
void Modify(int p,int l,int r,int x){
if(l==r){
seg[p].Min=a[l];
return ;
}
pushdown(p);
int mid=(l+r)>>1;
if(x<=mid) Modify(p<<1,l,mid,x);
else Modify(p<<1|1,mid+1,r,x);
upd(p);
}
int main(){
scanf("%d",&n);
rep(i,1,n) scanf("%d",a+i);
b[1]=a[1];
rep(i,2,n) b[i]=min(b[i-1],a[i]);
build(1,1,n);
printf("%lld\n",seg[1].sum);
int Q; scanf("%d",&Q);
while(Q--){
int opt,p;
scanf("%d%d",&opt,&p);
p++;
if(opt==1){
a[p]++;
Modify(1,1,n,p);
int Min=querypre(1,1,n,p);
int ps=queryless(1,1,n,Min-1);
modify(1,1,n,p,ps-1,Min);
}else{
a[p]--;
Modify(1,1,n,p);
int Min=querypre(1,1,n,p);
int ps=queryless(1,1,n,Min-1);
modify(1,1,n,p,ps-1,Min);
}
printf("%lld\n",seg[1].sum);
}
return 0;
}
/*
5
2 1 3 0 2
6
1 0
1 1
2 4
1 3
2 1
2 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5628kb
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: 2ms
memory: 5860kb
input:
1 0 0
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 5848kb
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 20 24 24 26 26 22 26 26 26 26 22 26 26
result:
wrong answer 9th numbers differ - expected: '24', found: '20'