From d2ae7650a0ee552d4aead0cdc09d64b2d22aa78b Mon Sep 17 00:00:00 2001 From: arielherself Date: Thu, 16 Jan 2025 00:16:38 +0800 Subject: [PATCH] add: fast io --- misc/fastio.cc | 22 ++++++++++++++++++++++ trees/segtree_generic.cc | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 misc/fastio.cc diff --git a/misc/fastio.cc b/misc/fastio.cc new file mode 100644 index 0000000..a6ea7cf --- /dev/null +++ b/misc/fastio.cc @@ -0,0 +1,22 @@ +char *p1,*p2,buf[100000]; +#define nc() (p1==p2 && (p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++) +inline int fastread() { + int x=0,f=1; + char ch=nc(); + while(ch<48||ch>57) { + if(ch=='-') f=-1; + ch=nc(); + } + while(ch>=48&&ch<=57) + x=x*10+ch-48,ch=nc(); + return x*f; +} + +void fastwrite(int x) { + if(x<0) putchar('-'),x=-x; + if(x>9) fastwrite(x/10); + putchar(x%10+'0'); + return; +} + + diff --git a/trees/segtree_generic.cc b/trees/segtree_generic.cc index 69d15cd..ae4ed03 100644 --- a/trees/segtree_generic.cc +++ b/trees/segtree_generic.cc @@ -28,7 +28,7 @@ private: else set(m + 1, t, p * 2 + 1, x, c); pull(p); } - + void range_apply(size_type s, size_type t, size_type p, size_type l, size_type r, const tag_type& c) { if (l <= s && t <= r) { d[p].apply(c, t - s + 1); @@ -73,7 +73,7 @@ public: void set(size_type i, const info_type& c) { set({}, _max, 1, i, c); } - + void range_apply(size_type l, size_type r, const tag_type& c) { range_apply({}, _max, 1, l, r, c); }