关于ios::sync_with_stdio(false)
作用就是取消同步,这样的话使用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; } } } ; }
关于ios::sync_with_stdio(false)的更多相关文章
- 关于C++中ios::sync_with_stdio(false)
粘贴自:https://blog.csdn.net/weixin_44015865/article/details/84974373 在C++中的输入和输出有两种方式,一种是scanf和printf, ...
- ios::sync_with_stdio(false)提高C++读写速度
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:ios::sync_with_stdio(false)提高C++读写速度 本文地址:h ...
- 关于std::ios::sync_with_stdio(false)
std::ios::sync_with_stdio(false); 很多C++的初学者可能会被这个问题困扰,经常出现程序无故超时,最终发现问题处在cin和cout上,(甚至有些老oier也会被这个问题 ...
- 关于ios::sync_with_stdio(false);和 cin.tie(0)加速c++输入输出流
原文地址:http://www.hankcs.com/program/cpp/cin-tie-with-sync_with_stdio-acceleration-input-and-output.ht ...
- hdu 1754 I Hate It (线段树、单点更新)(PS:ios::sync_with_stdio(false)可以加快cin、cout的读取写出速度)
I Hate ItTime Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- C++输入输出流加速器,关闭同步流,ios::sync_with_stdio(false)和 cin.tie(0)
leetcode练习时,总会发现运行时间短的代码都会有类似: static int x=[](){ std::ios::sync_with_stdio(false); cin.tie(NULL); ; ...
- C++关闭同步流 ios::sync_with_stdio(false)
说明:ios::sync_with_stdio(false) 1.这句语句是用来取消cin的同步,什么叫同步呢?就是iostream的缓冲跟stdio的同步.这就是为什么cin和cout比scanf和 ...
- std:ios:sync_with_stdio (false)以及局限性
如何在输入输出上提高一下效率emmmm #include<iostream> #include<stdio.h> #include<stdlib.h> #inclu ...
- std::ios::sync_with_stdio(false);
这句语句是用来取消cin的同步,什么叫同步呢?就是iostream的缓冲跟stdio的同步.如果你已经在头文件上用了using namespace std;那么就可以去掉前面的std::了.取消后就c ...
随机推荐
- C++11 学习 间隔更新中
1.*this 返回执行它的的对象的引用,this返回的是地址,这涉及C++对象模式有可能是对象的首地址,有可能是首地址加上虚表的长度, 一般是*this ,有不同意见的可以提出来讨论 2.初始化列表 ...
- Java并发基础——Thread
并发编程可以使我们将程序划分为多个分离的,独立运行的任务.通过多线程机制,这些独立任务都将由执行线程来驱动.在使用线程时,CPU将轮流给每个任务分配占用时间,每个任务都觉得自己在占用CPU,但实际上C ...
- 给Linux RedHat7 设置启动终端的快捷键
RedHat7中设置启动终端的快捷键... ------------------------------ 征服Linux从终端开始 ---------------------------------- ...
- python中的collections.namedtuple
简介 collections.namedtuple是一个工厂方法,它可以动态的创建一个继承tuple的子类.跟tuple相比,返回的子类可以使用名称来访问元素. 使用方法 用一个例子来介绍: > ...
- Java温故而知新-空心菱形
空心菱形 今天做题练手,题目是空心菱形,一开始没什么思路,去网上找了找,发现很难找到讲的通透的,自己现在独立做出来了,记录一下,以备后用. * * * * * * * * * * * * * * * ...
- Python学习笔记6
raw_input 与 input 使用input和raw_input都可以读取控制台的输入,但是input和raw_input在处理数字时是有区别的 当输入为纯数字时 input返回的是数值类型,如 ...
- Extjs:添加查看全部按钮
var grid =new Ext.grid.GridPanel({ renderTo:'tsllb', title:'产品成本列表', selModel:csm, height:350, colum ...
- 原创: rsync软件服务利用ansible实现一键化部署
---恢复内容开始--- 首先创建一个脚本文件 /server/tools/peizhi.sh cat /server/tools/peizhi.sh cat >>/etc/rsyncd ...
- HAproxy功能配置
author:JevonWei 版权声明:原创作品 haproxy配置文档 https://cbonte.github.io/haproxy-dconv/ 环境 前端HAProxy 172.16.25 ...
- 【★】KMP算法完整教程
KMP算法完整教程 全称: Knuth_Morris_Pratt Algorithm(KMP算法) 类型: ...