Home > Back-end >  Why I can't submit all segment tree questions?
Why I can't submit all segment tree questions?

Time:09-26

I write my own segment tree board can't due in hdu and vj, can pay someone else to write the code, the sample I have got, what reason is this???????
 # include 
#include
#include
#include
#include
#include
#include
using namespace std;
Const int N=5 e4 + 5;
Int a [N], tr [N].
Void build_tree (int a [], int the tr [], int node, int st, int Ed) {
{if (st==Ed)
Tr=[node] a [st];
return;
}
Int l_node=node * 2 + 1;
Int r_node=node * 2 + 2;
Int mid=+ Ed (st) & gt;> 1;
Build_tree (a, tr, l_node, st, mid);
Build_tree (a, tr, r_node, mid + 1, Ed).
Tr=tr [l_node] + [node] tr [r_node];
}
Void the update (int a [], int the tr [], int node, int st, int Ed, int id, int val) {
{if (st==Ed)
A [id] +=val.
Tr=[node] a [id];
return;
}
Int mid=+ Ed (st) & gt;> 1;
Int l_node=node * 2 + 1;
Int r_node=node * 2 + 2;
If (id> Mid) {
Update (a, tr, r_node, mid + 1, Ed, id, val);
}
The else update (a, tr, l_node, st, mid, id, val);
Tr=tr [l_node] + [node] tr [r_node];
}
Int query (int a [], int the tr [], int node, int st, int Ed, int l, int r) {
Int mid=+ Ed (st) & gt;> 1;
Int l_node=node * 2 + 1;
Int r_node=node * 2 + 2;
If (r Ed) return 0;
Else if (st>=l& & Ed<=r) return the tr/node;//if [st, Ed] in [l, r] within the scope of direct return the value.
Int l_sum=query (a, tr, l_node, st, mid, l, r);
Int r_sum=query (a, tr, r_node, mid + 1, Ed, l, r);
Return l_sum + r_sum;
}
Int main () {
Int t, kase=0;
The scanf (" % d ", & amp; T);
While (t -) {
int n;
The scanf (" % d ", & amp; N);
for(int i=1; i<=n; I++) the scanf (" % d ", & amp; A [I]);
Memset (tr, 0, sizeof tr);
Build_tree (a, tr, 0, 1, n);
//for (int I=0; iPrintf (" Case % d: \ n ", + + kase);
Char c [15];
While (the scanf (" % s ", c)) {
int i,j;
if(! STRCMP (c, "Query")) {
The scanf (" % d % d ", & amp; I, & amp; J);
Printf (" % d \ n ", query (a, tr, 0, 1, n, I, j));
}
Else if (! STRCMP (c, "Add")) {
The scanf (" % d % d ", & amp; I, & amp; J);
Update (a, tr, 0, 1, n, I, j);
}
Else if (! STRCMP (c, "Sub")) {
The scanf (" % d % d ", & amp; I, & amp; J);
Update (a, tr, 0, 1, n, I, - j);
}
}
}
return 0;
}


To greatly help me to look at this is why, is I write the code has a problem?? This topic is hdu1166

CodePudding user response:

I submitted a web connection failure??????? What's the problem?????? Submitted to other types of questions is no problem, is not a line segment tree subject,

CodePudding user response:

0 _0_33084192_29606. CPP (31) : fatal error C1075: and on the left side of the curly braces "{" (in" 0 _0_33084192_29606. CPP (23) ") match before the end of the file,,, my two segment tree code has this thing, is this why????
  • Related