Submission #334870

#TimeUsernameProblemLanguageResultExecution timeMemory
334870beksultan04Birthday gift (IZhO18_treearray)C++14
30 / 100
4070 ms5740 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("%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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...