蓝题彩色二叉树求调
查看原帖
蓝题彩色二叉树求调
511268
PIKA_PIKA楼主2024/8/27 11:23
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10;
int n,q;
struct Ed{
    int w,id,col;
};
vector<Ed> tr[N];
void get(int x,int y,int id,int z){
    int ns=0;
    for(auto v:tr[x]){
        if(v.w<=y) ns++;
    }
    while(ns--) tr[x].pop_back();
    tr[x].push_back({y,id,z});
}
auto query(int x,int d){
    int l=0,r=tr[x].size()-1;
    while(l<r){
        int mid=l+r+1>>1;
        if(tr[x][mid].w>=d) l=mid;
        else r=mid-1;
    }
    return tr[x][l];
}
vector<Ed> b;
bool cmp(Ed A,Ed B){
    return A.id>B.id;
}
signed main(){
    cin>>n>>q;
    for(int i=1;i<=q;i++){
        int op,x,y,z;
        cin>>op>>x;
        if(op==1){
            cin>>y>>z;
            while(x){
                get(x,y,i,z);
                if(y==0) break;
                x>>=1;
                y--;
            }
        }
        else{
            int d=0;
            while(x){
                if(tr[x].size()) b.push_back(query(x,d));
                x>>=1;d++;
            }
            sort(b.begin(),b.end(),cmp);
            if(!b.size()) cout<<0<<"\n";
            else cout<<b[0].col<<"\n";
            b.clear();
        }
    }
}
2024/8/27 11:23
加载中...