QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620257 | #5278. Mex and Cards | hbhz_zcy | WA | 5ms | 23624kb | C++14 | 2.0kb | 2024-10-07 17:12:03 | 2024-10-07 17:12:17 |
Judging History
answer
//g++ m.cpp -o m -g -std=c++14 -O0 -Wall
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
#define LL long long
using namespace std;
int qd(){
int rt=0;char c=getchar();
while(c<'0'||c>'9') c=getchar();
while('0'<=c&&c<='9') rt=(rt<<3)+(rt<<1)+c-48,c=getchar();
return rt;
}
const int maxn=2e5+10,_max2n=4e5;
struct node{int t,v;};
bool operator<(const node &x,const node &y){return x.t<y.t;}
set<node>f;
set<int>tn[maxn<<1];
int N,a[maxn<<1];LL ans=0;//7 5 3 -> 7 6 (5) 3 no 7 (5) 4 3
node backf(){auto it=f.end();if(it!=f.begin()) return *--it;else return {1,1};}
void calc(int t){
auto it=f.lower_bound({t,0});
if(it->t!=t){
it=f.insert(it,(node){t,a[t]});
auto l=it,r=it;l--,r++;
ans+=1LL*(r->t-it->t)*(it->v-l->v);
}
else{
auto r=it;r++;
ans+=1LL*(r->t-it->t)*(a[t]-it->v);
f.erase(it);
it=f.insert({t,a[t]}).first;
}
auto l=it,r=it;l--,r++;
if(l->v<=it->v){
ans-=1LL*(r->t-it->t)*(it->v-l->v);
f.erase(it);
}
else if(r!=f.end()&&it->v<=r->v){
l=r=it=r;l--,r++;
ans-=1LL*(r->t-it->t)*(it->v-l->v);
f.erase(it);
}
}
int main(){
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
N=qd();
for(int i=1;i<=N;i++) a[i]=qd();
f.insert({0,_max2n});ans=-_max2n;
for(int i=1;i<=N+1;i++){
if(a[i]<backf().v) ans+=1LL*backf().v*(i-backf().t),f.insert({i,a[i]});
if(a[i]) tn[a[i]].insert(i);
}
if(backf().t!=N+1) f.insert({N+1,0});
printf("%lld\n",ans);
int Q=qd();
while(Q--){
int t=qd(),v=qd()+1,_av=a[v];a[v]+=t==1?1:-1;
if(_av) tn[_av].erase(tn[_av].find(v));
if(a[v]) tn[a[v]].insert(tn[a[v]].upper_bound(v),v);
calc(v);
auto it=tn[_av].upper_bound(v);
if(it!=tn[_av].end()) calc(*it);
printf("%lld\n",ans);
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 22964kb
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: 0ms
memory: 23308kb
input:
1 0 0
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 5ms
memory: 23624kb
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: -100
Wrong Answer
time: 0ms
memory: 23500kb
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 39 39 39 39 40
result:
wrong answer 17th numbers differ - expected: '43', found: '39'