답안 #334919

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334919 2020-12-10T09:05:33 Z beksultan04 Birthday gift (IZhO18_treearray) C++14
0 / 100
16 ms 23916 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 2e5+12,INF=1e9+7;
int q[N],z[N],up[N][40],tin[N],tout[N],cnt;
vector <int> g[N];
set <int> s[N],ans[N];
void dfs(int x,int p){
    int i;
    tin[x]=++cnt;
    up[x][0]=p;
    for (i=1;i<20;++i)
        up[x][i]= up[up[x][i-1]][i-1];

    for (i=0;i<g[x].size();++i){
        if (g[x][i] != p){
            dfs(g[x][i],x);
        }
    }
    tout[x] = ++cnt;
}

bool upper(int a,int b){
    ret (tin[a] <= tin[b] && tout[a] >= tout[b]);
}

int lca(int a,int b){
    int i;
    if (upper(a,b))ret a;
    if (upper(b,a))ret b;
    for(i=19;i>=0;--i){
        if (!upper(up[a][i],b)){
            a = up[a][i];
        }
    }
    ret up[a][0];
}
main(){
    int n,m,t,i,j;
    scan3(n,m,t)
    for (i=1;i<n;++i){
        int x,y;
        scan2(x,y)
        g[x].pb(y);
        g[y].pb(x);
    }

    dfs(1,1);
    for (i=1;i<=m;++i)
        scan1(q[i])
    for (i=1;i<=m;++i){
        s[q[i]].insert(i);
        z[i]=q[i];
    }


    for (i=1;i<m;++i){
        int c = lca(q[i],q[i+1]);
        ans[c].insert(i);
    }

    while (t--){
        int type;
        scan1(type)
        if (type == 1){
            int a,b;
            scan2(a,b)
            if (a > 1){
                int lc = lca(z[a],z[a-1]);
                ans[lc].erase(a-1);
            }
            if (a < m){
                int lc = lca(z[a],z[a+1]);
                ans[lc].erase(a);
            }
            s[z[a]].erase(a);
            z[a] = b;
            if (a > 1){
                int lc = lca(z[a],z[a-1]);
                ans[lc].insert(a-1);
            }
            if (a < m){
                int lc = lca(z[a],z[a+1]);
                ans[lc].insert(a);
            }
            s[z[a]].insert(a);

        }
        else {

            int l,r,v,ll=-1,rr=-1;
            scan3(l,r,v)
            auto it =  ans[v].lower_bound(l);
            if (it != ans[v].end()){
                if (*it < r){
                    ll = *it;
                    rr = ll+1;
                }
            }
            it =  s[v].lower_bound(l);
            if (it != s[v].end()){
                ll = rr = *it;
            }
            cout <<ll<<" "<<rr<<"\n";

        }
    }
}


Compilation message

treearray.cpp: In function 'void dfs(long long int, long long int)':
treearray.cpp:26:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (i=0;i<g[x].size();++i){
      |              ~^~~~~~~~~~~~
treearray.cpp: At global scope:
treearray.cpp:49:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   49 | main(){
      |      ^
treearray.cpp: In function 'int main()':
treearray.cpp:50:17: warning: unused variable 'j' [-Wunused-variable]
   50 |     int n,m,t,i,j;
      |                 ^
treearray.cpp:11:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:51:5: note: in expansion of macro 'scan3'
   51 |     scan3(n,m,t)
      |     ^~~~~
treearray.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
treearray.cpp:54:9: note: in expansion of macro 'scan2'
   54 |         scan2(x,y)
      |         ^~~~~
treearray.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
treearray.cpp:61:9: note: in expansion of macro 'scan1'
   61 |         scan1(q[i])
      |         ^~~~~
treearray.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
treearray.cpp:75:9: note: in expansion of macro 'scan1'
   75 |         scan1(type)
      |         ^~~~~
treearray.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
treearray.cpp:78:13: note: in expansion of macro 'scan2'
   78 |             scan2(a,b)
      |             ^~~~~
treearray.cpp:11:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 | #define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:103:13: note: in expansion of macro 'scan3'
  103 |             scan3(l,r,v)
      |             ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB n=5
2 Incorrect 16 ms 23916 KB Wrong output format.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB n=5
2 Incorrect 16 ms 23916 KB Wrong output format.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB n=5
2 Incorrect 16 ms 23916 KB Wrong output format.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB n=5
2 Incorrect 16 ms 23916 KB Wrong output format.
3 Halted 0 ms 0 KB -