当前位置:网站首页>8VC Venture Cup 2017 - Final Round C. Nikita and stack
8VC Venture Cup 2017 - Final Round C. Nikita and stack
2022-06-26 18:23:00 【不吃土司边】
#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;
}
边栏推荐
- Numpy's Matplotlib
- How pycharm modifies multiline annotation shortcuts
- Which securities company is better for a novice to open a stock trading account? How is it safer to speculate in stocks??
- 最小生成树、最短路径、拓扑排序、关键路径
- Request method 'POST' not supported
- JS cast
- Deep understanding of MySQL lock and transaction isolation level
- Bayesian network explanation
- 新手炒股开户选哪个证券公司比较好?怎样炒股比较安全??
- Chinese (Simplified) language pack
猜你喜欢
Leetcode interview question 29 clockwise print matrix
Deep understanding of MySQL lock and transaction isolation level
ARM裸板调试之串口打印及栈初步分析
Decision tree and random forest
SSO微服务工程中用户行为日志的记录
Clion compiling catkin_ WS (short for ROS workspace package) loads cmakelists Txt problems
Plt How to keep show() not closed
行锁与隔离级别案例分析
Detailed explanation of MySQL mvcc mechanism
Binary search-1
随机推荐
Handwritten promise all
LeetCode 面试题29 顺时针打印矩阵
几种常见的UML关系图汇总
Soft test preparation multimedia system
Interview key points that must be mastered index and affairs (with B-tree and b+ tree)
The eigen library calculates the angle between two vectors
Get and set settings in 26class
元宇宙链游开发案例版 NFT元宇宙链游系统开发技术分析
LeetCode 238 除自身以外数组的乘积
Digital signature standard (DSS)
Static registration and dynamic registration of JNI
Binary search-1
ARM裸板调试之串口打印及栈初步分析
vutils. make_ A little experience of grid () in relation to black and white images
带你解决哈希冲突,并实现一个简单hash表,
PC end records 515 ground sweeping robot /scan data
SSO微服务工程中用户行为日志的记录
输入n个整数,输出出现次数大于等于数组长度一半的数
Connected to surface test questions
Union, intersection and difference operations in SQL