Submission #334870

# Submission time Handle Problem Language Result Execution time Memory
334870 2020-12-10T06:34:41 Z beksultan04 Birthday gift (IZhO18_treearray) C++14
30 / 100
4000 ms 5740 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("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&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;
                    }
                }
            }
            printf("%d %d\n",ll,rr);
        }
    }
}






Compilation message

treearray.cpp:15:30: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   15 | const int N = 2e5+12,INF=1e18+7;
      |                          ~~~~^~
treearray.cpp: In function 'void dfs(int, int)':
treearray.cpp:26:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<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("%d %d %d",&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("%d %d",&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("%d",&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("%d",&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("%d %d",&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("%d %d %d",&a,&b,&c);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~
treearray.cpp:113:13: note: in expansion of macro 'scan3'
  113 |             scan3(l,r,v)
      |             ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5228 KB n=5
2 Correct 4 ms 5100 KB n=100
3 Correct 5 ms 5100 KB n=100
4 Correct 4 ms 5100 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 4 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 5100 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 4 ms 5100 KB n=100
26 Correct 4 ms 5100 KB n=12
27 Correct 5 ms 5100 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5228 KB n=5
2 Correct 4 ms 5100 KB n=100
3 Correct 5 ms 5100 KB n=100
4 Correct 4 ms 5100 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 4 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 5100 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 4 ms 5100 KB n=100
26 Correct 4 ms 5100 KB n=12
27 Correct 5 ms 5100 KB n=100
28 Correct 11 ms 5100 KB n=500
29 Correct 30 ms 5228 KB n=500
30 Correct 28 ms 5100 KB n=500
31 Correct 29 ms 5100 KB n=500
32 Correct 13 ms 5100 KB n=500
33 Correct 34 ms 5100 KB n=500
34 Correct 11 ms 5100 KB n=500
35 Correct 27 ms 5100 KB n=500
36 Correct 236 ms 5228 KB n=500
37 Correct 239 ms 5100 KB n=500
38 Correct 233 ms 5120 KB n=500
39 Correct 32 ms 5228 KB n=500
40 Correct 30 ms 5100 KB n=500
41 Correct 29 ms 5100 KB n=500
42 Correct 120 ms 5100 KB n=500
43 Correct 120 ms 5100 KB n=500
44 Correct 127 ms 5100 KB n=500
45 Correct 11 ms 5100 KB n=500
46 Correct 28 ms 5228 KB n=500
47 Correct 25 ms 5100 KB n=500
48 Correct 9 ms 5100 KB n=500
49 Correct 23 ms 5100 KB n=500
50 Correct 31 ms 5100 KB n=500
51 Correct 32 ms 5100 KB n=500
52 Correct 31 ms 5100 KB n=500
53 Correct 37 ms 5100 KB n=500
54 Correct 54 ms 5228 KB n=500
55 Correct 12 ms 5100 KB n=278
56 Correct 86 ms 5228 KB n=500
57 Correct 87 ms 5228 KB n=500
58 Correct 94 ms 5100 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5228 KB n=5
2 Correct 4 ms 5100 KB n=100
3 Correct 5 ms 5100 KB n=100
4 Correct 4 ms 5100 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 4 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 5100 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 4 ms 5100 KB n=100
26 Correct 4 ms 5100 KB n=12
27 Correct 5 ms 5100 KB n=100
28 Correct 11 ms 5100 KB n=500
29 Correct 30 ms 5228 KB n=500
30 Correct 28 ms 5100 KB n=500
31 Correct 29 ms 5100 KB n=500
32 Correct 13 ms 5100 KB n=500
33 Correct 34 ms 5100 KB n=500
34 Correct 11 ms 5100 KB n=500
35 Correct 27 ms 5100 KB n=500
36 Correct 236 ms 5228 KB n=500
37 Correct 239 ms 5100 KB n=500
38 Correct 233 ms 5120 KB n=500
39 Correct 32 ms 5228 KB n=500
40 Correct 30 ms 5100 KB n=500
41 Correct 29 ms 5100 KB n=500
42 Correct 120 ms 5100 KB n=500
43 Correct 120 ms 5100 KB n=500
44 Correct 127 ms 5100 KB n=500
45 Correct 11 ms 5100 KB n=500
46 Correct 28 ms 5228 KB n=500
47 Correct 25 ms 5100 KB n=500
48 Correct 9 ms 5100 KB n=500
49 Correct 23 ms 5100 KB n=500
50 Correct 31 ms 5100 KB n=500
51 Correct 32 ms 5100 KB n=500
52 Correct 31 ms 5100 KB n=500
53 Correct 37 ms 5100 KB n=500
54 Correct 54 ms 5228 KB n=500
55 Correct 12 ms 5100 KB n=278
56 Correct 86 ms 5228 KB n=500
57 Correct 87 ms 5228 KB n=500
58 Correct 94 ms 5100 KB n=500
59 Correct 161 ms 5484 KB n=2000
60 Correct 1425 ms 5740 KB n=2000
61 Correct 1520 ms 5612 KB n=2000
62 Correct 1589 ms 5616 KB n=2000
63 Correct 210 ms 5484 KB n=2000
64 Correct 1649 ms 5544 KB n=2000
65 Correct 149 ms 5484 KB n=2000
66 Correct 1584 ms 5504 KB n=2000
67 Correct 748 ms 5612 KB n=2000
68 Correct 1514 ms 5740 KB n=2000
69 Execution timed out 4070 ms 5508 KB Time limit exceeded
70 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5228 KB n=5
2 Correct 4 ms 5100 KB n=100
3 Correct 5 ms 5100 KB n=100
4 Correct 4 ms 5100 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 4 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 5100 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 4 ms 5100 KB n=100
26 Correct 4 ms 5100 KB n=12
27 Correct 5 ms 5100 KB n=100
28 Correct 11 ms 5100 KB n=500
29 Correct 30 ms 5228 KB n=500
30 Correct 28 ms 5100 KB n=500
31 Correct 29 ms 5100 KB n=500
32 Correct 13 ms 5100 KB n=500
33 Correct 34 ms 5100 KB n=500
34 Correct 11 ms 5100 KB n=500
35 Correct 27 ms 5100 KB n=500
36 Correct 236 ms 5228 KB n=500
37 Correct 239 ms 5100 KB n=500
38 Correct 233 ms 5120 KB n=500
39 Correct 32 ms 5228 KB n=500
40 Correct 30 ms 5100 KB n=500
41 Correct 29 ms 5100 KB n=500
42 Correct 120 ms 5100 KB n=500
43 Correct 120 ms 5100 KB n=500
44 Correct 127 ms 5100 KB n=500
45 Correct 11 ms 5100 KB n=500
46 Correct 28 ms 5228 KB n=500
47 Correct 25 ms 5100 KB n=500
48 Correct 9 ms 5100 KB n=500
49 Correct 23 ms 5100 KB n=500
50 Correct 31 ms 5100 KB n=500
51 Correct 32 ms 5100 KB n=500
52 Correct 31 ms 5100 KB n=500
53 Correct 37 ms 5100 KB n=500
54 Correct 54 ms 5228 KB n=500
55 Correct 12 ms 5100 KB n=278
56 Correct 86 ms 5228 KB n=500
57 Correct 87 ms 5228 KB n=500
58 Correct 94 ms 5100 KB n=500
59 Correct 161 ms 5484 KB n=2000
60 Correct 1425 ms 5740 KB n=2000
61 Correct 1520 ms 5612 KB n=2000
62 Correct 1589 ms 5616 KB n=2000
63 Correct 210 ms 5484 KB n=2000
64 Correct 1649 ms 5544 KB n=2000
65 Correct 149 ms 5484 KB n=2000
66 Correct 1584 ms 5504 KB n=2000
67 Correct 748 ms 5612 KB n=2000
68 Correct 1514 ms 5740 KB n=2000
69 Execution timed out 4070 ms 5508 KB Time limit exceeded
70 Halted 0 ms 0 KB -