当前位置:网站首页>8VC Venture Cup 2017 - Final Round C. Nikita and stack
8VC Venture Cup 2017 - Final Round C. Nikita and stack
2022-06-26 18:35:00 【No toast】
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define eps 1e-2
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long ll;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;
const int maxn = 1e5+2;
const int INF = 1<<30;
const int mod = 1e9+7;
const int N=1e5+10;
struct node{
ll l,r,mx,lazy;
}tr[N<<2];
ll t,n,Q,a[N];
void pushup(ll x){
tr[x].mx=max(tr[x<<1].mx,tr[x<<1|1].mx);
}
void pushdown(ll x){
if(tr[x].lazy){
tr[x<<1].mx+=tr[x].lazy;
tr[x<<1|1].mx+=tr[x].lazy;
tr[x<<1].lazy+=tr[x].lazy;
tr[x<<1|1].lazy+=tr[x].lazy;
tr[x].lazy=0;
}
}
void build(ll p,ll l,ll r){
tr[p].l=l;tr[p].r=r;
if(l==r) return ;
ll mid=(l+r)>>1;
build(p<<1,l,mid);build(p<<1|1,mid+1,r);
pushup(p);
}
void update(ll p,ll l,ll r,ll val){
// cout<<tr[p].l<<" "<<tr[p].r<<" "<<l<<" "<<r<<endl;
if(tr[p].l>=l&&tr[p].r<=r){
tr[p].lazy+=val;
tr[p].mx+=val;
// if(tr[p].l==1) cout<<tr[p].mx<<" "<<val<<endl;
return ;
}
pushdown(p);
int mid=(tr[p].l+tr[p].r)>>1;
if(mid>=l) update(p<<1,l,r,val);
if(mid+1<=r) update(p<<1|1,l,r,val);
pushup(p);
}
ll query(int p){
if(tr[p].l==tr[p].r){
if(tr[p].mx<=0) return -1;
else return a[tr[p].l];
}
ll mid=(tr[p].l+tr[p].r)>>1;
pushdown(p);
int res=0;
if(tr[p<<1|1].mx>0) res=query(p<<1|1);
else res=query(p<<1);
pushup(p);
return res;
}
void solve(){
int m;scanf("%d",&m);
build(1,1,N);
// cout<<tr[3].l<<" "<<tr[3].r<<endl;
while(m--){
int op,x,y;scanf("%d%d",&x,&op);
if(op==1){
scanf("%d",&y);
update(1,1,x,1);a[x]=y;
}else{
update(1,1,x,-1);
}
// cout<<tr[1].mx<<endl;
printf("%lld\n",query(1));
}
return;
}
int main()
{
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
// ios::sync_with_stdio(false);
int t = 1;
//scanf("%d",&t);
while(t--){
// printf("Case %d: ",cas++);
solve();
}
return 0;
}
边栏推荐
- How about opening an account at Guojin securities? Is it safe to open an account?
- Example of using QPushButton style (and method of adding drop-down menu to button SetMenu)
- To: Apple CEO Cook: great ideas come from constantly rejecting the status quo
- 几种常见的UML关系图汇总
- 知識點總結
- The cross compilation environment appears So link file not found problem
- Leetcode interview question 29 clockwise print matrix
- In and exceptions, count (*) query optimization
- Filebeat安装及使用
- (树) 树状数组
猜你喜欢
随机推荐
SQL中的并、交、差运算
Some basic mistakes
微信小程序 uniapp 左滑 删除 带删除icon
刷新三观的HP-UX系统中的强指针赋值出core问题
How to create and enforce indexes
wm_concat()和group_concat()函数
项目实战五:搭建ELk日志收集系统
Properties file garbled
Ethereum技术架构介绍
成功解决之idea引用Lombok的@Slf4j后无法正常使用log
(multi threading knowledge points that must be mastered) understand threads, create threads, common methods and properties of using threads, and the meaning of thread state and state transition
Record of user behavior log in SSO microservice Engineering
PC端录制扫515地机器人/scan数据
判断某个序列是否为栈的弹出序列
Preliminary analysis of serial port printing and stack for arm bare board debugging
Eigen库计算两个向量夹角
Tag dynamic programming - preliminary knowledge for question brushing -2 0-1 knapsack theory foundation and two-dimensional array solution template
ros::spinOnce()和ros::spin()的使用和区别
零时科技 | 智能合约安全系列文章之反编译篇
Map and list < map > transfer to corresponding objects









