답안 #334869

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334869 2020-12-10T06:32:29 Z beksultan04 Birthday gift (IZhO18_treearray) C++14
30 / 100
4000 ms 6128 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=1e18+7;
int q[N],up[N][40],tin[N],tout[N],cnt,der[4*N];
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];
}
/*
void build(int v,int l,int r){
    if (l == r){
        der[v] = q[l];
    }
    else {
        int m = l+r>>1;
        build(v<<1,l,m);
        build((v<<1)+1,m+1,r);
        der[v] = lca(der[v<<1],der[(v<<1)+1]);
    }
}
void update(int v,int l,int r,int x,int y){
    if (l == r){
        der[v]=y;
    }
    else {
        int m = l+r>>1;
        if (m < x){
            update((v<<1)+1,m+1,r,x,y);
        }
        else update(v<<1,l,m,x,y);

        der[v] = lca(der[v<<1],der[(v<<1)+1]);
    }
}

int get_ans(int v,int l,int r,int ql,int qr){
    if (ql <= l && r <= qr)ret der[v];
    if (ql > r || qr < l)ret 0;
    else {
        int m = l+r>>1;
        int x = get_ans(v<<1,l,m,ql,qr);
        int y = get_ans((v<<1)+1,m+1,r,ql,qr);
        if (x == 0)ret y;
        if (y == 0)ret x;
        ret lca(x,y);
    }
}
*/
main(){
    int n,m,t,i,j,mm;
    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 = q[i];
                for (j=i;j<=r;++j){
                    lc =lca(lc,q[j]);
                    if (lc == v){
                        ll = i;
                        rr = j;
                        break;
                    }
                }
            }
            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:89:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   89 | main(){
      |      ^
treearray.cpp: In function 'int main()':
treearray.cpp:90:19: warning: unused variable 'mm' [-Wunused-variable]
   90 |     int n,m,t,i,j,mm;
      |                   ^~
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:91:5: note: in expansion of macro 'scan3'
   91 |     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:94:9: note: in expansion of macro 'scan2'
   94 |         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:102:9: note: in expansion of macro 'scan1'
  102 |         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:105:9: note: in expansion of macro 'scan1'
  105 |         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:108:13: note: in expansion of macro 'scan2'
  108 |             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:113:13: note: in expansion of macro 'scan3'
  113 |             scan3(l,r,v)
      |             ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB n=5
2 Correct 4 ms 5100 KB n=100
3 Correct 4 ms 5100 KB n=100
4 Correct 7 ms 5120 KB n=100
5 Correct 5 ms 5100 KB n=100
6 Correct 7 ms 5100 KB n=100
7 Correct 7 ms 5100 KB n=100
8 Correct 5 ms 5100 KB n=100
9 Correct 4 ms 5100 KB n=100
10 Correct 5 ms 5100 KB n=100
11 Correct 5 ms 5100 KB n=100
12 Correct 4 ms 5100 KB n=100
13 Correct 4 ms 5120 KB n=100
14 Correct 4 ms 5100 KB n=100
15 Correct 4 ms 5100 KB n=100
16 Correct 4 ms 5100 KB n=100
17 Correct 4 ms 5100 KB n=100
18 Correct 4 ms 5100 KB n=100
19 Correct 4 ms 5100 KB n=100
20 Correct 4 ms 5100 KB n=100
21 Correct 4 ms 5100 KB n=100
22 Correct 4 ms 5100 KB n=100
23 Correct 4 ms 5100 KB n=100
24 Correct 4 ms 5100 KB n=100
25 Correct 5 ms 5100 KB n=100
26 Correct 4 ms 5100 KB n=12
27 Correct 5 ms 5100 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB n=5
2 Correct 4 ms 5100 KB n=100
3 Correct 4 ms 5100 KB n=100
4 Correct 7 ms 5120 KB n=100
5 Correct 5 ms 5100 KB n=100
6 Correct 7 ms 5100 KB n=100
7 Correct 7 ms 5100 KB n=100
8 Correct 5 ms 5100 KB n=100
9 Correct 4 ms 5100 KB n=100
10 Correct 5 ms 5100 KB n=100
11 Correct 5 ms 5100 KB n=100
12 Correct 4 ms 5100 KB n=100
13 Correct 4 ms 5120 KB n=100
14 Correct 4 ms 5100 KB n=100
15 Correct 4 ms 5100 KB n=100
16 Correct 4 ms 5100 KB n=100
17 Correct 4 ms 5100 KB n=100
18 Correct 4 ms 5100 KB n=100
19 Correct 4 ms 5100 KB n=100
20 Correct 4 ms 5100 KB n=100
21 Correct 4 ms 5100 KB n=100
22 Correct 4 ms 5100 KB n=100
23 Correct 4 ms 5100 KB n=100
24 Correct 4 ms 5100 KB n=100
25 Correct 5 ms 5100 KB n=100
26 Correct 4 ms 5100 KB n=12
27 Correct 5 ms 5100 KB n=100
28 Correct 10 ms 5228 KB n=500
29 Correct 32 ms 5248 KB n=500
30 Correct 30 ms 5228 KB n=500
31 Correct 33 ms 5228 KB n=500
32 Correct 13 ms 5228 KB n=500
33 Correct 36 ms 5228 KB n=500
34 Correct 11 ms 5228 KB n=500
35 Correct 30 ms 5228 KB n=500
36 Correct 255 ms 5356 KB n=500
37 Correct 261 ms 5228 KB n=500
38 Correct 255 ms 5248 KB n=500
39 Correct 32 ms 5228 KB n=500
40 Correct 31 ms 5228 KB n=500
41 Correct 30 ms 5228 KB n=500
42 Correct 131 ms 5368 KB n=500
43 Correct 130 ms 5356 KB n=500
44 Correct 127 ms 5376 KB n=500
45 Correct 11 ms 5228 KB n=500
46 Correct 30 ms 5228 KB n=500
47 Correct 27 ms 5228 KB n=500
48 Correct 9 ms 5228 KB n=500
49 Correct 25 ms 5228 KB n=500
50 Correct 33 ms 5228 KB n=500
51 Correct 42 ms 5228 KB n=500
52 Correct 35 ms 5228 KB n=500
53 Correct 38 ms 5228 KB n=500
54 Correct 66 ms 5228 KB n=500
55 Correct 13 ms 5100 KB n=278
56 Correct 94 ms 5228 KB n=500
57 Correct 97 ms 5356 KB n=500
58 Correct 101 ms 5356 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB n=5
2 Correct 4 ms 5100 KB n=100
3 Correct 4 ms 5100 KB n=100
4 Correct 7 ms 5120 KB n=100
5 Correct 5 ms 5100 KB n=100
6 Correct 7 ms 5100 KB n=100
7 Correct 7 ms 5100 KB n=100
8 Correct 5 ms 5100 KB n=100
9 Correct 4 ms 5100 KB n=100
10 Correct 5 ms 5100 KB n=100
11 Correct 5 ms 5100 KB n=100
12 Correct 4 ms 5100 KB n=100
13 Correct 4 ms 5120 KB n=100
14 Correct 4 ms 5100 KB n=100
15 Correct 4 ms 5100 KB n=100
16 Correct 4 ms 5100 KB n=100
17 Correct 4 ms 5100 KB n=100
18 Correct 4 ms 5100 KB n=100
19 Correct 4 ms 5100 KB n=100
20 Correct 4 ms 5100 KB n=100
21 Correct 4 ms 5100 KB n=100
22 Correct 4 ms 5100 KB n=100
23 Correct 4 ms 5100 KB n=100
24 Correct 4 ms 5100 KB n=100
25 Correct 5 ms 5100 KB n=100
26 Correct 4 ms 5100 KB n=12
27 Correct 5 ms 5100 KB n=100
28 Correct 10 ms 5228 KB n=500
29 Correct 32 ms 5248 KB n=500
30 Correct 30 ms 5228 KB n=500
31 Correct 33 ms 5228 KB n=500
32 Correct 13 ms 5228 KB n=500
33 Correct 36 ms 5228 KB n=500
34 Correct 11 ms 5228 KB n=500
35 Correct 30 ms 5228 KB n=500
36 Correct 255 ms 5356 KB n=500
37 Correct 261 ms 5228 KB n=500
38 Correct 255 ms 5248 KB n=500
39 Correct 32 ms 5228 KB n=500
40 Correct 31 ms 5228 KB n=500
41 Correct 30 ms 5228 KB n=500
42 Correct 131 ms 5368 KB n=500
43 Correct 130 ms 5356 KB n=500
44 Correct 127 ms 5376 KB n=500
45 Correct 11 ms 5228 KB n=500
46 Correct 30 ms 5228 KB n=500
47 Correct 27 ms 5228 KB n=500
48 Correct 9 ms 5228 KB n=500
49 Correct 25 ms 5228 KB n=500
50 Correct 33 ms 5228 KB n=500
51 Correct 42 ms 5228 KB n=500
52 Correct 35 ms 5228 KB n=500
53 Correct 38 ms 5228 KB n=500
54 Correct 66 ms 5228 KB n=500
55 Correct 13 ms 5100 KB n=278
56 Correct 94 ms 5228 KB n=500
57 Correct 97 ms 5356 KB n=500
58 Correct 101 ms 5356 KB n=500
59 Correct 155 ms 5888 KB n=2000
60 Correct 1552 ms 6064 KB n=2000
61 Correct 1655 ms 5868 KB n=2000
62 Correct 1704 ms 6000 KB n=2000
63 Correct 208 ms 5996 KB n=2000
64 Correct 1748 ms 6128 KB n=2000
65 Correct 140 ms 5996 KB n=2000
66 Correct 1744 ms 6044 KB n=2000
67 Correct 772 ms 5996 KB n=2000
68 Correct 1639 ms 5868 KB n=2000
69 Execution timed out 4065 ms 5860 KB Time limit exceeded
70 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5100 KB n=5
2 Correct 4 ms 5100 KB n=100
3 Correct 4 ms 5100 KB n=100
4 Correct 7 ms 5120 KB n=100
5 Correct 5 ms 5100 KB n=100
6 Correct 7 ms 5100 KB n=100
7 Correct 7 ms 5100 KB n=100
8 Correct 5 ms 5100 KB n=100
9 Correct 4 ms 5100 KB n=100
10 Correct 5 ms 5100 KB n=100
11 Correct 5 ms 5100 KB n=100
12 Correct 4 ms 5100 KB n=100
13 Correct 4 ms 5120 KB n=100
14 Correct 4 ms 5100 KB n=100
15 Correct 4 ms 5100 KB n=100
16 Correct 4 ms 5100 KB n=100
17 Correct 4 ms 5100 KB n=100
18 Correct 4 ms 5100 KB n=100
19 Correct 4 ms 5100 KB n=100
20 Correct 4 ms 5100 KB n=100
21 Correct 4 ms 5100 KB n=100
22 Correct 4 ms 5100 KB n=100
23 Correct 4 ms 5100 KB n=100
24 Correct 4 ms 5100 KB n=100
25 Correct 5 ms 5100 KB n=100
26 Correct 4 ms 5100 KB n=12
27 Correct 5 ms 5100 KB n=100
28 Correct 10 ms 5228 KB n=500
29 Correct 32 ms 5248 KB n=500
30 Correct 30 ms 5228 KB n=500
31 Correct 33 ms 5228 KB n=500
32 Correct 13 ms 5228 KB n=500
33 Correct 36 ms 5228 KB n=500
34 Correct 11 ms 5228 KB n=500
35 Correct 30 ms 5228 KB n=500
36 Correct 255 ms 5356 KB n=500
37 Correct 261 ms 5228 KB n=500
38 Correct 255 ms 5248 KB n=500
39 Correct 32 ms 5228 KB n=500
40 Correct 31 ms 5228 KB n=500
41 Correct 30 ms 5228 KB n=500
42 Correct 131 ms 5368 KB n=500
43 Correct 130 ms 5356 KB n=500
44 Correct 127 ms 5376 KB n=500
45 Correct 11 ms 5228 KB n=500
46 Correct 30 ms 5228 KB n=500
47 Correct 27 ms 5228 KB n=500
48 Correct 9 ms 5228 KB n=500
49 Correct 25 ms 5228 KB n=500
50 Correct 33 ms 5228 KB n=500
51 Correct 42 ms 5228 KB n=500
52 Correct 35 ms 5228 KB n=500
53 Correct 38 ms 5228 KB n=500
54 Correct 66 ms 5228 KB n=500
55 Correct 13 ms 5100 KB n=278
56 Correct 94 ms 5228 KB n=500
57 Correct 97 ms 5356 KB n=500
58 Correct 101 ms 5356 KB n=500
59 Correct 155 ms 5888 KB n=2000
60 Correct 1552 ms 6064 KB n=2000
61 Correct 1655 ms 5868 KB n=2000
62 Correct 1704 ms 6000 KB n=2000
63 Correct 208 ms 5996 KB n=2000
64 Correct 1748 ms 6128 KB n=2000
65 Correct 140 ms 5996 KB n=2000
66 Correct 1744 ms 6044 KB n=2000
67 Correct 772 ms 5996 KB n=2000
68 Correct 1639 ms 5868 KB n=2000
69 Execution timed out 4065 ms 5860 KB Time limit exceeded
70 Halted 0 ms 0 KB -