제출 #334910

#제출 시각아이디문제언어결과실행 시간메모리
334910beksultan04Birthday gift (IZhO18_treearray)C++14
56 / 100
4043 ms84344 KiB
#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],up[N][40],tin[N],tout[N],cnt;
vector <int> g[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])
    while (t--){
        int type;
        scan1(type)
        if (type==1){
            int l,r;
            scan2(l,r)
            q[l]=r;
        }
        else {
            int l,r,v,ll=-1,rr=-1;
            scan3(l,r,v)
            for (i=l;i<r;++i){
                int lc = lca(q[i],q[i+1]);
                if (lc == v){
                    ll=i;
                    rr=i+1;
                    break;
                }
                if (q[i] == v){
                    ll=i;
                    rr=i;
                    break;
                }

            }
            if (q[r] == v)ll=r,rr=r;
            cout <<ll<<" "<<rr<<"\n";
        }
    }
}


컴파일 시 표준 에러 (stderr) 메시지

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:62:9: note: in expansion of macro 'scan1'
   62 |         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:65:9: note: in expansion of macro 'scan1'
   65 |         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:68:13: note: in expansion of macro 'scan2'
   68 |             scan2(l,r)
      |             ^~~~~
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:73:13: note: in expansion of macro 'scan3'
   73 |             scan3(l,r,v)
      |             ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...