关于ios::sync_with_stdio(false)

时间:2023-03-08 19:11:15

  作用就是取消同步,这样的话使用cin就和使用scanf效率相似。

  但是今天在做题的时候碰到一点小问题,就是在关闭同步的时候使用scanf是交了一发代码,然后RE了(经检查scanf没有写错),而把关同步注释后就AC了

不是很理解,先记下来在研究研究

  附上今天做题代码:(很水的一题即可瞎搞又可线段树)  

  HDU-5443

  

 #include <bits/stdc++.h>

 using namespace std;

 const int N = 1e5;

 #define lson rt<<1, left, m
 #define rson rt<<1|1, m+1, right

 struct Node
 {
     int left, right, value;
     int mid()
     {
         ;
     }
 }node[N<<];

 void Build(int rt, int left, int right)
 {
     node[rt].left = left;
     node[rt].right = right;
     node[rt].value = ;
     if(left == right)
     {
         //scanf("%d", &node[rt].value);
         cin>>node[rt].value;
         return;
     }
     int m = node[rt].mid();
     Build(lson);
     Build(rson);
     node[rt].value = max(node[rt<<].value, node[rt<<|].value);
 }

 int Query(int rt, int left, int right)
 {
     int L = node[rt].left, R = node[rt].right;

     if((node[rt].left >= left) && (node[rt].right <= right))
     {
         return node[rt].value;
     }

     int m = node[rt].mid();

     if(right <= m)
     {
         , left, right);
     }
     else if(left > m)
     {
         |, left, right);
     }
     else
     {
         , left, m), Query(rt<<|, m+, right));
     }
 }

 int main()
 {
     ios::sync_with_stdio(false);
     int n;
     cin>>n;
     {
         int m, a, b, c;
         while(n--)
         {
             cin>>m;
             Build(, , m);
             cin>>a;
             while(a--)
             {
                 cin>>b>>c;
                 cout<<Query(, b, c)<<endl;
             }
         }
     }
     ;
 }