fork(1) download
  1. {$m 10000500}
  2. const maxn = 1000000;
  3.  
  4. var
  5. fwt,wage:array[0..maxn] of int64;
  6. f,t,p,tin,tout:array[0..maxn] of longint;
  7. x,y,pred,ii,timer,n,m,i,j:longint;
  8. ch:chAR;
  9.  
  10. procedure addedge(const x, y:longint);
  11. begin
  12. inc(ii);
  13. t[ii]:=y;
  14. p[ii]:=f[x];
  15. f[x]:=ii;
  16. end;
  17.  
  18. procedure dfs(const k:longint);
  19. var
  20. q:longint;
  21. begin
  22. inc(timer); tin[k]:=timer;
  23. q:=f[k];
  24. while q>0 do
  25. begin
  26. dfs(t[q]);
  27. q:=p[q];
  28. end;
  29. tout[k]:=timer;
  30. end;
  31.  
  32. procedure fwt_modify(j, x:longint);
  33. begin
  34. while j<=n do
  35. begin
  36. inc(fwt[j], x);
  37. j:=j or (j-1)+1;
  38. end;
  39. end;
  40.  
  41. function fwt_findsum(j:longint):int64;
  42. var
  43. res:int64;
  44. begin
  45. res:=0;
  46. while j>0 do
  47. begin
  48. inc(res, fwt[j]);
  49. j:=j and (j-1);
  50. end;
  51. fwt_findsum:=res;
  52. end;
  53.  
  54. begin
  55. { assign(input, 'in.txt');
  56.   reset(input);
  57.   assign(output, 'out.txt');
  58.   rewrite(output);}
  59. readln(n, m);
  60. readln(wage[1]);
  61. for i:=2 to n do
  62. begin
  63. readln(wage[i], pred);
  64. addedge(pred, i);
  65. end;
  66. dfs(1);
  67. for i:=1 to m do
  68. begin
  69. read(ch);
  70. if ch = 'u' then
  71. begin
  72. readln(x);
  73. writeln(fwt_findsum(tin[x])+wage[x]);
  74. end else
  75. begin
  76. readln(x, y);
  77. fwt_modify(tin[x]+1, y);
  78. fwt_modify(tout[x]+1, -y);
  79. end;
  80. end;
  81. close(output);
  82. end.
Runtime error #stdin #stdout 0.01s 35416KB
stdin
Standard input is empty
stdout
Runtime error 106 at $0804829E
  $0804829E
  $0805F141