Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Node getMax(int a, int b, int add){
- Node ret = LOS;
- while(dad[a] != dad[b]){
- if(depth[dad[a]] > depth[dad[b]]) swap(a, b);
- ret = kombaj(ret, query(1, 0, timer - 1, pos[dad[b]], pos[b]));
- b = parent[dad[b]];
- }
- if(depth[a] > depth[b]) swap(a, b);
- ret = kombaj(ret, query(1, 0, timer - 1, pos[a] + add, pos[b]));
- return ret;
- }
- void upd(int a, int b, int x){
- while(dad[a] != dad[b]){
- if(depth[dad[a]] > depth[dad[b]]) swap(a, b);
- update(1, 0, timer - 1, pos[dad[b]], pos[b], x);
- b = parent[dad[b]];
- }
- if(depth[a] > depth[b]) swap(a, b);
- update(1, 0, timer - 1, pos[a], pos[b], x);
- }
- while(q--){
- int t, a, b; scanf("%d %d %d", &t, &a, &b);
- int lca = getLca(a, b);
- if(t == 1){
- Node lef = getMax(lca, a, 0);
- Node rig = getMax(lca, b, 1);
- ll sol = kombaj(lef, rig).best;
- printf("%lld\n", sol);
- }
- else{
- int x; scanf("%d", &x);
- upd(a, b, x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement