Submission #953992

# Submission time Handle Problem Language Result Execution time Memory
953992 2024-03-27T04:26:15 Z owoovo Tourism (JOI23_tourism) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define F first 
#define S second 
using namespace std;
int f[100010],si[100010],hs[100010],top[100010],dep[100010],in[100010],cnt;
int n,m,q;
vector<int> e[100010];
int dfs1(int now,int last){
    dep[now]=dep[last]+1;
    f[now]=last;
    si[now]=1;
    for(auto x:e[now]){
        if(x==last)continue;
        int siz=dfs1(x,now);
        if(siz>si[hs[now]]){
            hs[now]=x;
        }
        si[now]+=siz;
    }
    return si[now];
}
void dfs2(int now,int tp){
    in[now]=++cnt;
    top[now]=tp;
    if(hs[now]!=0)dfs2(hs[now],tp);
    for(auto x:e[now]){
        if(x==f[now]||x==hs[now])continue;
        dfs2(x,x);
    }
    return;
}
struct Bit{
    int ori[100010]={};
    void modify(int p,int x){
        while(p<=100000){
            ori[p]+=x;
            p+=p&(-p);
        }
        return ;
    }
    int query(int p){
        int ans=0;
        while(p){
            ans+=ori[p];
            p-=p&(-p);
        }
        return ans;
    }
}bit;
int ans[100010],ver[100010];
vector<pair<pair<int,int>,int>> qu;
set<pair<pair<int,int>,int>>st;
void segin(int l,int r,int id){
    if(l>r)swap(l,r);
    //cout<<l<<" "<<r<<" "<<id<<" x\n";
    auto oi=st.upper_bound({{l,m+1},0});
    auto tar=oi;
    vector<pair<pair<int,int>,int>> add;
    vector<set<pair<pair<int,int>,int>>::iterator> del
    if(tar!=st.begin()&&(*(tar--)).F.S>=l)--oi;
    tar=oi;
    while(tar!=st.end()&&(*tar).F.F<=r){
        auto [x,ID]=*tar;
        auto [L,R]=x;
        del.push_back(tar);
        // cout<<L<<" "<<R<<" "<<l<<" "<<r<<" "<<ID<<"\n";
        if(l<=L&&R<=r){
            bit.modify(ID,L-R-1);
        }else if(L<l&&R<=r){
            add.push_back(MP(MP(L,l-1),ID));
            bit.modify(ID,l-R-1);
        }else if(l<=L&&r<R){
            add.push_back(MP(MP(r+1,R),ID));
            bit.modify(ID,L-r-1);
        }else{
            add.push_back(MP(MP(L,l-1),ID));
            add.push_back(MP(MP(r+1,R),ID));
            bit.modify(ID,l-r-1);
        }
        tar++;
    }
    for(auto x:del) st.erase(x);
    for(auto x:add)st.insert(x);
    st.insert({{l,r},id});
    bit.modify(id,r-l+1);
    return;
}
void putin(int u,int v,int id){
    while(1){
        //cout<<u<<" "<<v<<" "<<id<<"\n";
        if(top[u]==top[v]){
            segin(in[v],in[u],id);
            break;
        }
        if(dep[top[u]]<dep[top[v]])swap(u,v);
        segin(in[top[u]],in[u],id);
        u=f[top[u]];
    }
    return;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m>>q;
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    dfs1(1,1);
    dfs2(1,1);
    for(int i=1;i<=m;i++){
        cin>>ver[i];
    }
    for(int i=1;i<=q;i++){
        int l,r;
        cin>>l>>r;
        if(l==r){
            ans[i]=1;
            continue;
        }
        qu.push_back({{l,r},i});
    }
    sort(qu.begin(),qu.end());
    reverse(qu.begin(),qu.end());
    int now=0;
    for(int i=m-1;i>=1;i--){
        //cout<<i<<"ok\n";
        //put in i,i+1
        putin(ver[i],ver[i+1],i+1);
        while(now!=q&&qu[now].F.F==i){
            auto [x,id]=qu[now];
            auto [l,r]=x;
            ans[id]=bit.query(r);
            now++;
        }
    }
    for(int i=1;i<=q;i++)cout<<ans[i]<<"\n";
    return 0;
}

Compilation message

tourism.cpp: In function 'void segin(int, int, int)':
tourism.cpp:62:5: error: expected initializer before 'if'
   62 |     if(tar!=st.begin()&&(*(tar--)).F.S>=l)--oi;
      |     ^~
tourism.cpp:67:9: error: 'del' was not declared in this scope; did you mean 'dep'?
   67 |         del.push_back(tar);
      |         ^~~
      |         dep
tourism.cpp:84:16: error: 'del' was not declared in this scope; did you mean 'dep'?
   84 |     for(auto x:del) st.erase(x);
      |                ^~~
      |                dep