Home > Back-end >  Strange question about printf (C)
Strange question about printf (C)

Time:02-20

Why the printf is stressed in this within a for loop join any 1 printf (can not output anything), can obtain the normal conclusion?? Ignoring the printf get strange answers, and the plustree cycle use this function, you make mistakes without the printf
Closed questions (the original, so can't show, this code is part of the data is failed)
If there are who can help me to point out that the inside of the code of other errors is better
 # include 
# include
using namespace std;
Const int L=0, R=1;
Struct Seg {
Int l, r;
Int son [2];
Int plusm=0;
} c [400005];
Int f [200005], [200005] s, CNTS=0;
Int n, m, a [200005], CNT=1;
Void buildtree (int k, int l, int r) {
//printf (" % d % d % d k \ n ", k, l, r);
C [k]. L=l; C [k]. R=r;
If (l==r) return;
Int mid=(l + r)/2;
Cnt++; C [k]. Son [L]=CNT;
Buildtree (c [k]. Son [L], L, mid);
Cnt++; C [k]. Son [R]=CNT;
Buildtree (c [k]. Son [R], mid + 1, R);
return;
}
Void addtree (int k, int l, int r, int v) {
If (c [k]. L==l& & C [k]. R==r) {
C [k]. Plusm +=v;
return;
}
Int mid=(c [k]. [k]. L + c r)/2;
//printf (" % d % d % d % d \ n ", k, l, r, mid);
If (l<=mid) addtree (c [k]. Son [L], L, min (mids, r), v);
If (r> Mid) addtree (c [k]. Son [R], Max (mids + 1, l), R, v);
}
{int plustree1 (int k, int j)
If (c [k]. [k]. L==c r) {
Printf (" k=% d - the plustree function return value % d \ n ", k, c [k]. Plusm);//test code
Return c [k]. Plusm;
}
Int q;
Int mid=(c [k]. [k]. L + c r)/2;
If (j<=mid) q +=plustree1 (c [k]. Son [L], j);
The else q +=plustree1 (c [k]. Son [R], j);
Printf (" k=% d - the plustree function return value % d \ n ", k, c [k]. Plusm + q);//test code
Return c [k]. Plusm + q;
}
Int main () {
F [0]=f [1]=1;
For (int I=2; i<=200005; + + I) f=f [I] [I - 1) + f [I - 2);
The scanf (" % d % d ", & amp; N, & amp; M);
for(int i=1; i<=n; + + I) the scanf (" % d ", & amp; A [I]);
Int root=1;
Buildtree (root, 1, n);
For (int ii=1; Ii<=m; + + ii) {
Int t;
The scanf (" % d ", & amp; T);
If (t==1) {
Int x, v.
The scanf (" % d % d ", & amp; X, & amp; V);
A [x]=v - plustree1 (1, x);
}
If (t==2) {
Int l, r, su=0;
The scanf (" % d % d ", & amp; L, & amp; R);
Int v=r - l;
Int suj [205].//suj is used to record the change of the su
for(int i=0; i<=v; + + I) {
Su +=(f [I] * (a/l + I + plustree1 (1, l + I))) % 1000000000;
Su %=1000000000; Printf (" ");//this is the printf<<<<<<<<
Suj [I]=su;
}
Printf (" suj array is used to record the change of the su: \ n ");
for(int i=0; i<=v; + + I) {
Printf (" suj [% d]=% d \ n ", I, suj [I]);
}

Cnts++;
S (CNTS)=su;//printf (" % d \ n ", su);
}
If (t==3) {
Int l2, r2, d;
The scanf (" % d % d % d ", & amp; L2, & amp; R2, & amp; d);
Addtree (1, l2, r2, d);
}
}
for(int i=1; i<=CNTS; + + I) {
if(i!=1) printf (" \ n ");
Printf (" % d ", s [I]);
}
return 0;
}

The following sample data:
5 4
1 1 2 3 4
3 4 1
2 2 4
1 2 10
2 1 5
The sample correct answer:
12
45
Joined the printf program results:

Didn't add this printf program results:

CodePudding user response:

 f [0]=f [1]=1; 
For (int I=2; i<=200005; + + I) f=f [I] [I - 1) + f [I - 2);//here early breakthrough the limit
  • Related