Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
32697 | 23级李京宁 | 【J】ask | C++ | 通过 | 100 | 33 MS | 1060 KB | 638 | 2024-09-26 19:00:03 |
#include <bits/stdc++.h> using namespace std; #define int long long int n,q,a[100005],cnt[105],x,y,ans; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>n>>q; for(int i=1;i<=n;i++){ cin>>a[i]; cnt[a[i]]++; for(int j=a[i]+1;j<=100;j++) ans+=cnt[j]; }while(q--){ cin>>x; if(x==1){ cin>>a[++n]; for(int i=a[n]+1;i<=100;i++) ans+=cnt[i]; cnt[a[n]]++; }else{ for(int i=a[n]+1;i<=100;i++) ans-=cnt[i]; cnt[a[n--]]--; }cout<<ans<<'\n'; }return 0; }