diff --git a/Algorithms/DSU.cpp b/Algorithms/DSU.cpp new file mode 100644 index 0000000..e69de29 diff --git a/Algorithms/HeapSort b/Algorithms/HeapSort new file mode 100755 index 0000000..e4a1529 Binary files /dev/null and b/Algorithms/HeapSort differ diff --git a/Algorithms/HeapSort.cpp b/Algorithms/HeapSort.cpp new file mode 100644 index 0000000..43bf2ed --- /dev/null +++ b/Algorithms/HeapSort.cpp @@ -0,0 +1,49 @@ +#include +using namespace std; + +int a[]={0, 36, 21, 16, 31, 58, 41, 26, 59, 53, 97}; + +void heapify(int a[], int n, int i) +{ + if(i<=n && 2*i<=n) + { + int largest = i, left = 2*i, right = 2*i +1 ; + int index=((left<=n?a[left]:0)>(right<=n?a[right]:0))?left:right; //left and right mese maximum + if(a[largest]>a[index]) return; + if(largest != index && a[largest]0; i--) + { + // printf("i= %d\n", i); + heapify(a,n,i); + } + + for(int i=n;i>0;i--) + { + if(a[1] +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace pretty_print +{ + namespace detail + { + // SFINAE type trait to detect whether T::const_iterator exists. + + struct sfinae_base + { + using yes = char; + using no = yes[2]; + }; + + template + struct has_const_iterator : private sfinae_base + { + private: + template static yes & test(typename C::const_iterator*); + template static no & test(...); + public: + static const bool value = sizeof(test(nullptr)) == sizeof(yes); + using type = T; + }; + + template + struct has_begin_end : private sfinae_base + { + private: + template + static yes & f(typename std::enable_if< + std::is_same(&C::begin)), + typename C::const_iterator(C::*)() const>::value>::type *); + + template static no & f(...); + + template + static yes & g(typename std::enable_if< + std::is_same(&C::end)), + typename C::const_iterator(C::*)() const>::value, void>::type*); + + template static no & g(...); + + public: + static bool const beg_value = sizeof(f(nullptr)) == sizeof(yes); + static bool const end_value = sizeof(g(nullptr)) == sizeof(yes); + }; + + } // namespace detail + + + // Holds the delimiter values for a specific character type + + template + struct delimiters_values + { + using char_type = TChar; + const char_type * prefix; + const char_type * delimiter; + const char_type * postfix; + }; + + + // Defines the delimiter values for a specific container and character type + + template + struct delimiters + { + using type = delimiters_values; + static const type values; + }; + + + // Functor to print containers. You can use this directly if you want + // to specificy a non-default delimiters type. The printing logic can + // be customized by specializing the nested template. + + template , + typename TDelimiters = delimiters> + struct print_container_helper + { + using delimiters_type = TDelimiters; + using ostream_type = std::basic_ostream; + + template + struct printer + { + static void print_body(const U & c, ostream_type & stream) + { + using std::begin; + using std::end; + + auto it = begin(c); + const auto the_end = end(c); + + if (it != the_end) + { + for ( ; ; ) + { + stream << *it; + + if (++it == the_end) break; + + if (delimiters_type::values.delimiter != NULL) + stream << delimiters_type::values.delimiter; + } + } + } + }; + + print_container_helper(const T & container) + : container_(container) + { } + + inline void operator()(ostream_type & stream) const + { + if (delimiters_type::values.prefix != NULL) + stream << delimiters_type::values.prefix; + + printer::print_body(container_, stream); + + if (delimiters_type::values.postfix != NULL) + stream << delimiters_type::values.postfix; + } + + private: + const T & container_; + }; + + // Specialization for pairs + + template + template + struct print_container_helper::printer> + { + using ostream_type = typename print_container_helper::ostream_type; + + static void print_body(const std::pair & c, ostream_type & stream) + { + stream << c.first; + if (print_container_helper::delimiters_type::values.delimiter != NULL) + stream << print_container_helper::delimiters_type::values.delimiter; + stream << c.second; + } + }; + + // Specialization for tuples + + template + template + struct print_container_helper::printer> + { + using ostream_type = typename print_container_helper::ostream_type; + using element_type = std::tuple; + + template struct Int { }; + + static void print_body(const element_type & c, ostream_type & stream) + { + tuple_print(c, stream, Int<0>()); + } + + static void tuple_print(const element_type &, ostream_type &, Int) + { + } + + static void tuple_print(const element_type & c, ostream_type & stream, + typename std::conditional, std::nullptr_t>::type) + { + stream << std::get<0>(c); + tuple_print(c, stream, Int<1>()); + } + + template + static void tuple_print(const element_type & c, ostream_type & stream, Int) + { + if (print_container_helper::delimiters_type::values.delimiter != NULL) + stream << print_container_helper::delimiters_type::values.delimiter; + + stream << std::get(c); + + tuple_print(c, stream, Int()); + } + }; + + // Prints a print_container_helper to the specified stream. + + template + inline std::basic_ostream & operator<<( + std::basic_ostream & stream, + const print_container_helper & helper) + { + helper(stream); + return stream; + } + + + // Basic is_container template; specialize to derive from std::true_type for all desired container types + + template + struct is_container : public std::integral_constant::value && + detail::has_begin_end::beg_value && + detail::has_begin_end::end_value> { }; + + template + struct is_container : std::true_type { }; + + template + struct is_container : std::false_type { }; + + template + struct is_container> : std::true_type { }; + + template + struct is_container> : std::true_type { }; + + template + struct is_container> : std::true_type { }; + + + // Default delimiters + + template struct delimiters { static const delimiters_values values; }; + template const delimiters_values delimiters::values = { "[", ", ", "]" }; + template struct delimiters { static const delimiters_values values; }; + template const delimiters_values delimiters::values = { L"[", L", ", L"]" }; + + + // Delimiters for (multi)set and unordered_(multi)set + + template + struct delimiters< ::std::set, char> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::set, char>::values = { "{", ", ", "}" }; + + template + struct delimiters< ::std::set, wchar_t> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::set, wchar_t>::values = { L"{", L", ", L"}" }; + + template + struct delimiters< ::std::multiset, char> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::multiset, char>::values = { "{", ", ", "}" }; + + template + struct delimiters< ::std::multiset, wchar_t> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::multiset, wchar_t>::values = { L"{", L", ", L"}" }; + + template + struct delimiters< ::std::unordered_set, char> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::unordered_set, char>::values = { "{", ", ", "}" }; + + template + struct delimiters< ::std::unordered_set, wchar_t> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::unordered_set, wchar_t>::values = { L"{", L", ", L"}" }; + + template + struct delimiters< ::std::unordered_multiset, char> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::unordered_multiset, char>::values = { "{", ", ", "}" }; + + template + struct delimiters< ::std::unordered_multiset, wchar_t> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::unordered_multiset, wchar_t>::values = { L"{", L", ", L"}" }; + + + // Delimiters for pair and tuple + + template struct delimiters, char> { static const delimiters_values values; }; + template const delimiters_values delimiters, char>::values = { "(", ", ", ")" }; + template struct delimiters< ::std::pair, wchar_t> { static const delimiters_values values; }; + template const delimiters_values delimiters< ::std::pair, wchar_t>::values = { L"(", L", ", L")" }; + + template struct delimiters, char> { static const delimiters_values values; }; + template const delimiters_values delimiters, char>::values = { "(", ", ", ")" }; + template struct delimiters< ::std::tuple, wchar_t> { static const delimiters_values values; }; + template const delimiters_values delimiters< ::std::tuple, wchar_t>::values = { L"(", L", ", L")" }; + + + // Type-erasing helper class for easy use of custom delimiters. + // Requires TCharTraits = std::char_traits and TChar = char or wchar_t, and MyDelims needs to be defined for TChar. + // Usage: "cout << pretty_print::custom_delims(x)". + + struct custom_delims_base + { + virtual ~custom_delims_base() { } + virtual std::ostream & stream(::std::ostream &) = 0; + virtual std::wostream & stream(::std::wostream &) = 0; + }; + + template + struct custom_delims_wrapper : custom_delims_base + { + custom_delims_wrapper(const T & t_) : t(t_) { } + + std::ostream & stream(std::ostream & s) + { + return s << print_container_helper, Delims>(t); + } + + std::wostream & stream(std::wostream & s) + { + return s << print_container_helper, Delims>(t); + } + + private: + const T & t; + }; + + template + struct custom_delims + { + template + custom_delims(const Container & c) : base(new custom_delims_wrapper(c)) { } + + std::unique_ptr base; + }; + + template + inline std::basic_ostream & operator<<(std::basic_ostream & s, const custom_delims & p) + { + return p.base->stream(s); + } + + + // A wrapper for a C-style array given as pointer-plus-size. + // Usage: std::cout << pretty_print_array(arr, n) << std::endl; + + template + struct array_wrapper_n + { + typedef const T * const_iterator; + typedef T value_type; + + array_wrapper_n(const T * const a, size_t n) : _array(a), _n(n) { } + inline const_iterator begin() const { return _array; } + inline const_iterator end() const { return _array + _n; } + + private: + const T * const _array; + size_t _n; + }; + + + // A wrapper for hash-table based containers that offer local iterators to each bucket. + // Usage: std::cout << bucket_print(m, 4) << std::endl; (Prints bucket 5 of container m.) + + template + struct bucket_print_wrapper + { + typedef typename T::const_local_iterator const_iterator; + typedef typename T::size_type size_type; + + const_iterator begin() const + { + return m_map.cbegin(n); + } + + const_iterator end() const + { + return m_map.cend(n); + } + + bucket_print_wrapper(const T & m, size_type bucket) : m_map(m), n(bucket) { } + + private: + const T & m_map; + const size_type n; + }; + +} // namespace pretty_print + + +// Global accessor functions for the convenience wrappers + +template +inline pretty_print::array_wrapper_n pretty_print_array(const T * const a, size_t n) +{ + return pretty_print::array_wrapper_n(a, n); +} + +template pretty_print::bucket_print_wrapper +bucket_print(const T & m, typename T::size_type n) +{ + return pretty_print::bucket_print_wrapper(m, n); +} + + +// Main magic entry point: An overload snuck into namespace std. +// Can we do better? + +namespace std +{ + // Prints a container to the stream using default delimiters + + template + inline typename enable_if< ::pretty_print::is_container::value, + basic_ostream &>::type + operator<<(basic_ostream & stream, const T & container) + { + return stream << ::pretty_print::print_container_helper(container); + } +} + +#endif // H_PRETTY_PRINT diff --git a/ICPC/KCHESS b/ICPC/KCHESS new file mode 100755 index 0000000..34e201e Binary files /dev/null and b/ICPC/KCHESS differ diff --git a/ICPC/KCHESS.cpp b/ICPC/KCHESS.cpp new file mode 100644 index 0000000..4fba906 --- /dev/null +++ b/ICPC/KCHESS.cpp @@ -0,0 +1,85 @@ +#include +using namespace std; + +#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) +#define debug(x) do { std::cerr << #x << ": " << x << std::endl; } while (0) +#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) + +#define ll long long + +ll n,t,x,y,a,b; +int X[]={1,2,-1,-2,-1,-2,1,2}; +int Y[]={2,1,2,1,-2,-1,-2,-1}; +int X1[]={1,0,1,-1,0,-1,-1,1}; +int Y1[]={0,1,1,0,-1,1,-1,-1}; +vector > posknight; +vector > poscov; + +int32_t main() +{ + fast_io(); + cin>>t; + while(t--) + { + cin>>n; + for(int i=1;i<=n;i++) + { + + cin>>x>>y; + posknight.push_back({x,y}); + } + + cin>>a>>b; + + + for(int i=0;i p=make_pair(a+X1[i],b+Y1[i]); + if(find(poscov.begin(), poscov.end(), p)==poscov.end()) + { + // cout< + #include + #include + int main() + { + std::vector> v = {{1,2}, {3,4}, {5,6}}; + auto p = std::make_pair(3, 4); + + if(std::find(v.begin(), v.end(), p) != v.end()) + std::cout << "yes\n"; + }*/ \ No newline at end of file diff --git a/ICPC/PNTWLL b/ICPC/PNTWLL new file mode 100755 index 0000000..ecea9e8 Binary files /dev/null and b/ICPC/PNTWLL differ diff --git a/ICPC/PNTWLL.cpp b/ICPC/PNTWLL.cpp new file mode 100644 index 0000000..993a7b8 --- /dev/null +++ b/ICPC/PNTWLL.cpp @@ -0,0 +1,69 @@ +#include +using namespace std; + +#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) +#define debug(x) do { std::cerr << #x << ": " << x << std::endl; } while (0) +#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) + +#define ll long long + +ll n,m,t,h,c,a,b; +map colours; +// int X[]={1,2,-1,-2,-1,-2,1,2}; +// int Y[]={2,1,2,1,-2,-1,-2,-1}; +// int X1[]={1,0,1,-1,0,-1,-1,1}; +// int Y1[]={0,1,1,0,-1,1,-1,-1}; +vector > student; +// vector > poscov; + +int32_t main() +{ + fast_io(); + cin>>t; + while(t--) + { + for(int i=0;i>n>>m; + int count=0; + for(int i=0;i>h; + student.push_back({h,0}); + } + + // cin>>a>>b; + + for(int i=0;i>c; + student[i].second=c; + } + + /*for(int i=0;i +using namespace std; + +#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) +#define debug(x) do { std::cerr << #x << ": " << x << std::endl; } while (0) +#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) + +#define ll long long + +ll n,k; +ll a[55]; + +int32_t main() +{ + int t; + cin>>t; + while(t--) + { + cin>>n>>k; + for(int i=1;i<=n;i++) + { + cin>>a[i]; + } + + sort(a[i]); + + for(int i=1;i +using namespace std; + +#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) +#define debug(x) do { std::cerr << #x << ": " << x << std::endl; } while (0) +#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) + +#define ll long long + +ll n; + +int32_t main() +{ + int t; + while() +} diff --git a/ICPC/prettyprint.hpp b/ICPC/prettyprint.hpp new file mode 100644 index 0000000..f0df2a7 --- /dev/null +++ b/ICPC/prettyprint.hpp @@ -0,0 +1,444 @@ +// Copyright Louis Delacroix 2010 - 2014. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// A pretty printing library for C++ +// +// Usage: +// Include this header, and operator<< will "just work". + +#ifndef H_PRETTY_PRINT +#define H_PRETTY_PRINT + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace pretty_print +{ + namespace detail + { + // SFINAE type trait to detect whether T::const_iterator exists. + + struct sfinae_base + { + using yes = char; + using no = yes[2]; + }; + + template + struct has_const_iterator : private sfinae_base + { + private: + template static yes & test(typename C::const_iterator*); + template static no & test(...); + public: + static const bool value = sizeof(test(nullptr)) == sizeof(yes); + using type = T; + }; + + template + struct has_begin_end : private sfinae_base + { + private: + template + static yes & f(typename std::enable_if< + std::is_same(&C::begin)), + typename C::const_iterator(C::*)() const>::value>::type *); + + template static no & f(...); + + template + static yes & g(typename std::enable_if< + std::is_same(&C::end)), + typename C::const_iterator(C::*)() const>::value, void>::type*); + + template static no & g(...); + + public: + static bool const beg_value = sizeof(f(nullptr)) == sizeof(yes); + static bool const end_value = sizeof(g(nullptr)) == sizeof(yes); + }; + + } // namespace detail + + + // Holds the delimiter values for a specific character type + + template + struct delimiters_values + { + using char_type = TChar; + const char_type * prefix; + const char_type * delimiter; + const char_type * postfix; + }; + + + // Defines the delimiter values for a specific container and character type + + template + struct delimiters + { + using type = delimiters_values; + static const type values; + }; + + + // Functor to print containers. You can use this directly if you want + // to specificy a non-default delimiters type. The printing logic can + // be customized by specializing the nested template. + + template , + typename TDelimiters = delimiters> + struct print_container_helper + { + using delimiters_type = TDelimiters; + using ostream_type = std::basic_ostream; + + template + struct printer + { + static void print_body(const U & c, ostream_type & stream) + { + using std::begin; + using std::end; + + auto it = begin(c); + const auto the_end = end(c); + + if (it != the_end) + { + for ( ; ; ) + { + stream << *it; + + if (++it == the_end) break; + + if (delimiters_type::values.delimiter != NULL) + stream << delimiters_type::values.delimiter; + } + } + } + }; + + print_container_helper(const T & container) + : container_(container) + { } + + inline void operator()(ostream_type & stream) const + { + if (delimiters_type::values.prefix != NULL) + stream << delimiters_type::values.prefix; + + printer::print_body(container_, stream); + + if (delimiters_type::values.postfix != NULL) + stream << delimiters_type::values.postfix; + } + + private: + const T & container_; + }; + + // Specialization for pairs + + template + template + struct print_container_helper::printer> + { + using ostream_type = typename print_container_helper::ostream_type; + + static void print_body(const std::pair & c, ostream_type & stream) + { + stream << c.first; + if (print_container_helper::delimiters_type::values.delimiter != NULL) + stream << print_container_helper::delimiters_type::values.delimiter; + stream << c.second; + } + }; + + // Specialization for tuples + + template + template + struct print_container_helper::printer> + { + using ostream_type = typename print_container_helper::ostream_type; + using element_type = std::tuple; + + template struct Int { }; + + static void print_body(const element_type & c, ostream_type & stream) + { + tuple_print(c, stream, Int<0>()); + } + + static void tuple_print(const element_type &, ostream_type &, Int) + { + } + + static void tuple_print(const element_type & c, ostream_type & stream, + typename std::conditional, std::nullptr_t>::type) + { + stream << std::get<0>(c); + tuple_print(c, stream, Int<1>()); + } + + template + static void tuple_print(const element_type & c, ostream_type & stream, Int) + { + if (print_container_helper::delimiters_type::values.delimiter != NULL) + stream << print_container_helper::delimiters_type::values.delimiter; + + stream << std::get(c); + + tuple_print(c, stream, Int()); + } + }; + + // Prints a print_container_helper to the specified stream. + + template + inline std::basic_ostream & operator<<( + std::basic_ostream & stream, + const print_container_helper & helper) + { + helper(stream); + return stream; + } + + + // Basic is_container template; specialize to derive from std::true_type for all desired container types + + template + struct is_container : public std::integral_constant::value && + detail::has_begin_end::beg_value && + detail::has_begin_end::end_value> { }; + + template + struct is_container : std::true_type { }; + + template + struct is_container : std::false_type { }; + + template + struct is_container> : std::true_type { }; + + template + struct is_container> : std::true_type { }; + + template + struct is_container> : std::true_type { }; + + + // Default delimiters + + template struct delimiters { static const delimiters_values values; }; + template const delimiters_values delimiters::values = { "[", ", ", "]" }; + template struct delimiters { static const delimiters_values values; }; + template const delimiters_values delimiters::values = { L"[", L", ", L"]" }; + + + // Delimiters for (multi)set and unordered_(multi)set + + template + struct delimiters< ::std::set, char> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::set, char>::values = { "{", ", ", "}" }; + + template + struct delimiters< ::std::set, wchar_t> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::set, wchar_t>::values = { L"{", L", ", L"}" }; + + template + struct delimiters< ::std::multiset, char> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::multiset, char>::values = { "{", ", ", "}" }; + + template + struct delimiters< ::std::multiset, wchar_t> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::multiset, wchar_t>::values = { L"{", L", ", L"}" }; + + template + struct delimiters< ::std::unordered_set, char> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::unordered_set, char>::values = { "{", ", ", "}" }; + + template + struct delimiters< ::std::unordered_set, wchar_t> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::unordered_set, wchar_t>::values = { L"{", L", ", L"}" }; + + template + struct delimiters< ::std::unordered_multiset, char> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::unordered_multiset, char>::values = { "{", ", ", "}" }; + + template + struct delimiters< ::std::unordered_multiset, wchar_t> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::unordered_multiset, wchar_t>::values = { L"{", L", ", L"}" }; + + + // Delimiters for pair and tuple + + template struct delimiters, char> { static const delimiters_values values; }; + template const delimiters_values delimiters, char>::values = { "(", ", ", ")" }; + template struct delimiters< ::std::pair, wchar_t> { static const delimiters_values values; }; + template const delimiters_values delimiters< ::std::pair, wchar_t>::values = { L"(", L", ", L")" }; + + template struct delimiters, char> { static const delimiters_values values; }; + template const delimiters_values delimiters, char>::values = { "(", ", ", ")" }; + template struct delimiters< ::std::tuple, wchar_t> { static const delimiters_values values; }; + template const delimiters_values delimiters< ::std::tuple, wchar_t>::values = { L"(", L", ", L")" }; + + + // Type-erasing helper class for easy use of custom delimiters. + // Requires TCharTraits = std::char_traits and TChar = char or wchar_t, and MyDelims needs to be defined for TChar. + // Usage: "cout << pretty_print::custom_delims(x)". + + struct custom_delims_base + { + virtual ~custom_delims_base() { } + virtual std::ostream & stream(::std::ostream &) = 0; + virtual std::wostream & stream(::std::wostream &) = 0; + }; + + template + struct custom_delims_wrapper : custom_delims_base + { + custom_delims_wrapper(const T & t_) : t(t_) { } + + std::ostream & stream(std::ostream & s) + { + return s << print_container_helper, Delims>(t); + } + + std::wostream & stream(std::wostream & s) + { + return s << print_container_helper, Delims>(t); + } + + private: + const T & t; + }; + + template + struct custom_delims + { + template + custom_delims(const Container & c) : base(new custom_delims_wrapper(c)) { } + + std::unique_ptr base; + }; + + template + inline std::basic_ostream & operator<<(std::basic_ostream & s, const custom_delims & p) + { + return p.base->stream(s); + } + + + // A wrapper for a C-style array given as pointer-plus-size. + // Usage: std::cout << pretty_print_array(arr, n) << std::endl; + + template + struct array_wrapper_n + { + typedef const T * const_iterator; + typedef T value_type; + + array_wrapper_n(const T * const a, size_t n) : _array(a), _n(n) { } + inline const_iterator begin() const { return _array; } + inline const_iterator end() const { return _array + _n; } + + private: + const T * const _array; + size_t _n; + }; + + + // A wrapper for hash-table based containers that offer local iterators to each bucket. + // Usage: std::cout << bucket_print(m, 4) << std::endl; (Prints bucket 5 of container m.) + + template + struct bucket_print_wrapper + { + typedef typename T::const_local_iterator const_iterator; + typedef typename T::size_type size_type; + + const_iterator begin() const + { + return m_map.cbegin(n); + } + + const_iterator end() const + { + return m_map.cend(n); + } + + bucket_print_wrapper(const T & m, size_type bucket) : m_map(m), n(bucket) { } + + private: + const T & m_map; + const size_type n; + }; + +} // namespace pretty_print + + +// Global accessor functions for the convenience wrappers + +template +inline pretty_print::array_wrapper_n pretty_print_array(const T * const a, size_t n) +{ + return pretty_print::array_wrapper_n(a, n); +} + +template pretty_print::bucket_print_wrapper +bucket_print(const T & m, typename T::size_type n) +{ + return pretty_print::bucket_print_wrapper(m, n); +} + + +// Main magic entry point: An overload snuck into namespace std. +// Can we do better? + +namespace std +{ + // Prints a container to the stream using default delimiters + + template + inline typename enable_if< ::pretty_print::is_container::value, + basic_ostream &>::type + operator<<(basic_ostream & stream, const T & container) + { + return stream << ::pretty_print::print_container_helper(container); + } +} + +#endif // H_PRETTY_PRINT diff --git a/kartik.txt b/kartik.txt new file mode 100644 index 0000000..edba6aa --- /dev/null +++ b/kartik.txt @@ -0,0 +1 @@ +hwllo nidbvkjbsvksfv diff --git a/nimrodcoder.txt b/nimrodcoder.txt new file mode 100644 index 0000000..dbe6884 --- /dev/null +++ b/nimrodcoder.txt @@ -0,0 +1 @@ +I am a bad girl or am i? diff --git a/spoj/496B b/spoj/496B new file mode 100755 index 0000000..a09812d Binary files /dev/null and b/spoj/496B differ diff --git a/spoj/496B.cpp b/spoj/496B.cpp new file mode 100644 index 0000000..c5ac4a2 --- /dev/null +++ b/spoj/496B.cpp @@ -0,0 +1,40 @@ +#include +using namespace std; +#define ll long long + +string a,b; +ll dp[2005][2005]; + +int main() +{ + int t; + cin>>t; + while(t--) + { + cin>>a>>b; + memset(dp,0,sizeof(dp)); + + for(int i=1;i<=a.length();i++) + { + dp[i][0]=i; + } + + for(int i=1;i<=b.length();i++) + { + dp[0][i]=i; + } + + for(int i=1;i<=a.length();i++) + { + for(int j=1;j<=b.length();j++) + { + if(a[i-1]!=b[j-1]) + dp[i][j]=1+dp[i-1][j]; + else + dp[i][j]=dp[i-1][j-1]; + } + } + + printf("%lld\n",dp[a.length()][b.length()]); + } +} \ No newline at end of file diff --git a/spoj/AAC1 b/spoj/AAC1 new file mode 100755 index 0000000..f695207 Binary files /dev/null and b/spoj/AAC1 differ diff --git a/spoj/AAC1'1.cpp b/spoj/AAC1'1.cpp new file mode 100644 index 0000000..e69de29 diff --git a/spoj/AAC1.cpp b/spoj/AAC1.cpp new file mode 100644 index 0000000..a5ee979 --- /dev/null +++ b/spoj/AAC1.cpp @@ -0,0 +1,72 @@ +#include +using namespace std; +long long int a[10000][10000]; +bool vis[10000]; + + + +int main() +{ + long long int t; + cin>>t; + while(t--) + { + long long int n,m,x,y; + cin>>n>>m; + + memset(a,2,sizeof(a)); + memset(vis,false,sizeof(vis)); + + for(long long int i=0;i>x>>y; + a[x-1][y-1]=1; + a[y-1][x-1]=1; + } + + // stack p; + long long int dist[n]; + memset(dist,2,sizeof(dist)); + + long long int min_index=0; + dist[0]=0; + + while(min_index!=n-1) + { + long long int index=min_index; + vis[index]=true; + + for(long long int i=0;idist[i]?dist[i]:(dist[index]+a[index][i]); + // cout< +using namespace std; +#define SIZE 100002 + +vector > adj[SIZE]; +int dist[SIZE]; +bool vis[SIZE]; + +void addedge(int u,int v, int weight) +{ + adj[u].push_back(make_pair(v,weight)); + adj[v].push_back(make_pair(u,weight)); +} + +void dijkstra() +{ + memset(vis,false,sizeof(vis)); + dist[1]=0; + multiset > s; + + s.insert(make_pair(0,1)); + + while(!s.empty()) + { + pair p = *s.begin(); + s.erase(s.begin()); + + int x=p.second; + int wei=p.first; + + if(vis[x]) continue; + + vis[x]=true; + + for(int i=0;i>t; + while(t--) + { + int n,m; + cin>>n>>m; + + for(int i=0;i>x>>y; + addedge(x,y,1); + } + + /*for(int i=0;i +using namespace std; +#define ll long long + +string n; +// mapv; +ll dp[50007]; + +ll acode(string s) +{ + memset(dp,0,sizeof(dp)); + dp[0]=1; + int j,n=s.length(); + for(int i=1;i9 && j<27) + { + if(i==1) + dp[i]=dp[i]+1; + else + dp[i]=dp[i]+dp[i-2]; + } + } + + return dp[n-1]; +} + +int main() +{ + while(true) + { + cin>>n; + if(n!="0") + { + printf("%lld\n",acode(n)); + continue; + } + else + return 0; + } +} \ No newline at end of file diff --git a/spoj/ACODEtest b/spoj/ACODEtest new file mode 100755 index 0000000..2448095 Binary files /dev/null and b/spoj/ACODEtest differ diff --git a/spoj/ACODEtest.cpp b/spoj/ACODEtest.cpp new file mode 100644 index 0000000..14b0ff5 --- /dev/null +++ b/spoj/ACODEtest.cpp @@ -0,0 +1,36 @@ +#include +#include +int main() +{ + char a[5010]; + int i,j; + scanf("%s",a); + while(a[0]!='0') + { + + int n= strlen(a); + long long int b[n]; + for(i=0;i9 && j<27) + { + if(i==1) + b[i]= b[i] + 1; + else + b[i]= b[i] + b[i-2]; + } + + } + printf("%lld\n",b[n-1]); + scanf("%s",a); + } + if(a[0]=='0') + return 0; +} \ No newline at end of file diff --git a/spoj/AKBAR b/spoj/AKBAR new file mode 100755 index 0000000..1be146d Binary files /dev/null and b/spoj/AKBAR differ diff --git a/spoj/AKBAR.cpp b/spoj/AKBAR.cpp new file mode 100644 index 0000000..b770464 --- /dev/null +++ b/spoj/AKBAR.cpp @@ -0,0 +1,105 @@ +#include +using namespace std; +#define SIZE 1000002 + +vector > adj[SIZE]; +// long long bit[SIZE]; +queue q; +bool vis[SIZE]; + +void addedge(int u,int v, int weight) +{ + adj[u].push_back(make_pair(v,weight)); + adj[v].push_back(make_pair(u,weight)); +} + +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + long long n,r,m; + int flag=0; + scanf("%lld %lld %lld",&n,&r,&m); + + for(int i=0;i +using namespace std; +char a[110][110]; +int X[]={1,0,-1,0}; +int Y[]={0,1,0,-1}; +int n,m,tx,ty,k; +// queue >q; +bool vis[110][110]; + +bool issafe(int x,int y){ + if(x>0 && x<=n && y>0 && y<=m) + { + return true; + } + return false; +} + +bool dfs(int x,int y,int steps) +{ + + if(vis[x][y]) + { + if(x==tx && y==ty && steps>=k) + { + return 1; + } + return 0; + } + + vis[x][y]=1; + + int cx,cy; + for(int i=0;i<4;i++) + { + cx=x+X[i]; + cy=y+Y[i]; + + if(issafe(cx,cy) && a[cx][cy]=='.') + { + if(dfs(cx,cy,steps + 1)) + return 1; + } + } + vis[x][y]=0; + return 0; +} + +int main() +{ + // int n,m; + cin>>n>>m; + cin>>k; + cin>>tx>>ty; + + for(int i=1;i<=n;i++) + { + for(int j=1;j<=m;j++) + { + cin>>a[i][j]; + } + } + // memset(vis,false,sizeof(vis)); + + // q.push(make_pair(x,y)); + // vis[x][y]=true; + // q.push(make_pair(-1,-1)); + + /*while(k--) + { + int cx,cy; + pair node=q.front(); + q.pop(); + cx=node.first; + cy=node.second; + // vis[cx][cy]=true;*/ + + // } + + /*int x1,y1; + + x1=q.front().first; + y1=q.front().second; + + if(x1==x && y1==y) + { + printf("YES\n"); + } + else + { + printf("NO\n"); + }*/ + + if(dfs(tx,ty,0)) + { + printf("YES\n"); + } + else + { + printf("NO\n"); + } + +} \ No newline at end of file diff --git a/spoj/ALIEN b/spoj/ALIEN new file mode 100755 index 0000000..83f5d50 Binary files /dev/null and b/spoj/ALIEN differ diff --git a/spoj/ALIEN.cpp b/spoj/ALIEN.cpp new file mode 100644 index 0000000..3917547 --- /dev/null +++ b/spoj/ALIEN.cpp @@ -0,0 +1,52 @@ +#include +using namespace std; +#define ll long long +#define SIZE 100005 + +ll a,b; +ll arr[SIZE]; + +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + scanf("%lld %lld", &a, &b); + // memset(arr,0,sizeof(arr)); + for(int i=0;ib) + { + sum-=arr[i]; + length--; + i++; + } + if(maxlengthsum) + { + minsum=sum; + } + } + } + + printf("%d %d\n", minsum,maxlength); + } + return 0; +} \ No newline at end of file diff --git a/spoj/ALLIZZWELL b/spoj/ALLIZZWELL new file mode 100755 index 0000000..0673ea7 Binary files /dev/null and b/spoj/ALLIZZWELL differ diff --git a/spoj/ALLIZZWELL.cpp b/spoj/ALLIZZWELL.cpp new file mode 100644 index 0000000..9707c6e --- /dev/null +++ b/spoj/ALLIZZWELL.cpp @@ -0,0 +1,101 @@ +#include +using namespace std; + +// stack >st; +int X[]={0, 0, 1, -1, 1, 1, -1, -1}; +int Y[]={1, -1, 0, 0, 1, -1, 1, -1}; +bool vis[101][101]; +char a[101][101]; +char sent[11]={'A','L','L','I','Z','Z','W','E','L','L'}; +int r,c; + +bool issafe(int x,int y) +{ + if(x>=0 && y>=0 && x>t; + + while(t--) + { + int r1,c1; + cin>>r1>>c1; + r=r1; + c=c1; + + memset(vis,false,sizeof(vis)); + + for(int i=0;i>a[i][j]; + } + } + + + bool flag=false; + + + for(int i=0;i +using namespace std; +long long p[10000010]; +long long res[10000010]; +void spf() +{ + + for(int i=2;i<=10000000;i++) + { + if(!p[i]) + { + for(int j=2*i;j<=10000000;j+=i) + { + if(!p[j]) + { + p[j]=i; + } + } + res[i]=res[i-1]+i; + } + else + { + res[i]=res[i-1]+p[i]; + } + } +} + +int main() +{ + spf(); + int t; + scanf("%d",&t); + while(t--) + { + long long int n; + scanf("%lld",&n); + printf("%lld\n", res[n]); + } + +} \ No newline at end of file diff --git a/spoj/ASSIST b/spoj/ASSIST new file mode 100755 index 0000000..c2a9884 Binary files /dev/null and b/spoj/ASSIST differ diff --git a/spoj/ASSIST.cpp b/spoj/ASSIST.cpp new file mode 100644 index 0000000..0f68c37 --- /dev/null +++ b/spoj/ASSIST.cpp @@ -0,0 +1,48 @@ +#include +using namespace std; +int ans[3005]; +list v; + + +void pre() +{ + for(int i=2;i<=34000;i++) + { + v.push_back(i); + } + + int count=0; + list::iterator it,it2; + while(count<=3000) + { + int k=v.front(); + + ans[count]=k; + count++; + //cout< +#include + +using namespace std; + +int main(){ + list L; + for(int i = 2;i<=33850;++i) L.push_back(i); + + int sz = 0, ans[3000]; + list :: iterator it,it2; + + while(!L.empty() && sz<3000){ + ans[sz] = L.front(); + ++sz; + + int k = L.front(),i = 0; + + for(it = L.begin();it!=L.end();it = it2,++i){ + it2 = it; ++it2; + if(i%k==0) L.erase(it); + } + } + + int n; + + while(true){ + scanf("%d",&n); + if(n==0) break; + printf("%d\n",ans[n-1]); + } + + return 0; +} \ No newline at end of file diff --git a/spoj/ATM b/spoj/ATM new file mode 100755 index 0000000..b18ad07 Binary files /dev/null and b/spoj/ATM differ diff --git a/spoj/ATM.cpp b/spoj/ATM.cpp new file mode 100644 index 0000000..285c7fc --- /dev/null +++ b/spoj/ATM.cpp @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + int x; + double y; + scanf("%d %lf", &x, &y); + + if(x%5==0 && (x+0.5)<=y){ + + printf("%.2lf\n", y-(x+0.5)); + } + else + { + printf("%.2lf\n", y); + } + return 0; +} \ No newline at end of file diff --git a/spoj/Aman_and_Painting b/spoj/Aman_and_Painting new file mode 100755 index 0000000..1bf9ed2 Binary files /dev/null and b/spoj/Aman_and_Painting differ diff --git a/spoj/Aman_and_Painting.cpp b/spoj/Aman_and_Painting.cpp new file mode 100644 index 0000000..421d2fb --- /dev/null +++ b/spoj/Aman_and_Painting.cpp @@ -0,0 +1,113 @@ +#include +using namespace std; +#define SIZE 100005 +#define ll long long +#define INF 1000000000 + +vector > adj[SIZE]; +int n,m,src,dest,tim; +ll dist[SIZE]; + +void addedge(int x,int y, int d) +{ + adj[x].push_back(make_pair(y,d)); + adj[y].push_back(make_pair(x,d)); +} + +ll djisktras() +{ + for(int i=0;i<=n;i++) + { + dist[i]=INF; + } + dist[src]=0; + priority_queue > q; + q.push(make_pair(src,0)); + + while(!q.empty()) + { + pair p=q.top(); + q.pop(); + + int x=p.first; + + for(int i=0;idist[x]+w) + { + dist[e]=dist[x]+w; + q.push(make_pair(e,dist[e])); + } + } + } + if(dist[dest]==INF) + { + return -1; //if one cannot reach the destination from the source + } + else + { + return dist[dest]; + } +} + +int main() +{ + ofstream of; + of.open("AMANPNT output file #2"); + + int t; + scanf("%d",&t); + + while(t--) + { + scanf("%d%d%d%d%d",&n,&m,&src,&dest,&tim); + + + + for(int i=0;i<=n;i++) + { + adj[i].clear(); + } + + for(int i=1;i<=m;i++) + { + int u,v; + scanf("%d %d", &u,&v); + addedge(u,v,1); + } + + if(src==dest) + { + if(tim>=2) //if source and destination is at the same location it will only take 2 time units to complete the painting + { + // printf("YES\n"); + of<<"YES\n"; + } + continue; + } + + ll shortest_time = djisktras(); + + + + if(shortest_time == -1) + { + // printf("NOT POSSIBLE\n"); + of<<"NOT POSSIBLE\n"; + } + else if(2*shortest_time+2<=tim) + { + // printf("YES\n"); + of<<"YES\n"; + + } + else + { + // printf("NO\n"); + of<<"NO\n"; + } + } +} \ No newline at end of file diff --git a/spoj/BRCKTS b/spoj/BRCKTS new file mode 100755 index 0000000..367e2a6 Binary files /dev/null and b/spoj/BRCKTS differ diff --git a/spoj/BRCKTS.cpp b/spoj/BRCKTS.cpp new file mode 100644 index 0000000..a46d130 --- /dev/null +++ b/spoj/BRCKTS.cpp @@ -0,0 +1,141 @@ +#include +using namespace std; +#define SIZE 30005 +struct trees +{ + int k,s; +}; + +trees tree[SIZE<<3]; + +string s; + +trees merge(trees a,trees b) +{ + trees res; + int n=min(a.k,b.s); + res.k=a.k+b.k-n; + res.s=a.s+b.s-n; + + return res; +} + +void build(int node, int start, int end) +{ + if(start==end) + { + if(s[start-1]=='(') + { + tree[node].k=1; + tree[node].s=0; + } + else + { + tree[node].s=1; + tree[node].k=0; + } + return; + } + int mid=(start+end)>>1; + int p1=node<<1; + int p2=node<<1|1; + + build(p1,start,mid); + build(p2,mid+1,end); + + tree[node]=merge(tree[p1],tree[p2]); +} + +void update(int node,int start, int end, int x) +{ + if(start==end) + { + if(s[x-1]=='(') + { + s[x-1]=')'; + tree[node].k=0; + tree[node].s=1; + } + else if(s[x-1]==')') + { + s[x-1]='('; + tree[node].k=1; + tree[node].s=0; + } + } + else + { + int mid=(start+end)>>1; + int p1=node<<1; + int p2=node<<1|1; + + if(start<=x && x<=mid) + { + update(p1,start,mid,x); + } + else + { + update(p2,mid+1,end,x); + } + tree[node]=merge(tree[p1],tree[p2]); + } +} + +trees query(int node,int start,int end,int l,int r) +{ + if(start==l && end==r) + { + return tree[node]; + } + int mid=(start+end)>>1; + + int p1=node<<1; + int p2=node<<1|1; + + if(r<=mid) + { + return query(p1,start,mid,l,r); + } + else if(l>mid) + { + return query(p2,mid+1,end,l,r); + } + else return (merge(query(p1,start,mid,l,mid),query(p2,mid+1,end,mid+1,r))); +} + +int main() +{ + int u=10; + while(u--) + { + printf("Test %d:\n",10-u); + int n; + scanf("%d",&n); + + cin>>s; + + build(1,1,n); + + int m; + scanf("%d",&m); + while(m--) + { + int k; + scanf("%d",&k); + + if(k) + { + update(1,1,n,k); + } + else + { + trees p=query(1,1,n,1,n); + if(p.k==0 && p.s==0) + printf("YES\n"); + else + printf("NO\n"); + } + } + } + return 0; +} \ No newline at end of file diff --git a/spoj/BRCKTStest b/spoj/BRCKTStest new file mode 100755 index 0000000..47d78c6 Binary files /dev/null and b/spoj/BRCKTStest differ diff --git a/spoj/BRCKTStest.cpp b/spoj/BRCKTStest.cpp new file mode 100644 index 0000000..fb744a8 --- /dev/null +++ b/spoj/BRCKTStest.cpp @@ -0,0 +1,126 @@ +#include +#include +using namespace std; + +struct SegmentTreeNode { + int unmatchedOpenParans, unmatchedClosedParans; + + void assignLeaf(char paranthesis) { + if (paranthesis == '(') + unmatchedOpenParans = 1, unmatchedClosedParans = 0; + else + unmatchedOpenParans = 0, unmatchedClosedParans = 1; + } + + void merge(SegmentTreeNode& left, SegmentTreeNode& right) { + int newMatches = min(left.unmatchedOpenParans, right.unmatchedClosedParans); + unmatchedOpenParans = right.unmatchedOpenParans + left.unmatchedOpenParans - newMatches; + unmatchedClosedParans = left.unmatchedClosedParans + right.unmatchedClosedParans - newMatches; + } + + bool getValue() { + return unmatchedOpenParans == 0 && unmatchedClosedParans == 0; + } +}; + +template +class SegmentTree { + SegmentTreeNode* nodes; + int N; + +public: + SegmentTree(T arr[], int N) { + this->N = N; + nodes = new SegmentTreeNode[getSegmentTreeSize(N)]; + buildTree(arr, 1, 0, N-1); + } + + ~SegmentTree() { + delete[] nodes; + } + + V getValue(int lo, int hi) { + SegmentTreeNode result = getValue(1, 0, N-1, lo, hi); + return result.getValue(); + } + + void update(int index, T value) { + update(1, 0, N-1, index, value); + } + +private: + void buildTree(T arr[], int stIndex, int lo, int hi) { + if (lo == hi) { + nodes[stIndex].assignLeaf(arr[lo]); + return; + } + + int left = 2 * stIndex, right = left + 1, mid = (lo + hi) / 2; + buildTree(arr, left, lo, mid); + buildTree(arr, right, mid + 1, hi); + nodes[stIndex].merge(nodes[left], nodes[right]); + } + + SegmentTreeNode getValue(int stIndex, int left, int right, int lo, int hi) { + if (left == lo && right == hi) + return nodes[stIndex]; + + int mid = (left + right) / 2; + if (lo > mid) + return getValue(2*stIndex+1, mid+1, right, lo, hi); + if (hi <= mid) + return getValue(2*stIndex, left, mid, lo, hi); + + SegmentTreeNode leftResult = getValue(2*stIndex, left, mid, lo, mid); + SegmentTreeNode rightResult = getValue(2*stIndex+1, mid+1, right, mid+1, hi); + SegmentTreeNode result; + result.merge(leftResult, rightResult); + return result; + } + + int getSegmentTreeSize(int N) { + int size = 1; + for (; size < N; size <<= 1); + return size << 1; + } + + void update(int stIndex, int lo, int hi, int index, T value) { + if (lo == hi) { + nodes[stIndex].assignLeaf(value); + return; + } + + int left = 2 * stIndex, right = left + 1, mid = (lo + hi) / 2; + if (index <= mid) + update(left, lo, mid, index, value); + else + update(right, mid+1, hi, index, value); + + nodes[stIndex].merge(nodes[left], nodes[right]); + } +}; + +int main() { + int N, M, k; + char word[30005]; + + for (int t = 1; t <= 10; ++t) { + scanf("%d", &N); + scanf("%s", word); + SegmentTree st(word, N); + + printf("Test %d:\n", t); + scanf("%d", &M); + while(M--) { + scanf("%d", &k); + if (k != 0) { + --k; + word[k] = (word[k] == '(') ? ')' : '('; + st.update(k, word[k]); + } else + printf("%s\n", st.getValue(0, N-1) ? "YES" : "NO"); + } + } + + return 0; +} \ No newline at end of file diff --git a/spoj/BUGLIFE b/spoj/BUGLIFE new file mode 100755 index 0000000..5aa6bde Binary files /dev/null and b/spoj/BUGLIFE differ diff --git a/spoj/BUGLIFE.cpp b/spoj/BUGLIFE.cpp new file mode 100644 index 0000000..3756f2c --- /dev/null +++ b/spoj/BUGLIFE.cpp @@ -0,0 +1,104 @@ +#include +using namespace std; +#define SIZE 1000002 +vector adj[2002]; +queue q; +long long coloured[2002]; + + +void addedge(long long x,long long y) +{ + adj[x].push_back(y); + adj[y].push_back(x); +} + +int bfs(long long src) +{ + coloured[src]=1; + + while(!q.empty()) + { + q.pop(); + } + + q.push(src); + + while(!q.empty()) + { + long long u=q.front(); + q.pop(); + + for(int i=0;i>t; + while(t--) + { + long long n,c; + int flag=0; + scanf("%lld %lld",&n,&c); + int res; + memset(coloured,-1,sizeof(coloured)); + + for(long long i=1;i<=n;i++) + { + adj[i].clear(); + } + + for(long long i=0;i +using namespace std; +int G[2019][2019]={0,0}; +int chec(int a); +int n; +int colorArr[2019]; +int main() +{ + int t,m,x,y,i; + scanf("%d",&t); + for(int test = 1 ; test <= t ; test++) + { + memset(G,0,sizeof(G)); + int flag=0; + scanf("%d%d",&n,&m); + for(i=0;i q; + q.push(start); + while (!q.empty()) + { + + int i = q.front(); + q.pop(); + + + for (int j = 1; j <= n; j++) + { + if (G[i][j] && colorArr[j] == -1) + { + + colorArr[j] = 1 - colorArr[i]; + q.push(j); + } + else if (G[i][j] && colorArr[j] == colorArr[i]) + return 0; + } + } + return 1; +} \ No newline at end of file diff --git a/spoj/CCOST b/spoj/CCOST new file mode 100755 index 0000000..1b71018 Binary files /dev/null and b/spoj/CCOST differ diff --git a/spoj/CCOST.cpp b/spoj/CCOST.cpp new file mode 100644 index 0000000..c2cae87 --- /dev/null +++ b/spoj/CCOST.cpp @@ -0,0 +1,131 @@ +#include +using namespace std; +#define ll long long +#define MAXR 500005 +#define MAXV 10000005 + +int BIT[MAXV]; +int ans[4*MAXR]; +int r,mr,n; + +typedef struct tree +{ + int x,y; + int val; +}tree; + +typedef struct qu +{ + int x,y,pos; +}quer; + +bool compt(const tree &a,const tree &b) +{ + return a.y0;x-=x&-x) + sum+=BIT[x]; + return sum; +} + +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + scanf("%d",&n); + tree t[n+5]; + memset(BIT,0,sizeof(BIT)); + + for(int i=0;i + +using namespace std; + +#define MAXN 100005 +#define MAXR 500005 +#define MAXV 10000005 + +int tree[MAXV], ans[4*MAXR], n, r, mr; + +struct points +{ + int x, y, val; +}; + +struct query +{ + int x, y, pos; +}; + +points p[MAXN]; +query q[MAXR]; + +bool cmpP(const points &a, const points &b) +{ + return a.y0) + { + sum+=tree[idx]; + idx-=idx&-idx; + } + return sum; +} + +int main() +{ + int t, x1, y1, x2, y2, curr, pre, qre; + scanf("%d", &t); + while(t--) + { + memset(tree, 0, sizeof(tree)); + scanf("%d", &n); + for(int i=0;i%d %d %d\n", p[i].x, p[i].y, p[i].val); + }*/ + scanf("%d", &r); + for(int i=0;i%d %d %d\n", q[i].x, q[i].y, q[i].pos); + }*/ + pre=qre=0; + while(pre> %d %d", p[pre].y, q[qre].y); + while(pre0>\n"); + update(p[pre].x, p[pre].val); + pre++; + } + while(qre1>%d %d %d\n", q[qre].y, q[qre+1].y, read(q[qre].x)); + ans[q[qre].pos]=read(q[qre].x); + qre++; + } + //printf(">2> %d\n", read(q[qre].x)); + ans[q[qre].pos]=read(q[qre].x); + qre++; + } + /*for(int i=0;i%d ", ans[i]); + } + printf("\nTree:\n"); + for(int i=0;i%d ", tree[i]); + } + printf("\n");*/ + for(int i=0;i +using namespace std; +#define ll long long +#define SIZE 100005 + +ll sieve[1000005]; +int n,q; +ll a[SIZE]; + +void sievefunc() +{ + sieve[1]=1; + for(int i=2;i<=1000000;i++) + { + if(!sieve[i]) + { + for(int j=i;j<=1000000;j+=i) + { + if(!sieve[j]) + { + sieve[j]=i; + } + } + } + } +} + +struct trees +{ + vector v; +}; + +trees tree[SIZE<<4]; + + +void build(int node,int start,int end) +{ + // printf("here\n"); + if(start>end) return; + if(start==end) + { + ll x=a[start]; + // printf("%lld\n", x); + + int k=sieve[x]; + // printf("%d\n", k); + + tree[node].v.push_back(k); + + while(x!=k) + { + // printf("%d\n", tree[node].v.front()); + x/=k; + k=sieve[x]; + tree[node].v.push_back(k); + } + + /*for(int i=0;i>1; + build(2*node,start,mid); + build(2*node+1,mid+1,end); + tree[node].v.resize(tree[2*node].v.size()+tree[2*node+1].v.size()); + merge(tree[2*node].v.begin(),tree[2*node].v.end(),tree[2*node+1].v.begin(),tree[2*node+1].v.end(),tree[node].v.begin()); +} + +int query(int node, int start, int end, int l, int r, int x, int y) +{ + if(start>end || start>r || end>1; + return query(2*node,start,mid,l,r,x,y)+query(2*node+1,mid+1,end,l,r,x,y); +} + +int main() +{ + sievefunc(); + /*for(int i=1;i<=1000000;i++) + { + printf("%d\n",sieve[i] ); + }*/ + scanf("%d",&n); + for(int i=1;i<=n;i++) + { + scanf("%lld",&a[i]); + } + build(1,1,n); + + /*for(int i=1;i<=2*n-1;i++) + { + for(int j=0;j +using namespace std; +#define SIZE 110 +vector > adj[SIZE]; +bool vis[SIZE]; +double dist[SIZE]; +long long n,m; +// vectorpath; + +void addedge(long long x,long long y,double p) +{ + adj[x].push_back(make_pair(y,p)); + adj[y].push_back(make_pair(x,p)); +} + +double max_dijkstra() +{ + memset(dist,0,sizeof(dist)); + // memset(vis,false,sizeof(vis)); + //path.empty(); + dist[1]=1; + //priority_queue >q; + queueq; + q.push(1); + + while(!q.empty()) + { + int x=q.front(); + q.pop(); + // int wei=p.second; + + // if(vis[x]) continue; + + // vis[x]=true; + // path.push_back(x); + // if(x==n) break; + + for(long long i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define INF 1 + +typedef long long int LLD; +typedef unsigned long long int LLU; + +using namespace std; + +vector< vector< pair > > graph; +vector dis; + +double dijkstra(int s, int d){ + queue q; + fill(dis.begin(), dis.end(), -INF); + dis[s] = 1; + q.push(s); + while(!q.empty()){ + int node = q.front(); + q.pop(); +// cout << "working on " << node << endl; + for(int i=0;i tmpPair; + while(true){ + scanf("%d", &n); + if(n == 0) + break; + scanf("%d", &m); + graph.clear(); + graph.resize(n); + dis.clear(); + dis.resize(n); + for(int i=0;i +using namespace std; + + +#define MAXR 101 +#define MAXC 101 +#define MAXDIRTY 101 +#define MAXMASK 2048 +#define INF INT_MAX + + + +int dist[MAXR][MAXC][MAXDIRTY]; +int dp[MAXDIRTY][MAXMASK]; + +vector > dirty; +int len,limit,r,c; + +char arr[21][21]; + +int X[]={-1,0,0,1}; +int Y[]={0,1,-1,0}; + + +bool safe(int x, int y) +{ + if (x >= r or y>= c or x<0 or y<0) + return false; + if (arr[x][y] == 'x') + return false; + return true; +} + + +void bfs(int idx) +{ + bool vis[21][21]; + memset(vis,false,sizeof(vis)); + + int cx=dirty[idx].first; + int cy=dirty[idx].second; + + queue >pq; + pq.push({cx,cy}); + + for(int i=0;i>w>>h; + r=h; + c=w; + if(w==0 && h==0) + break; + else + { + memset(dp, -1, sizeof(dp)); + dirty.clear(); + int x,y; + for(int i=0;i>arr[i][j]; + if(arr[i][j]=='o') + { + x=i; + y=j; + } + if(arr[i][j]=='*') + dirty.push_back({i,j}); + } + } + + dirty.insert(dirty.begin(),{x,y}); + + len=dirty.size(); + + limit=(1<= INF) + cout << "-1" << endl; + else + cout << ans << endl; + } + + } + return 0; +} \ No newline at end of file diff --git a/spoj/CLEANRBT1 b/spoj/CLEANRBT1 new file mode 100755 index 0000000..54ad941 Binary files /dev/null and b/spoj/CLEANRBT1 differ diff --git a/spoj/CLEANRBT1.cpp b/spoj/CLEANRBT1.cpp new file mode 100644 index 0000000..fd51f09 --- /dev/null +++ b/spoj/CLEANRBT1.cpp @@ -0,0 +1,186 @@ +#include +using namespace std; + +#define INF 99999999 +#define MAXR 101 +#define MAXC 101 +#define MAXMASK 2048 +#define MAXHOUSE 101 + +// stores distance taking souce +// as every dirty tile +int dist[MAXR][MAXC][MAXHOUSE]; + +// memoization for dp states +int dp[MAXHOUSE][MAXMASK]; + +// stores coordinates for +// dirty tiles +vector < pair < int, int > > dirty; + +// Directions +int X[] = {-1, 0, 0, 1}; +int Y[] = {0, 1, -1, 0}; + +char arr[21][21]; + +// len : number of dirty tiles + 1 +// limit : 2 ^ len -1 +// r, c : number of rows and columns +int len, limit, r, c; + + +// Returns true if current position +// is safe to visit +// else returns false +// Time Complexity : O(1) +bool safe(int x, int y) +{ + if (x >= r or y>= c or x<0 or y<0) + return false; + if (arr[x][y] == 'x') + return false; + return true; +} + + +// runs BFS traversal at tile idx +// calulates distance to every cell +// in the grid +// Time Complexity : O(r*c) +void getDist(int idx){ + + // visited array to track visited cells + bool vis[21][21]; + memset(vis, false, sizeof(vis)); + + // getting current positon + int cx = dirty[idx].first; + int cy = dirty[idx].second; + + // initializing queue for bfs + queue < pair < int, int > > pq; + pq.push({cx, cy}); + + // initializing the dist to max + // because some cells cannot be visited + // by taking source cell as idx + for (int i = 0;i<= r;i++) + for (int j = 0;j<= c;j++) + dist[i][j][idx] = INF; + + // base conditions + vis[cx][cy] = true; + dist[cx][cy][idx] = 0; + + while (! pq.empty()) + { + auto x = pq.front(); + pq.pop(); + for (int i = 0;i<4;i++) + { + cx = x.first + X[i]; + cy = x.second + Y[i]; + if (safe(cx, cy)) + { + if (vis[cx][cy]) + continue; + vis[cx][cy] = true; + dist[cx][cy][idx] = dist[x.first][x.second][idx] + 1; + pq.push({cx, cy}); + } + } + } +} + +// Dynamic Programming state transition recursion +// with memoization. Time Complexity: O(n*n*2 ^ n) +int solve(int idx, int mask) +{ + // goal state + if (mask == limit) + return 0; + + // if already visited state + if (dp[idx][mask] != -1) + return dp[idx][mask]; + + int ret = INT_MAX; + + // state transiton relation + for (int i = 0;i>w>>h; + r=h; + c=w; + if(h==0&&w==0) + break; + else + { + memset(dp, -1, sizeof(dp)); + dirty.clear(); + int x,y; + + for(int i = 0;i>arr[i][j]; + if(arr[i][j]=='o') + { + x=i; + y=j; + } + if (arr[i][j] == '*') + dirty.push_back({i, j}); + } + //cout << endl; + } + + // - initializitiation + // - precalculations + // init(); + + // populating dirty tile positions + + // inserting ronot's location at the + // begining of the dirty tile + dirty.insert(dirty.begin(), {x, y}); + + len = dirty.size(); + + // calculating LIMIT_MASK + limit = (1<= INF) + cout << "-1" << endl; + else + cout << ans << endl; + } + } + return 0; +} \ No newline at end of file diff --git a/spoj/CODFURY b/spoj/CODFURY new file mode 100755 index 0000000..d48199a Binary files /dev/null and b/spoj/CODFURY differ diff --git a/spoj/CODFURY.cpp b/spoj/CODFURY.cpp new file mode 100644 index 0000000..7b4e42d --- /dev/null +++ b/spoj/CODFURY.cpp @@ -0,0 +1,50 @@ +#include +using namespace std; +#define SIZE 50005 + +int a[SIZE]; + +int main() +{ + int t; + scanf("%d", &t); + + while(t--) + { + int p,m; + scanf("%d %d", &p, &m); + + for(int i=0;im) + { + sum-=a[i]; + length--; + i++; + } + if(maxlengthsum) + { + minsum=sum; + } + } + } + + printf("%d %d\n",minsum, maxlength); + } +} \ No newline at end of file diff --git a/spoj/COINS b/spoj/COINS new file mode 100755 index 0000000..c2fa19a Binary files /dev/null and b/spoj/COINS differ diff --git a/spoj/COINS.cpp b/spoj/COINS.cpp new file mode 100644 index 0000000..5a21eff --- /dev/null +++ b/spoj/COINS.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; +#define ll long long + +ll n; +mapv; + +ll maxdollars(ll n) +{ + if(n<12) return n; + if(v[n]) return v[n]; + return v[n]=max(v[n],maxdollars(n/2)+maxdollars(n/3)+maxdollars(n/4)); +} + +int main() +{ + while(scanf("%lld", &n)!=EOF) + { + printf("%lld\n",maxdollars(n)); + } +} \ No newline at end of file diff --git a/spoj/CPAIR b/spoj/CPAIR new file mode 100755 index 0000000..8fa0aea Binary files /dev/null and b/spoj/CPAIR differ diff --git a/spoj/CPAIR.cpp b/spoj/CPAIR.cpp new file mode 100644 index 0000000..9567514 --- /dev/null +++ b/spoj/CPAIR.cpp @@ -0,0 +1,171 @@ +//still TLE + +#include +using namespace std; +#define SIZE 100005 +int n,qu; + +struct num +{ + int val,index; +}a[SIZE]; + +bool cmp(num a,num b) +{ + return a.val>b.val; +} + +struct cpair +{ + int v,a,b,pos; +}q[SIZE]; + +bool cmp1(cpair a,cpair b) +{ + if(a.v==b.v) + { + a.b>b.b; + } + return a.v>b.v; +} + +struct trees +{ + int sum,size,flag; +}; + +trees tree[SIZE<<3]; + +trees merge(trees a, trees b) +{ + trees res; + res.sum=a.sum+b.sum; + res.size=a.size+b.size; + if(a.flag>0 &&b.flag>0) + res.flag=1; + else + res.flag=0; + // res.flag=a.flag & b.flag; + return res; +} + +void build(int node, int start, int end) +{ + if(start==end) + { + tree[node].sum=0; + tree[node].size=1; + tree[node].flag=0; + return; + } + int mid=start+end>>1; + build(2*node,start,mid); + build(2*node+1,mid+1,end); + tree[node]=merge(tree[2*node],tree[2*node+1]); +} + +void update(int node,int start,int end,int x) +{ + if(start==x && end==x) + { + tree[node].sum=1; + tree[node].flag=1; + return; + } + if(start>end || start>x || end>1; + update(2*node,start,mid,x); + update(2*node+1,mid+1,end,x); + tree[node]=merge(tree[2*node],tree[2*node+1]); +} + +int query(int node,int a,int b) +{ + int s=0; + if(tree[node].flag==1) + { + /*for(int i=a;i<=b;i++) + { + if(tree[node].sum-(i-1)>0) + { + s+=tree[node].sum-(i-1); + } + }*/ + + if(tree[node].size1) + { + return query(2*node,a,b)+query(2*node+1,a,b); + } + else + { + return 0; + } +} + +int main() +{ + scanf("%d %d",&n,&qu); + + int result[qu+5]; + + for(int i=1;i<=n;i++) + { + scanf("%d",&a[i].val); + a[i].index=i; + } + + sort(a+1, a+1+n, cmp); + + for(int i=1;i<=qu;i++) + { + scanf("%d%d%d",&q[i].v,&q[i].a,&q[i].b); + q[i].pos=i; + } + + sort(q+1, q+1+qu, cmp1); + + build(1,1,n); + + int j=1; + for(int i=1;i<=qu;i++) + { + while(j<=n && a[j].val>=q[i].v) //using the concept of kquery + { + + update(1,1,n,a[j].index); + j++; + } + + /*printf("%d\n", query(1,q[i].a,q[i].b));*/ + result[q[i].pos]=query(1,q[i].a,q[i].b); + /*printf("\n"); + for (int k = 1; k <= 2*n-1 ; k++) + { + printf("%d %d %d\n", tree[k].sum, tree[k].size, tree[k].flag); + } + printf("\n");*/ + } + + for(int i=1;i<=qu;i++) + { + printf("%d\n", result[i]); + } + return 0; +} \ No newline at end of file diff --git a/spoj/CTRICK b/spoj/CTRICK new file mode 100755 index 0000000..e3b2d20 Binary files /dev/null and b/spoj/CTRICK differ diff --git a/spoj/CTRICK#2 b/spoj/CTRICK#2 new file mode 100755 index 0000000..0051111 Binary files /dev/null and b/spoj/CTRICK#2 differ diff --git a/spoj/CTRICK#2.cpp b/spoj/CTRICK#2.cpp new file mode 100644 index 0000000..91eadca --- /dev/null +++ b/spoj/CTRICK#2.cpp @@ -0,0 +1,70 @@ +#include +using namespace std; +#define ll long long + +int BIT[20005]; +int n; + +void update(int x,int val) +{ + for(;x<=n;x+=x&-x) + { + BIT[x]+=val; + } +} + +int query(int x) +{ + int sum=0; + for(;x>0;x-=x&-x) + { + sum+=BIT[x]; + // cout<0 ; i--) + { + /* code */ + rot=rot%i+1; + start=1;end=n; + while(start<=end) //search for the rot-th zero required + { + int mid=(start+end)>>1; + if(query(mid)>=rot) + end=mid-1; + else start=mid+1; + } + a[start]=n-i+1; + rot+=n-i+1; + update(start,-1); + } + + + for(int i=1;i<=n;i++) + { + printf("%d ",a[i]); + } + cout< +using namespace std; +#define ll long long + +int BIT[20005]; +int n; + +void update(int x,int val) +{ + for(;x<=n;x+=x&-x) + { + BIT[x]+=val; + } +} + +int query(int x) +{ + int sum=0; + for(;x>0;x-=x&-x) + { + sum+=BIT[x]; + // cout<=rot) end=mid-1; + else start=mid+1; + } + + a[start]=i; + update(start,-1); + } + + for(int i=1;i<=n;i++) + { + printf("%d ",a[i]); + } + cout< +#include +using namespace std; +using namespace tr1; +int sieve[100005]; +int n,q; +int a[100005]; + +void sievefunc() +{ + sieve[0]=0; + sieve[1]=1; + for(int i=2;i<=100000;i++) + { + if(!sieve[i]) + { + for(int j=i;j<=100000;j+=i) + { + if(!sieve[j]) + { + sieve[j]=i; + } + } + } + } +} + +vector > primefactors(int a) +{ + vector > v; + unordered_map h; + int k=sieve[a]; + // printf("%d\n", k); + while(k!=1) + { + h[k]++; + // printf("%d\n", h[k]); + a=a/k; + k=sieve[a]; + } + + unordered_map::iterator it; + // v.push_back(0); + for(it=h.begin();it!=h.end();it++) + { + v.push_back(make_pair(it->first,it->second)); + } + + return v; +} + +struct trees +{ + vector > v; + vector prefix; +}; + +trees tree[100005<<3]; + +trees merge(trees a, trees b) +{ + trees res; + /*vector >::iterator it1; + vector >::iterator it2;*/ + + unordered_map m; + + for(int i=0;i::iterator it; + // v.push_back(0); + for(it=m.begin();it!=m.end();it++) + { + res.v.push_back(make_pair(it->first,it->second)); + } + + /*for(int i=0;i a, pair b) +{ + return a.firstend) return; + if(start==end) + { + tree[node].v=primefactors(a[start]); + + // printf("%d\n",node ); + + /*for(int i=0;i>1; + build(2*node,start,mid); + build(2*node+1,mid+1,end); + tree[node]=merge(tree[2*node],tree[2*node+1]); +} + +int query(int node,int start,int end, int l,int r, int x, int y) +{ + if(start>r||endend) + return 0; + if(l<=start && end<=r) + { + + /*// printf("%d %d\n",left,right); + vector >::iterator left; + vector >::iterator right;*/ + + int left,right; + int s=start,e=end; + + while(s>1; + if(x<=tree[node].v[mid].first) + e=mid; + else + s=mid+1; + } + + left=s; + + s=start; + e=end; + + while(s>1; + if(x>=tree[node].v[mid].first) + s=mid+1; + else + e=mid; + } + + right=l; + + printf("%d %d\n",left, right ); + /*left=lower_bound(tree[node].v.begin(), tree[node].v.end(), x, cmp)-tree[node].v.begin(); + right=upper_bound(tree[node].v.begin(), tree[node].v.end(), y, cmp)-tree[node].v.begin();*/ + return tree[node].prefix[right]-tree[node].prefix[left-1]; + } + int mid=start+end>>1; + return query(2*node,start,mid,l,r,x,y)+query(2*node+1,mid+1,end,l,r,x,y); +} + +int main() +{ + sievefunc(); + + scanf("%d",&n); + for(int i=1;i<=n;i++) + { + scanf("%d",&a[i]); + } + + build(1,1,n); + /*for(int i=2;i<=10;i++) + { + printf("%d\n",sieve[i]); + }*/ + + /*vector >v; + v=primefactors(10); + for(int i=0;i +using namespace std; + +int main() +{ + int t; + cin>>t; + while(t--) + { + int n,m,b; + cin>>n>>m>>b; + int a[n][n]; + + for(int i=0;i>x>>y>>k; + a[x-1][y-1]=k; + a[y-1][x-1]=k; + } + + /*for(int i=0;ia[i][k]+a[k][j]) + { + a[i][j]=a[i][k]+a[k][j]; + a[j][i]=a[i][k]+a[k][j]; + } + } + } + } + + /*for(int i=0;i>z; + + int bit[z]; + int p[z][z]; + for(int i=0;i>p[i][j]; + } + } + + int parcels=0; + for(int i=0;i + +using namespace std; + +// Input macros + +#define si(n) scanf("%d",&n) +#define sc(n) scanf("%c",&n) +#define sl(n) scanf("%lld",&n) +#define sf(n) scanf("%lf",&n) +#define ss(n) scanf("%s",n) + +// Useful constants + +#define INF (int)1e9 +#define EPS 1e-9 +#define MOD1 1000000009 +#define MOD2 1000000007 + +// Useful hardware instructions + +#define bitcount __builtin_popcount +#define gcd __gcd + +// Useful container manipulation / traversal macros + +#define forI(i,n) for(i=0 ; i< n ;i++) +#define forD(i,n) for(i=n-1; i>=0 ;i--) +#define forall(i,a,b) for(i=a ; i<=b ;i++) +#define foreach(v, c) for( typeof( (c).begin()) v = (c).begin(); v != (c).end(); ++v) +#define all(a) a.begin(), a.end() +#define in(a,b) ( (b).find(a) != (b).end()) +#define pb push_back +#define fill(a,v) memset(a, v, sizeof a) +#define sz(a) ((int)(a.size())) +#define mp make_pair + +// Some common useful functions + +#define MAX(a,b) ( (a) > (b) ? (a) : (b)) +#define MIN(a,b) ( (a) < (b) ? (a) : (b)) +#define checkbit(n,b) ( (n >> b) & 1) +#define DREP(a) sort(all(a)); a.erase(unique(all(a)),a.end()) +#define INDEX(arr,ind) (lower_bound(all(arr),ind)-arr.begin()) + +// datatypes + +#define ll long long int +#define ull unsigned long long +#define ui unsigned int +#define us unsigned short +#define vi vector +#define pii pair +#define gc getchar_unlocked +#define pc putchar_unlocked + +// Faster Input/Output + +inline void get_int(int &x) +{ + register int c = gc(); + x = 0; + int neg = 0; + for(;((c<48 || c>57) && c != '-');c = gc()); + if(c=='-') {neg=1;c=gc();} + for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;} + if(neg) x=-x; +} + +inline void get_long(ll &x) +{ + register int c = gc(); + x = 0; + int neg = 0; + for(;((c<48 || c>57) && c != '-');c = gc()); + if(c=='-') {neg=1;c=gc();} + for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;} + if(neg) x=-x; +} +inline void print_int(int X) +{ + if(X<0) { pc('-'); X=-X; } + int Len=0,Data[20]; + while(X) { Data[Len++]=X%10; X/=10; } + if(!Len) Data[Len++]=0; + while(Len--) pc(Data[Len]+48); + pc('\n'); +} +inline void print_long(long long int X) +{ + if(X<0) { pc('-'); X=-X; } + int Len=0,Data[20]; + while(X) { Data[Len++]=X%10; X/=10; } + if(!Len) Data[Len++]=0; + while(Len--) pc(Data[Len]+48); + pc('\n'); +} + +// Main Function +#define MAXN 505 +ll BIT1[MAXN][MAXN],BIT2[MAXN][MAXN]; +ll N,M; +void init() +{ + ll i,j; + forI(i,MAXN) + { + forI(j,MAXN) + { + BIT1[i][j]=BIT2[i][j]=0; + } + } +} +void update(ll BIT[][505],ll x,ll y,ll val) +{ + while(y <= M) + { + BIT[x][y]+=val; + y += (y & -y); + } +} +/*void update_pt(ll x,ll y,ll v) +{ + update(BIT1,x,y,v); + update(BIT2,x,y,v*(y-1)); +}*/ +void update_range(ll x,ll y1,ll y2,ll v) +{ + update(BIT1,x,y1,v); + update(BIT1,x,y2+1,-v); + update(BIT2,x,y1,v*(y1-1)); + update(BIT2,x,y2+1,-v*y2); +} +void update_range2D(ll x1,ll y1,ll x2,ll y2,ll v) +{ + ll i; + forall(i,x1,x2) + { + update_range(i,y1,y2,v); + } +} +ll read(ll BIT[][505],ll x,ll y) +{ + ll sum = 0; + while(y>0) + { + sum+=BIT[x][y]; + y-=(y & -y); + } + return sum; +} +ll query(ll x,ll y) +{ + return read(BIT1,x,y)*y-read(BIT2,x,y); +} +ll query_range(ll x,ll y1,ll y2) +{ + return query(x,y2)-query(x,y1-1); +} +ll query_range2D(ll x1,ll y1,ll x2,ll y2) +{ + ll i,sum=0; + forall(i,x1,x2) + { + sum+=query_range(i,y1,y2); + } + return sum; +} +int main() +{ + ll i,j,q,num; + init(); + get_long(N);get_long(M); + forI(i,N) + { + forI(j,M) + { + get_long(num); + update_range2D(i+1,j+1,i+1,j+1,num); + } + } + get_long(q); + ll ch,x1,y1,x2,y2,v; + + /*for(int i=0;i +using namespace std; +#define SIZE 30005 +#define ll long long + +int a[SIZE]; + +int n,d,sq; + +struct query{ + int l; + int r; + int id; +}; + +query q[200005]; + +int counter[2000005]; +int ans[2000005]; +int x=0; + +bool cmp(const query a,const query b) +{ + if(a.l/sq != b.l/sq) + return a.l/sq33){ + *a=*a*10+c-'0'; + c=getchar_unlocked(); + } +} + +/*void add(int position) { + counter[a[position]]++; + if(counter[a[position]] == 1) { + x++; + } +} + +void remove(int position) { + counter[a[position]]--; + if(counter[a[position]] == 0) { + x--; + } +}*/ + +int main() +{ + fastread(&n); + sq=sqrt(n); + for(int i=1;i<=n;i++) + { + fastread(a+i); + } + + fastread(&d); + for(int i=1;i<=d;i++) + { + fastread(&(q[i].l)); + fastread(&(q[i].r)); + q[i].id=i; + } + + sort(q+1,q+d+1,cmp); + + int start=q[1].l; + int end=start; + counter[a[start]]++; + int x=1; + + + /*int start=0; + int end = 0;*/ + for(int i=1;i<=d;i++) + { + /*int l = q[i].l, r = q[i].r; + while(start < l) { + remove(start); + start++; + } + while(start > l) { + add(start-1); + start--; + } + while(end <= r) { + add(end); + end++; + } + while(end > r+1) { + remove(end-1); + end--; + }*/ + + while(startq[i].l) + { + start--; + counter[a[start]]++; + if(counter[a[start]]==1) + x++; + } + while(endq[i].r) + { + counter[a[end]]--; + if(counter[a[end]]==0) + x--; + end--; + } + + + ans[q[i].id]=x; + } + + for(int i=1;i<=d;i++) + { + printf("%d\n", ans[i]); + } +} \ No newline at end of file diff --git a/spoj/DQUERYtest b/spoj/DQUERYtest new file mode 100755 index 0000000..2744427 Binary files /dev/null and b/spoj/DQUERYtest differ diff --git a/spoj/DQUERYtest.cpp b/spoj/DQUERYtest.cpp new file mode 100644 index 0000000..bfeb6bb --- /dev/null +++ b/spoj/DQUERYtest.cpp @@ -0,0 +1,98 @@ +#include +#include +#include + +int sq; + +struct query { + int l, r, id; +} q[200001]; + +int count[2000001]; + +void fastread( int *a){ + char c=0; + while(c<33){ + c=getchar_unlocked(); + } + *a=0; + while(c>33){ + *a=*a*10+c-'0'; + c=getchar_unlocked(); + } +} + +int cmp(const void* a, const void* b) { + struct query* x = (struct query*) a; + struct query* y = (struct query*) b; + if (x->l / sq != y->l / sq) { + if (((x->l)/sq) < ((y->l)/sq)) + return -1; + else if (((x->l)/sq) > ((y->l)/sq)) + return 1; + else + return 0; + } + if ((x->r) < (y->r)) { + return -1; + } + else if ( (x->r) > (y->r) ) { + return 1; + } + else + return 0; +} + + +int main(void) { + int n; + fastread(&n); + sq = sqrt(n); + int a[n]; + int t, i; + for (i = 0; i < 2000001; i++) + count[i] = 0; + for (i = 0; i < n; i++) + fastread(a+i); + fastread(&t); + int ans[t]; + for (i = 0; i < t; i++) { + fastread(&(q[i].l)); + fastread(&(q[i].r)); + q[i].l = q[i].l - 1; + q[i].r = q[i].r - 1; + q[i].id = i; + } + qsort(q, t, sizeof(struct query), cmp); + int cl = 0, cr = 0, x = 0; + for (i = 0; i < t; i++) { + while (cl > q[i].l) { + count[a[cl-1]]++; + if (count[a[cl-1]] == 1) + x++; + cl--; + } + while (cl < q[i].l) { + count[a[cl]]--; + if (count[a[cl]] == 0) + x--; + cl++; + } + while (cr <= q[i].r) { + count[a[cr]]++; + if (count[a[cr]] == 1) + x++; + cr++; + } + while (cr > q[i].r + 1) { + count[a[cr-1]]--; + if (count[a[cr-1]] == 0) + x--; + cr--; + } + ans[q[i].id] = x; + } + for (i = 0; i < t; i++) + printf("%d\n", ans[i]); + return 0; +} \ No newline at end of file diff --git a/spoj/DQUERYtest2 b/spoj/DQUERYtest2 new file mode 100755 index 0000000..3eba6c5 Binary files /dev/null and b/spoj/DQUERYtest2 differ diff --git a/spoj/DQUERYtest2.cpp b/spoj/DQUERYtest2.cpp new file mode 100644 index 0000000..a3eafda --- /dev/null +++ b/spoj/DQUERYtest2.cpp @@ -0,0 +1,77 @@ +#include +using namespace std; + +#define N 311111 +#define A 1111111 +#define BLOCK 555 // ~sqrt(N) + +int cnt[A], a[N], ans[N], answer = 0; + +struct node { + int L, R, i; +}q[N]; + +bool cmp(node x, node y) { + if(x.L/BLOCK != y.L/BLOCK) { + // different blocks, so sort by block. + return x.L/BLOCK < y.L/BLOCK; + } + // same block, so sort by R value + return x.R < y.R; +} + +void add(int position) { + cnt[a[position]]++; + if(cnt[a[position]] == 1) { + answer++; + } +} + +void remove(int position) { + cnt[a[position]]--; + if(cnt[a[position]] == 0) { + answer--; + } +} + +int main() { + int n; + scanf("%d", &n); + for(int i=0; i L) { + add(currentL-1); + currentL--; + } + while(currentR <= R) { + add(currentR); + currentR++; + } + while(currentR > R+1) { + remove(currentR-1); + currentR--; + } + ans[q[i].i] = answer; + } + + for(int i=0; i +using namespace std; + +#define N 311111 +#define A 1111111 +#define BLOCK 555 // ~sqrt(N) + +int cnt[A], a[N], ans[N], answer = 0; + +struct node { + int L, R, i; +}q[N]; + +bool cmp(node x, node y) { + if(x.L/BLOCK != y.L/BLOCK) { + // different blocks, so sort by block. + return x.L/BLOCK < y.L/BLOCK; + } + // same block, so sort by R value + return x.R < y.R; +} + +void add(int position) { + cnt[a[position]]++; + if(cnt[a[position]] == 1) { + answer++; + } +} + +void remove(int position) { + cnt[a[position]]--; + if(cnt[a[position]] == 0) { + answer--; + } +} + +int main() { + int n; + scanf("%d", &n); + for(int i=0; i L) { + add(currentL-1); + currentL--; + } + while(currentR <= R) { + add(currentR); + currentR++; + } + while(currentR > R+1) { + remove(currentR-1); + currentR--; + } + ans[q[i].i] = answer; + } + + for(int i=0; i +using namespace std; +#define SIZE 100002 + +vector > adj[SIZE]; +long long n; +vector v; +queue > q; +bool vis[SIZE]; +long long dist[SIZE]; + +void addedge(long long u,long long v,long long d) +{ + adj[u].push_back(make_pair(v,d)); + adj[v].push_back(make_pair(u,d)); +} + +long long BFS(long long src) +{ + q.push(make_pair(src,0)); + long long max=0; + + while(!q.empty()) + { + pair node=q.front(); + q.pop(); + + int x=node.first; + if(vis[x]) continue; + + vis[x]=true; + + for(int i=0;i>t; + while(t--) + { + long long n; + scanf("%lld",&n); + + for(long long int i=1;i<=n;i++) + { + adj[i].clear(); + } + + for(long long int i=0;i +using namespace std; +#define SIZE 100100 +vector >graph[SIZE]; +long long int dp[SIZE]={0}; +long long int l[SIZE]={0}; +long long int r[SIZE]={0}; + +void rootat(int u, int prev) +{ + for(int i=0;i=0;i--) + { + int v=graph[u][i].first; + long long int w=graph[u][i].second; + if(i==k-1) + r[v]=dp[v]+w; + else + { + int nxt=graph[u][i+1].first; + r[v]=max(r[nxt],dp[v]+w); + } + } + + for(int i=0;i +#define mp make_pair +using namespace std; +typedef long long int lli; +typedef pair pii; + +vector graph[100100]; +lli dp[100100] = {0}; +lli l[100100] = {0}; +lli r[100100] = {0}; + +void rootat(int u, int prev) { + for (int i = 0; i < graph[u].size(); i++) { + int v = graph[u][i].first; + if (v == prev) + graph[u].erase(graph[u].begin() + i); + } + for (int i = 0; i < graph[u].size(); i++) + rootat(graph[u][i].first, u); +} + +void dfs1(int u, int prev) { + lli mx = 0; + for (int i = 0; i < graph[u].size(); i++) { + int v = graph[u][i].first; + lli w = graph[u][i].second; + if (v != prev) { + dfs1(v, u); + mx = max(mx, dp[v] + w); + } + } + dp[u] = mx; +} + +void dfs2(int u, int prev, lli up) { + dp[u] = max(dp[u], up); + int k = graph[u].size(); + for (int i = 0; i < k; i++) { + int v = graph[u][i].first; + lli w = graph[u][i].second; + if (i == 0) + l[v] = dp[v] + w; + else { + int pr = graph[u][i-1].first; + l[v] = max(l[pr], dp[v] + w); + } + } + for (int i = k-1; i >= 0; i--) { + int v = graph[u][i].first; + lli w = graph[u][i].second; + if (i == k-1) + r[v] = dp[v] + w; + else { + int nxt = graph[u][i+1].first; + r[v] = max(r[nxt], dp[v] + w); + } + } + for (int i = 0; i < k; i++) { + int v = graph[u][i].first; + lli w = graph[u][i].second; + lli best = up; + if (i != 0) { + int pr = graph[u][i-1].first; + best = max(best, l[pr]); + } + if (i != k - 1) { + int nxt = graph[u][i+1].first; + best = max(best, r[nxt]); + } + dfs2(v, u, best + w); + } +} + +int main(void) { + int t; + scanf("%d", &t); + while (t--) { + int n; + scanf("%d", &n); + for (int i = 1; i <= n; i++) { + dp[i] = l[i] = r[i] = 0; + graph[i].clear(); + } + for (int i = 1; i < n; i++) { + int u, v, w; + scanf("%d %d %d", &u, &v, &w); + graph[u].push_back(mp(v, w)); + graph[v].push_back(mp(u, w)); + } + + /*for(int i=1;i<=n;i++) + { + for(int j=0;j +using namespace std; +#define ll long long + +string a,b; +ll dp[2005][2005]; + +int main() +{ + int t; + cin>>t; + while(t--) + { + cin>>a>>b; + memset(dp,0,sizeof(dp)); + + for(int i=1;i<=a.length();i++) + { + dp[i][0]=i; + } + + for(int i=1;i<=b.length();i++) + { + dp[0][i]=i; + } + + for(int i=1;i<=a.length();i++) + { + for(int j=1;j<=b.length();j++) + { + if(a[i-1]!=b[j-1]) + dp[i][j]=1+min(dp[i-1][j],min(dp[i][j-1],dp[i-1][j-1])); + else + dp[i][j]=dp[i-1][j-1]; + } + } + + printf("%lld\n",dp[a.length()][b.length()]); + } +} \ No newline at end of file diff --git a/spoj/ELIS.cpp b/spoj/ELIS.cpp new file mode 100644 index 0000000..801c757 --- /dev/null +++ b/spoj/ELIS.cpp @@ -0,0 +1,13 @@ +/*simple DP +Tutorial : https://www.codechef.com/wiki/tutorial-dynamic-programming +*/ + +#include +using namespace std; + +int memo[1005]; + +int main() +{ + +} \ No newline at end of file diff --git a/spoj/ENCMSG b/spoj/ENCMSG new file mode 100755 index 0000000..3ea6b74 Binary files /dev/null and b/spoj/ENCMSG differ diff --git a/spoj/ENCMSG.cpp b/spoj/ENCMSG.cpp new file mode 100644 index 0000000..4607b4b --- /dev/null +++ b/spoj/ENCMSG.cpp @@ -0,0 +1,46 @@ +#include +using namespace std; + +int main() +{ + int t; + scanf("%d",&t); + + while(t--) + { + int n; + scanf("%d",&n); + + string s; + cin>>s; + + if(n%2==0) + { + for(int i=1;i +using namespace std; +#define ll long long +#define SIZE 100005 + +struct trees +{ + ll sum; + int ones; + int zeros; +}; + +int lazy[SIZE<<3]; +trees tree[SIZE<<3]; + +trees merge(trees a, trees b) +{ + trees res; + res.sum=a.sum+b.sum; + res.ones=a.ones+b.ones; + res.zeros=a.zeros+b.zeros; + return res; +} + +void build(int node,int start,int end) +{ + if(start==end) + { + tree[node].sum=0; + tree[node].zeros=1; + tree[node].ones=0; + return; + } + + int mid=start+end>>1; + build(2*node,start,mid); + build(2*node+1,mid+1,end); + tree[node]=merge(tree[2*node],tree[2*node+1]); +} + +void update(int node,int start,int end,int l,int r) +{ + if(lazy[node]%2==1) + { + tree[node].sum+=tree[node].zeros-tree[node].ones; + + int temp=tree[node].zeros; + tree[node].zeros=tree[node].ones; + tree[node].ones=temp; + + if(startend || start>r || end>1; + + update(2*node,start,mid,l,r); + update(2*node+1,mid+1,end,l,r); + + tree[node]=merge(tree[2*node],tree[2*node+1]); +} + +ll query(int node,int start, int end, int l, int r) +{ + if(lazy[node]%2==1) + { + tree[node].sum+=tree[node].zeros-tree[node].ones; + + int temp=tree[node].zeros; + tree[node].zeros=tree[node].ones; + tree[node].ones=temp; + + if(startend || start>r || end>1; + return query(2*node,start,mid,l,r)+query(2*node+1,mid+1,end,l,r); + +} + +int main() +{ + int n,q; + scanf("%d %d",&n,&q); + + memset(tree ,0, sizeof(tree)); + memset(lazy ,0, sizeof(lazy)); + + build(1,1,n); + + while(q--) + { + int c,x,y; + // int val; + scanf("%d",&c); + if(c) + { + scanf("%d %d",&x,&y); + printf("%lld\n", query(1,1,n,x+1,y+1)); + } + else + { + scanf("%d %d",&x,&y); + update(1,1,n,x+1,y+1); + } + } + return 0; + +} \ No newline at end of file diff --git a/spoj/GSS1 b/spoj/GSS1 new file mode 100755 index 0000000..419a51d Binary files /dev/null and b/spoj/GSS1 differ diff --git a/spoj/GSS1.cpp b/spoj/GSS1.cpp new file mode 100644 index 0000000..2b57512 --- /dev/null +++ b/spoj/GSS1.cpp @@ -0,0 +1,96 @@ +#include +using namespace std; +#define RANGE 4*50005 + +int a[50005]; +int tree[RANGE]; +int prefixsum[RANGE]; +int suffixsum[RANGE]; +int maxsum[RANGE]; +int sum[RANGE]; + + +void build(int node,int start, int end) +{ + if(start>end) + return; + + if(start==end) + { + tree[node]=prefixsum[node]=suffixsum[node]=maxsum[node]=sum[node]=a[start]; + return ; + } + + int mid=(start+end)>>1; + + build(2*node,start,mid); + build(2*node+1, mid+1, end); + + sum[node]=sum[2*node]+sum[2*node+1]; //calculating total sum of range + prefixsum[node]=max(prefixsum[2*node],sum[2*node]+prefixsum[2*node+1]); //max prefixsum + suffixsum[node]=max(suffixsum[2*node+1],sum[2*node+1]+suffixsum[2*node]); //max suffixsum + + maxsum[node]=max(max(maxsum[2*node],maxsum[2*node+1]),(suffixsum[2*node]+prefixsum[2*node+1])); + // maxsum[node]=max(prefixsum[node],max(suffixsum[node],max(maxsum[2*node],max(maxsum[2*node+1],suffixsum[2*node]+prefixsum[2*node+1])))); //maxsum + // maxsum[node]=max(maxsum[2*node],max(maxsum[2*node+1],suffixsum[2*node]+prefixsum[2*node+1])); //maxsum + tree[node]=maxsum[node]; +} + +int query(int node, int start, int end, int l, int r) +{ + if(start==l && end==r) + { + maxsum[node]=tree[node]; + return node; + } + int p1=2*node; + int p2=2*node+1; + + int mid=(start+end)>>1; + + if(r<=mid) return query(p1,start,mid,l,r); + else if(l>mid) return query(p2,mid+1,end,l,r); + else + { + int k1=query(p1,start,mid,l,mid); + int k2=query(p2,mid+1,end,mid+1,r); + + sum[node]=sum[k1]+sum[k2]; //calculating total sum of range + prefixsum[node]=max(prefixsum[k1],sum[k1]+prefixsum[k2]); //max prefixsum + suffixsum[node]=max(suffixsum[k2],sum[k2]+suffixsum[k1]); //max suffixsum + + maxsum[node]=max(max(maxsum[k1],maxsum[k2]),(suffixsum[k1]+prefixsum[k2])); + + // maxsum[node]=max(prefixsum[node],max(suffixsum[node],max(maxsum[p1],max(maxsum[p2],suffixsum[p1]+prefixsum[p2])))); //maxsum + // maxsum[node]=max(maxsum[2*node],max(maxsum[2*node+1],suffixsum[2*node]+prefixsum[2*node+1])); //maxsum + return node; + + } +} + +int main() +{ + int n; + + scanf("%d",&n); + + for(int i=1;i<=n;i++) + { + scanf("%d",&a[i]); + } + + build(1,1,n); + + int q; + + scanf("%d",&q); + + while(q--) + { + int x,y; + + scanf("%d %d",&x,&y); + + cout< +using namespace std; +#define SIZE 50007 +struct trees +{ + int maxsum; + int sum; + int prefixsum; + int suffixsum; +}; + +trees tree[SIZE<<3]; + +trees merge(trees a,trees b) +{ + trees res; + + res.sum=a.sum+b.sum; + res.prefixsum=max(a.prefixsum,a.sum+b.prefixsum); + res.suffixsum=max(b.suffixsum,b.sum+a.suffixsum); + res.maxsum=max(max(a.maxsum,b.maxsum),(a.suffixsum+b.prefixsum)); + + + return res; +} + +void build(int node,int start,int end) +{ + if(start==end) + { + int x; + scanf("%d",&x); + tree[node].sum=tree[node].prefixsum=tree[node].suffixsum=tree[node].maxsum=x; + return ; + } + + int p1=node<<1; + int p2=node<<1|1; + + int mid=(start+end)>>1; + + build(p1,start,mid); + build(p2,mid+1,end); + + tree[node]=merge(tree[p1],tree[p2]); +} + +trees query(int node,int start,int end, int l, int r) +{ + if(start==l && end==r) return tree[node]; + + int p1=node<<1; + int p2=node<<1|1; + + int mid=(start+end)>>1; + + if(r<=mid) return query(p1,start,mid,l,r); + else if(l>mid) return query(p2,mid+1,end,l,r); + else + { + return merge(query(p1,start,mid,l,mid),query(p2,mid+1,end,mid+1,r)); + } +} + +int main() +{ + int n; + if(scanf("%d",&n)==1) + { + build(1,1,n); + } + int q; + scanf("%d",&q); + while(q--) + { + int x,y; + scanf("%d%d",&x,&y); + printf("%d\n", query(1,1,n,x,y).maxsum); + } +} \ No newline at end of file diff --git a/spoj/GSS1test b/spoj/GSS1test new file mode 100755 index 0000000..1043c15 Binary files /dev/null and b/spoj/GSS1test differ diff --git a/spoj/GSS1test.cpp b/spoj/GSS1test.cpp new file mode 100644 index 0000000..28d022f --- /dev/null +++ b/spoj/GSS1test.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define rep(i,n) for( __typeof(n)i = 0 ; i < n ; i++ ) +#define For(i,n) for( __typeof(n)i = 1 ; i <= n ; i++ ) +#define forstl(i,n) for(__typeof(n.begin()) i = n.begin() ; i != n.end() ; i++) +typedef long long ll; + +#define SZ 50007 + +int a[SZ]; + +struct SegmentTree{ int prefixSum , suffixSum ,Sum ,maxSum ; }; + +SegmentTree tree[ SZ<<3 ]; + +SegmentTree merge( SegmentTree a , SegmentTree b) +{ + SegmentTree res ; + + res.Sum = a.Sum + b.Sum ; + + res.maxSum = max( max( a.maxSum , b.maxSum ) , (a.suffixSum + b.prefixSum ) ) ; + + res.prefixSum = max( a.prefixSum , a.Sum + b.prefixSum ); + + res.suffixSum = max( b.suffixSum , b.Sum + a.suffixSum ); + + return res ; +} + +void BUILD(int node , int start , int end) +{ + if(start == end) + { + int X; scanf("%d",&X); + + tree[node].prefixSum = tree[node].suffixSum = tree[node].Sum = tree[node].maxSum = X ; + + return ; + } + + int l = node<<1 ; + int r = node<<1|1; + + int mid = (start + end )>>1; + + BUILD(l,start,mid); + BUILD(r,mid+1,end); + + tree[ node ] = merge( tree[l] , tree[r] ); +} + + +SegmentTree Query(int node , int start , int end , int x , int y) +{ + if(start == x && end == y) return tree[node]; + + int l = node<<1 ; + int r = node<<1|1; + + int mid = (start + end )>>1; + + if(y <= mid ) return Query(l,start,mid,x,y); // whole side is in left + + else if( x > mid ) return Query(r,mid+1,end,x,y) ; // whole side is in right + + else + { + return merge( Query(l,start,mid,x,mid) , Query(r,mid+1,end,mid+1,y) ) ; // split in two side so merging + } +} +int main() +{ + int N ; + while(scanf("%d",&N)==1) + { + BUILD(1,1,N); + + int Q ; scanf("%d",&Q); + + while(Q--) + { + int x , y ; + scanf("%d %d",&x,&y); + printf("%d\n",Query(1,1,N,x,y).maxSum ); + } + } +} \ No newline at end of file diff --git a/spoj/GSS3 b/spoj/GSS3 new file mode 100755 index 0000000..8ccd1a5 Binary files /dev/null and b/spoj/GSS3 differ diff --git a/spoj/GSS3.cpp b/spoj/GSS3.cpp new file mode 100644 index 0000000..93d8c82 --- /dev/null +++ b/spoj/GSS3.cpp @@ -0,0 +1,111 @@ +#include +using namespace std; +#define SIZE 50007 +struct trees +{ + int maxsum; + int sum; + int prefixsum; + int suffixsum; +}; + +trees tree[SIZE<<3]; + +trees merge(trees a,trees b) +{ + trees res; + + res.sum=a.sum+b.sum; + res.prefixsum=max(a.prefixsum,a.sum+b.prefixsum); + res.suffixsum=max(b.suffixsum,b.sum+a.suffixsum); + res.maxsum=max(max(a.maxsum,b.maxsum),(a.suffixsum+b.prefixsum)); + + + return res; +} + +void build(int node,int start,int end) +{ + if(start==end) + { + int x; + scanf("%d",&x); + tree[node].sum=tree[node].prefixsum=tree[node].suffixsum=tree[node].maxsum=x; + return ; + } + + int p1=node<<1; + int p2=node<<1|1; + + int mid=(start+end)>>1; + + build(p1,start,mid); + build(p2,mid+1,end); + + tree[node]=merge(tree[p1],tree[p2]); +} + +trees query(int node,int start,int end, int l, int r) +{ + if(start==l && end==r) return tree[node]; + + int p1=node<<1; + int p2=node<<1|1; + + int mid=(start+end)>>1; + + if(r<=mid) return query(p1,start,mid,l,r); + else if(l>mid) return query(p2,mid+1,end,l,r); + else + { + return merge(query(p1,start,mid,l,mid),query(p2,mid+1,end,mid+1,r)); + } +} + + +void update(int node,int start,int end,int x,int val) +{ + if(start==end) + { + tree[node].maxsum=tree[node].prefixsum=tree[node].suffixsum=tree[node].sum=val; + } + else + { + int mid=(start+end)>>1; + if(start<=x && x<=mid) + { + update(2*node,start,mid,x,val); + } + else + { + update(2*node+1,mid+1,end,x,val); + } + tree[node]=merge(tree[2*node],tree[2*node+1]); + } +} + +int main() + +{ + int n; + if(scanf("%d",&n)==1) + { + build(1,1,n); + } + int q; + scanf("%d",&q); + while(q--) + { + int c,x,y; + scanf("%d%d%d",&c,&x,&y); + + if(c==0) + { + update(1,1,n,x,y); + } + else if(c==1) + { + printf("%d\n", query(1,1,n,x,y).maxsum); + } + } +} \ No newline at end of file diff --git a/spoj/GSS3test b/spoj/GSS3test new file mode 100755 index 0000000..3130091 Binary files /dev/null and b/spoj/GSS3test differ diff --git a/spoj/GSS3test.cpp b/spoj/GSS3test.cpp new file mode 100644 index 0000000..b9f781f --- /dev/null +++ b/spoj/GSS3test.cpp @@ -0,0 +1,85 @@ +#include +#include +#define MAX 100000 + +using namespace std; + +struct no { + int lsum, rsum, msum, sum; +}; + +no tree[ 4 * MAX + 1 ]; +int sums[ MAX + 1 ], array[ MAX + 1 ]; + +void init( int node, int i, int j ) { + if ( i == j ) { + tree[ node ] = ( ( no ) { array[ i ], array[ i ], array[ i ], array[ i ] } ); + } + else { + init( node * 2, i, ( i + j ) / 2 ); + init( node * 2 + 1, ( i + j ) / 2 + 1, j ); + no left = tree[ node * 2 ], right = tree[ node * 2 + 1 ]; + tree[ node ].lsum = max( left.lsum, left.sum + right.lsum ); + tree[ node ].rsum = max( right.rsum, right.sum + left.rsum ); + tree[ node ].msum = max( left.msum, max( right.msum, left.rsum + right.lsum ) ); + tree[ node ].sum = left.sum + right.sum; + } +} + +void update( int node, int pos, int val, int a, int b ) { + if ( a == b && a == pos ) { + tree[ node ] = ( ( no ) { val, val, val, val } ); + return; + } + else if ( pos <= ( a + b ) / 2 ) { + update( node * 2, pos, val, a, ( a + b ) / 2 ); + } + else if ( pos > ( a + b ) / 2 ) { + update( node * 2 + 1, pos, val, ( a + b ) / 2 + 1, b ); + } + no left = tree[ node * 2 ], right = tree[ node * 2 + 1 ]; + tree[ node ] = ( ( no ) { + max( left.lsum, left.sum + right.lsum ), + max( right.rsum, right.sum + left.rsum ), + max( left.msum, max( right.msum, right.lsum + left.rsum ) ), + left.sum + right.sum } ); +} + +no query( int node, int a, int b, int i, int j ) { + if ( i == a && j == b ) { + return tree[ node ]; + } + if ( j <= ( a + b ) / 2 ) { + return query( node * 2, a, ( a + b ) / 2, i, j ); + } + if ( i > ( a + b ) / 2 ) { + return query( node * 2 + 1, ( a + b ) / 2 + 1, b, i, j ); + } + no left = query( node * 2, a, ( a + b ) / 2, i, ( a + b ) / 2 ); + no right = query( node * 2 + 1, ( a + b ) / 2 + 1, b, ( a + b ) / 2 + 1, j ); + return ( ( no ) { + max( left.lsum, left.sum + right.lsum ), + max( right.rsum, right.sum + left.rsum ), + max( left.msum, max( right.msum, right.lsum + left.rsum ) ), + left.sum + right.sum } ); +} + +int main() { + int i, N, q, op, l, r; + scanf( "%d", &N ); + for ( i = 0; i < N; ++i ) { + scanf( "%d", array + i ); + } + init( 1, 0, N - 1 ); + scanf( "%d", &q ); + for ( i = 0; i < q; ++i ) { + scanf( "%d%d%d", &op, &l, &r ); + if ( op == 0 ) { + update( 1, l - 1, r, 0, N - 1 ); + } + else { + printf( "%d\n", query( 1, 0, N - 1, l - 1, r - 1 ).msum ); + } + } + return 0; +} \ No newline at end of file diff --git a/spoj/GSS3try b/spoj/GSS3try new file mode 100755 index 0000000..a8f7b0c Binary files /dev/null and b/spoj/GSS3try differ diff --git a/spoj/GSS3try.cpp b/spoj/GSS3try.cpp new file mode 100644 index 0000000..9bf6b94 --- /dev/null +++ b/spoj/GSS3try.cpp @@ -0,0 +1,119 @@ +#include +using namespace std; +#define SIZE 50005 +struct trees +{ + int maxsum; + int sum; + int prefixsum; + int suffixsum; +}; + +trees tree[SIZE<<3]; + +trees merge(trees a,trees b) +{ + trees res; + + res.sum=a.sum+b.sum; + res.prefixsum=max(a.prefixsum,(a.sum+b.prefixsum)); + res.suffixsum=max(b.suffixsum,(b.sum+a.suffixsum)); + res.maxsum=max(max(a.maxsum,b.maxsum),a.suffixsum+b.prefixsum); + + return res; +} + +void build(int node,int start,int end) +{ + if(start==end) + { + int x; + scanf("%d",&x); + tree[node].sum=tree[node].prefixsum=tree[node].suffixsum=tree[node].maxsum=x; + return; + } + int mid=(start+end)>>1; + + /*int p1=2*node; + int p2=2*node+1;*/ + + build(2*node,start,mid); + build(2*node+1,mid+1,end); + + tree[node]=merge(tree[2*node],tree[2*node+1]); +} + +void update(int node, int start, int end, int x,int val) +{ + if(start==end) + { + tree[node].sum=tree[node].prefixsum=tree[node].suffixsum=tree[node].maxsum=val; + } + else + { + int mid=(start+end)>>1; + if(start<=x&&x<=mid) + { + update(2*node,start,mid,x,val); + } + else + { + update(2*node+1,mid+1,end,x,val); + } + tree[node]=merge(tree[2*node],tree[2*node+1]); + } +} + +trees query(int node,int start,int end, int l,int r) +{ + if(start==l && end==r) + { + return tree[node]; + } + else + { + int mid=(start+end)>>1; + + /*int p1=2*node; + int p2=2*node+1;*/ + + if(r<=mid) + { + return query(2*node,start,mid,l,r); + } + else if(l>mid) + { + return query(2*node+1,mid+1,end,l,r); + } + else + { + return merge(query(2*node,start,mid,l,mid),query(2*node+1,mid+1,end,mid+1,r)); + } + } +} + +int main() +{ + int n; + if(scanf("%d",&n)==1) + { + build(1,1,n); + } + int q; + scanf("%d",&q); + + while(q--) + { + int c,x,y; + scanf("%d%d%d",&c,&x,&y); + if(c==0) + { + update(1,1,n,x,y); + } + else if(c==1) + { + printf("%d\n", query(1,1,n,x,y).maxsum); + } + } + return 0; +} \ No newline at end of file diff --git a/spoj/GSS4 b/spoj/GSS4 new file mode 100755 index 0000000..cc18883 Binary files /dev/null and b/spoj/GSS4 differ diff --git a/spoj/GSS4.cpp b/spoj/GSS4.cpp new file mode 100644 index 0000000..7bbe953 --- /dev/null +++ b/spoj/GSS4.cpp @@ -0,0 +1,162 @@ +//not using lazy but tackling the nodes which are 1 for optimisation + +#include +using namespace std; +#define ll long long +#define SIZE 100100 +int n; + +struct trees +{ + ll sum; + bool flag; +}; + +trees tree[SIZE<<3]; +ll a[SIZE]; + +trees merge(trees a, trees b) +{ + trees res; + res.sum=a.sum+b.sum; + res.flag=(a.flag && b.flag)?true:false; + return res; +} + +void build(int node,int start,int end) +{ + if(start==end) + { + tree[node].sum=a[start]; + if(a[start]==1) + { + tree[node].flag=true; + } + else + { + tree[node].flag=false; + } + return; + } + int mid=(start+end)>>1; + + int p1=node<<1; + int p2=node<<1|1; + + build(p1,start,mid); + build(p2,mid+1,end); + + tree[node]=merge(tree[p1],tree[p2]); +} + +ll query(int node,int start,int end,int l,int r) +{ + /*if(l>end || r>1; + int p1=node<<1; + int p2=node<<1|1; + + return query(p1,start,mid,l,r)+query(p2,mid+1,end,l,r);*/ + + if(start==l && end==r) + { + return tree[node].sum; + } + int mid=(start+end)>>1; + + int p1=node<<1; + int p2=node<<1|1; + + if(r<=mid) return query(p1,start,mid,l,r); + else if(l>mid) return query(p2,mid+1,end,l,r); + else + { + return query(p1,start,mid,l,mid)+query(p2,mid+1,end,mid+1,r); + } +} + +void update(int node,int start,int end,int l,int r) +{ + if(l>end || r>1; + + int p1=node<<1; + int p2=node<<1|1; + + if(r<=mid) + { + update(p1,start,mid,l,r); + } + else if(l>mid) + { + update(p2,mid+1,end,l,r); + } + else + { + update(p1,start,mid,l,r); + update(p2,mid+1,end,l,r); + } + tree[node]=merge(tree[p1],tree[p2]); +} + +int main() +{ + int count=1; + while(scanf("%d",&n)!=EOF) + { + printf("Case #%d:\n",count); + // ll a[n]; + for(int i=1;i<=n;i++) + { + scanf("%lld",&a[i]); + } + build(1,1,n); + + int q; + scanf("%d",&q); + + while(q--) + { + int c,x,y; + scanf("%d%d%d",&c,&x,&y); + + if(x>y) + { + int temp=x; + x=y; + y=temp; + } + + if(c) + { + printf("%lld\n", query(1,1,n,x,y)); + } + else + { + update(1,1,n,x,y); + } + } + count++; + printf("\n"); + } + return 0; +} \ No newline at end of file diff --git a/spoj/GSS4BIT b/spoj/GSS4BIT new file mode 100755 index 0000000..8692529 Binary files /dev/null and b/spoj/GSS4BIT differ diff --git a/spoj/GSS4BIT.cpp b/spoj/GSS4BIT.cpp new file mode 100644 index 0000000..c89ac54 --- /dev/null +++ b/spoj/GSS4BIT.cpp @@ -0,0 +1,144 @@ +#include +using namespace std; +#define SIZE 100100 +#define ll long long + +ll BIT[SIZE]; +ll a[SIZE]; +bool flag[SIZE]; +int n; +int root[SIZE]; + +void update(int x,ll val) +{ + for(;x<=n;x+=x&-x) + { + BIT[x]+=val; + } +} + +ll query(int x) +{ + ll sum=0; + for(;x>0;x-=x&-x) + { + sum+=BIT[x]; + } + return sum; +} + +int find(int i) +{ + if(root[i]!=i) + { + root[i]=find(root[i]); + } + return root[i]; +} + +void modify(int x,int y) +{ + /* Basic Idea : + + iterate from x to y and update each element a to sqrt(a) + i be the index between x and y + update(i,-a[i]) + a[i]=floor(sqrt(a[i])) + update(i,a[i]) + if(a[i]==1) set a flag for ith index*/ + + /* + + simply using a flag for the ith index is giving TLE + + for(int i=x;i<=y;i++) + { + if(!flag[i]) + { + update(i,-a[i]); + a[i]=floor(sqrt(a[i])); + update(i,a[i]); + if(a[i]==1) flag[i]=true; + } + }*/ + + /* + Modified Idea : + + recursively find the next index which does not have it's square root as one using an array root + it stores values at index i = i if square root of the ith index is not 1 + else it stores value at index i = i+1; + + */ + + int k=find(x); + + ll s,sq; + + while(k<=y) + { + s=query(k)-query(k-1); + if(s!=1) + { + update(k,-s); + sq=sqrt(s); + update(k,sq); + + if(sq==1) + { + root[k]=k+1; + } + } + k=find(k+1); + } +} + +int main() +{ + int count=1; + while(scanf("%d",&n)!=EOF) + { + printf("Case #%d:\n", count); + + memset(BIT,0,sizeof(BIT)); + memset(flag,false,sizeof(flag)); + + for(int i=1;i<=n;i++) + { + scanf("%lld",&a[i]); + update(i,a[i]); + root[i]=i; + } + + root[n+1]=n+1; + + int q; + scanf("%d",&q); + + while(q--) + { + int c,x,y; + scanf("%d%d%d",&c,&x,&y); + + if(x>y) + { + int temp=x; + x=y; + y=temp; + } + + if(c) + { + // printf("%lld\n", query(1,1,n,x,y)); + printf("%lld\n",query(y)-query(x-1)); + } + else + { + // update(1,1,n,x,y); + modify(x,y); + } + } + count++; + printf("\n"); + } +} \ No newline at end of file diff --git a/spoj/GSS4test b/spoj/GSS4test new file mode 100755 index 0000000..cf72bd4 Binary files /dev/null and b/spoj/GSS4test differ diff --git a/spoj/GSS4test.cpp b/spoj/GSS4test.cpp new file mode 100644 index 0000000..ce5583e --- /dev/null +++ b/spoj/GSS4test.cpp @@ -0,0 +1,80 @@ +/** http://www.spoj.com/problems/GSS4/ */ +#include +#include +#include +#define MAX 100100 + +long long int tree[4*MAX]; +long long int a[MAX]; + +void build(int i, int l, int r) { + if (l == r) + tree[i] = a[l]; + else { + int mid = (l + r) / 2; + build(2*i, l, mid); + build(2*i+1, mid+1, r); + tree[i] = tree[2*i] + tree[2*i+1]; + } +} + +void update(int l, int r, int i, int cl, int cr) { + if (cl == cr) { + tree[i] = (long long int) floor(sqrt(tree[i])); + return; + } + else if (cl >= l && cr <= r) { + if (tree[i] <= cr - cl + 1) + return; + } + int mid = (cl + cr) / 2; + if (r <= mid) + update(l, r, 2*i, cl, mid); + else if(l > mid) + update(l, r, 2*i+1, mid+1, cr); + else { + update(l, r, 2*i, cl, mid); + update(l, r, 2*i+1, mid+1, cr); + } + tree[i] = tree[2*i] + tree[2*i+1]; +} + +long long int sum(int l, int r, int i, int cl, int cr) { + if (cl > r || cr < l || cr < cl || r < l) + return 0; + else if (cl >= l && cr <= r) + return tree[i]; + else { + int mid = (cl + cr) / 2; + return sum(l, r, 2*i, cl, mid) + sum(l, r, 2*i+1, mid+1, cr); + } +} + +int main(void) { + int n; + int c = 1; + while(scanf("%d", &n) != EOF) { + printf("Case #%d:\n", c++); + int i; + for (i = 0; i < n; i++) + scanf("%lld", a+i); + build(1, 0, n-1); + int m; + scanf("%d", &m); + while (m--) { + int t, x, y; + scanf("%d %d %d", &t, &x, &y); + if (x > y) { + int temp = x; + x = y; + y = temp; + } + if (t == 1) + printf("%lld\n", sum(x-1, y-1, 1, 0, n-1)); + else + update(x-1, y-1, 1, 0, n-1); + } + printf("\n"); + } + return 0; +} \ No newline at end of file diff --git a/spoj/HAYBALE b/spoj/HAYBALE new file mode 100755 index 0000000..3716d8c Binary files /dev/null and b/spoj/HAYBALE differ diff --git a/spoj/HAYBALE.cpp b/spoj/HAYBALE.cpp new file mode 100644 index 0000000..7771053 --- /dev/null +++ b/spoj/HAYBALE.cpp @@ -0,0 +1,57 @@ +//Using BIT + +#include +using namespace std; +#define MAXN 1000005 +long long n,k; +long long BIT[MAXN]; +long long arr[MAXN]; + +void update(int x,int val) +{ + for(;x<=n;x+= x&-x) + BIT[x]+=val; +} + +int query(int x) +{ + int sum=0; + for(;x>0;x-= x&-x) + sum+=BIT[x]; + return sum; + +} + +int main() +{ + scanf("%lld %lld",&n,&k); + + for(long long i=0;i +#include +#include +#include +using namespace std; + +int tree[1000005],n,tree2[1000004]; + +int read(int idx){ + int sum = 0; + while(idx > 0){ + sum += tree[idx]; + idx -= (idx & -idx); + } + return sum; +} + +void update(int idx, int val){ + while(idx <= n){ + tree[idx] += val; + idx += (idx & -idx); + } +} + +int main() +{ + int i,j,k,a,b; + scanf("%d %d",&n,&k); + memset(tree,0,sizeof(tree)); + for(i=0;i +using namespace std; +#define ll long long +#define SIZE 100002 +vector > adj[SIZE]; +int n,m,src,dest; + +// int flag; + +void addedge(ll u, ll v, ll d) +{ + adj[u].push_back(make_pair(v,d)); + adj[v].push_back(make_pair(u,d)); +} + +void dijkstra() +{ + vector vis(n,false); + vector dist(n,1e9); + + dist[src]=0; + + priority_queue, vector >,greater > > s; + s.push(make_pair(0,src)); + + while(!s.empty()) + { + pair p=s.top(); + s.pop(); + + ll x=p.second; + + if(vis[x]) continue; + vis[x]=true; + + //if(x==dest) break; + + for(int i=0;i +using namespace std; +#define ll long long +#define SIZE 100002 +#define INF 1000000000 +vector >adj[SIZE]; +int n,m,src,dest; +ll dist[SIZE]; + +void addedge(ll u,ll v,ll d) +{ + adj[u].push_back(make_pair(v,d)); + adj[v].push_back(make_pair(u,d)); +} + +void dijsktra() +{ + for(int i=0;i<=n;i++) + { + dist[i]=INF; + } + dist[src]=0; + priority_queue >q; + q.push(make_pair(src,0)); + + while(!q.empty()) + { + pair p=q.top(); + q.pop(); + + int x=p.first; + + for(int i=0;idist[x]+w) + { + dist[e]=dist[x]+w; + q.push(make_pair(e,dist[e])); + } + } + } + if(dist[dest]==INF) + { + printf("NONE\n"); + } + else + { + printf("%lld\n", dist[dest]); + } +} + + +int main() +{ + int t; + scanf("%d",&t); + + while(t--) + { + scanf("%d %d %d %d",&n,&m,&src,&dest); + + for(int i=0;i<=n;i++) + { + adj[i].clear(); + } + + for(ll i=0;i +using namespace std; +#define SIZE 100002 +#define ll long long + +int n; +ll BIT1[SIZE]; +ll BIT2[SIZE]; + +void update1(int x,ll val) +{ + for(;x<=100001;x+=x&-x) + { + BIT1[x]+=val; + } +} + +void update2(int x,ll val) +{ + for(;x<=100001;x+=x&-x) + { + BIT2[x]+=val; + } +} + +ll query1(int x) +{ + ll sum=0; + for(;x>0;x-=x&-x) + { + sum+=BIT1[x]; + } + return sum; +} + +ll query2(int x) +{ + ll sum=0; + for(;x>0;x-=x&-x) + { + sum+=BIT2[x]; + } + return sum; +} + + + +int main() +{ + ll t; + scanf("%lld",&t); + + while(t--) + { + int type; + int c,p,q; + ll v; + memset(BIT1,0,sizeof(BIT1)); + memset(BIT2,0,sizeof(BIT2)); + + scanf("%d %d",&n,&c); + while(c--) + { + scanf("%d %d %d",&type,&p,&q); + if(type==0) + { + scanf("%lld",&v); + + update1(p,v); + update1(q+1,-v); + update2(p,(long long)v*(p-1)); + update2(q+1,-(long long)v*q); + } + else + { + ll ans = (query1(q)*q-query2(q)) - (query1(p-1)*(p-1)-query2(p-1)); + printf("%lld\n", ans); + } + } + + } + + return 0; +} \ No newline at end of file diff --git a/spoj/HORRIBLEseg b/spoj/HORRIBLEseg new file mode 100755 index 0000000..ea4dbf2 Binary files /dev/null and b/spoj/HORRIBLEseg differ diff --git a/spoj/HORRIBLEseg.cpp b/spoj/HORRIBLEseg.cpp new file mode 100644 index 0000000..ed56ad2 --- /dev/null +++ b/spoj/HORRIBLEseg.cpp @@ -0,0 +1,120 @@ +#include +using namespace std; +#define ll long long +#define SIZE 100005 + +struct trees +{ + ll sum; +}; + +ll lazy[SIZE<<3]; +trees tree[SIZE<<3]; + +void build(int node,int start,int end) +{ + if(start>end) + return; + if(start==end) + { + tree[node].sum=0; + return; + } + int mid=(start+end)>>1; + + build(2*node,start,mid); + build(2*node+1,mid+1,end); + + tree[node].sum=tree[2*node].sum+tree[2*node+1].sum; +} + +void update(int node,int start,int end,int l,int r,ll val) +{ + if(lazy[node]) + { + tree[node].sum+=(end-start+1)*lazy[node]; + if(startend || start>r || end>1; + update(2*node,start,mid,l,r,val); + update(2*node+1,mid+1,end,l,r,val); + + tree[node].sum=tree[2*node].sum+tree[2*node+1].sum; +} + +ll query(int node,int start,int end,int l,int r) +{ + if(lazy[node]) + { + tree[node].sum+=(end-start+1)*lazy[node]; + if(startend || start>r || end>1; + return query(2*node,start,mid,l,r)+query(2*node+1,mid+1,end,l,r); +} + +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + memset(lazy,0,sizeof(lazy)); + memset(tree,0,sizeof(tree)); + int n,m; + scanf("%d %d",&n,&m); + + build(1,1,n); + + while(m--) + { + int c,x,y; + ll val; + + scanf("%d",&c); + if(c) + { + scanf("%d %d", &x,&y); + printf("%lld\n",query(1,1,n,x,y)); + } + else + { + scanf("%d%d%lld",&x,&y,&val); + update(1,1,n,x,y,val); + } + } + } + return 0; +} \ No newline at end of file diff --git a/spoj/HORRIBLEsegtest b/spoj/HORRIBLEsegtest new file mode 100755 index 0000000..63253ef Binary files /dev/null and b/spoj/HORRIBLEsegtest differ diff --git a/spoj/HORRIBLEsegtest.cpp b/spoj/HORRIBLEsegtest.cpp new file mode 100644 index 0000000..1ed358a --- /dev/null +++ b/spoj/HORRIBLEsegtest.cpp @@ -0,0 +1,108 @@ +#include +#include +using namespace std; + +const int N=100005; +long long int lazy[4*N]; +long long int seg[4*N]; + +void build(int low,int high,int node) +{ + if(low>high) + return; + if(low == high) + { + seg[node]=0; + return; + } + int mid = low+high>>1; + build(low,mid,2*node+1); + build(mid+1,high,2*node+2); + seg[node]=seg[2*node+1]+seg[2*node+2]; +} + +void update(int low,int high,int lq,int hq,int node,long long int val) +{ + if(lazy[node]) + { + seg[node]+=(high-low+1)*lazy[node]; + if(high!=low) + { + lazy[2*node+1]+=lazy[node]; + lazy[2*node+2]+=lazy[node]; + } + lazy[node]=0; + } + if(low>hq || high>1; + update(low,mid,lq,hq,2*node+1,val); + update(mid+1,high,lq,hq,2*node+2,val); + seg[node]=seg[2*node+1]+seg[2*node+2]; +} + +long long int query(int low,int high,int lq,int hq,int node) +{ + if(lazy[node]) + { + seg[node]+=(high-low+1)*lazy[node]; + if(high!=low) + { + lazy[2*node+1]+=lazy[node]; + lazy[2*node+2]+=lazy[node]; + } + lazy[node]=0; + } + if(low>hq || high>1; + return query(low,mid,lq,hq,2*node+1)+query(mid+1,high,lq,hq,2*node+2); +} +int main(){ + int t; + scanf("%d",&t); + int n,q; + while(t--) + { + memset(seg,0,sizeof(seg)); + memset(lazy,0,sizeof(lazy)); + scanf("%d %d",&n,&q); + int type; + int x,y; + long long int val; + build(0,n-1,0); + while(q--) + { + scanf("%d",&type); + //printf("%dhh\n",type); + if(type) + { + scanf("%d %d",&x,&y); + printf("%lld\n",query(0,n-1,x-1,y-1,0)); + } + else + { + scanf("%d %d %lld",&x,&y,&val); + update(0,n-1,x-1,y-1,0,val); + } + } + + } + + return 0; + +} \ No newline at end of file diff --git a/spoj/HORRIBLEtest b/spoj/HORRIBLEtest new file mode 100755 index 0000000..445735b Binary files /dev/null and b/spoj/HORRIBLEtest differ diff --git a/spoj/HORRIBLEtest.cpp b/spoj/HORRIBLEtest.cpp new file mode 100644 index 0000000..98608b7 --- /dev/null +++ b/spoj/HORRIBLEtest.cpp @@ -0,0 +1,48 @@ +#include +#include + +using namespace std; + +long long bit1[100002],bit2[100002]; + +void update(long long bit[], int idx, long long val){ + for(int x = idx;x <= 100001;x += x & -x) + bit[x] += val; +} + +long long query(long long bit[], int idx){ + long long ret = 0; + + for(int x = idx;x > 0;x -= x & -x) + ret += bit[x]; + + return ret; +} + +int main(){ + int T,N,Q; + + scanf("%d",&T); + + while(T--){ + scanf("%d %d",&N,&Q); + + memset(bit1,0,sizeof bit1); + memset(bit2,0,sizeof bit2); + + for(int i = 0,op,l,r,v;i < Q;++i){ + scanf("%d %d %d",&op,&l,&r); + + if(op == 0){ + scanf("%d",&v); + + update(bit1,l,v); update(bit1,r + 1,-v); + update(bit2,l,-(long long)v * (l - 1)); update(bit2,r + 1,(long long)v * r); + }else{ + printf("%lld\n",query(bit1,r) * r + query(bit2,r) - query(bit1,l - 1) * (l - 1) - query(bit2,l - 1)); + } + } + } + + return 0; +} \ No newline at end of file diff --git a/spoj/HOTELS b/spoj/HOTELS new file mode 100755 index 0000000..6b4b1df Binary files /dev/null and b/spoj/HOTELS differ diff --git a/spoj/HOTELS#2 b/spoj/HOTELS#2 new file mode 100755 index 0000000..b32c008 Binary files /dev/null and b/spoj/HOTELS#2 differ diff --git a/spoj/HOTELS#2.cpp b/spoj/HOTELS#2.cpp new file mode 100644 index 0000000..65dd8eb --- /dev/null +++ b/spoj/HOTELS#2.cpp @@ -0,0 +1,63 @@ +//using prefix sum + +/*error in case + + 7 28 + 24 2 1 23 2 1 1 +*/ +#include +using namespace std; +#define ll long long +#define SIZE 300005 + +int n; +ll m; + +ll a[SIZE]; +ll pre[SIZE]; + +int main() +{ + scanf("%d %lld",&n, &m); + + for(int i=0;im) //if values are bigger in prefix sum then we try to reach the closest value + { + ll s=lower_bound(pre,pre+n,pre[k]-m)-pre; + // printf("%\n"); + ans=pre[k]-pre[s]; + } + else //if value is found in prefix sum + { + // printf("here\n"); + ans=pre[k]; + } + + printf("%lld\n", ans); +} \ No newline at end of file diff --git a/spoj/HOTELS.cpp b/spoj/HOTELS.cpp new file mode 100644 index 0000000..8cbd37e --- /dev/null +++ b/spoj/HOTELS.cpp @@ -0,0 +1,48 @@ +//using modified kadane +#include +using namespace std; +#define ll long long +#define SIZE 300005 + +int n; +ll m; + +ll a[SIZE]; + +int main() +{ + scanf("%d %lld",&n, &m); + + for(int i=0;im) + { + // printf("here\n"); + while(sum>m) + { + sum-=a[i]; + i++; + } + + } + // printf("%lld\n", sum); + + if(max +using namespace std; + +int main() +{ + int n; + scanf("%d",&n); + + char a[n][n]; + + for(int i=0;i>a[i][j]; + } + } + + +} \ No newline at end of file diff --git a/spoj/KAUSANDNIHA b/spoj/KAUSANDNIHA new file mode 100755 index 0000000..abca0a1 Binary files /dev/null and b/spoj/KAUSANDNIHA differ diff --git a/spoj/KAUSANDNIHA Input file #1 b/spoj/KAUSANDNIHA Input file #1 new file mode 100644 index 0000000..090f9c9 --- /dev/null +++ b/spoj/KAUSANDNIHA Input file #1 @@ -0,0 +1,5019 @@ +10 +85 87 +78 1 794 +21 72 493 +80 37 363 +83 21 60 +64 57 541 +82 58 737 +2 9 568 +40 83 531 +43 39 68 +46 35 803 +28 69 70 +68 4 457 +22 83 230 +44 37 920 +20 58 199 +65 11 371 +54 12 92 +56 52 874 +18 51 997 +57 11 926 +5 38 337 +36 62 730 +54 83 125 +66 83 546 +55 18 435 +15 39 751 +33 49 277 +59 19 585 +39 37 755 +15 8 61 +67 54 740 +18 47 587 +15 16 796 +51 80 379 +38 7 98 +83 63 493 +53 52 302 +76 67 442 +66 20 445 +20 76 730 +27 58 98 +72 32 676 +50 3 568 +67 53 354 +82 6 307 +29 45 625 +14 12 733 +5 44 20 +56 24 709 +16 1 150 +67 69 619 +1 12 452 +67 61 380 +19 85 229 +7 81 194 +1 25 765 +15 80 988 +37 84 492 +83 11 860 +22 68 552 +78 49 276 +63 50 122 +79 31 30 +13 6 794 +84 54 144 +32 54 530 +67 25 444 +69 19 539 +72 16 905 +14 79 689 +40 28 918 +7 5 744 +71 84 491 +25 53 726 +20 51 506 +10 40 787 +25 63 543 +75 3 508 +81 75 349 +12 3 829 +10 84 747 +14 6 423 +67 76 606 +22 57 731 +24 76 321 +37 85 627 +18 66 709 +417 +13 54 +45 8 +43 40 +61 2 +28 70 +85 1 +84 47 +64 22 +37 81 +44 50 +66 24 +40 17 +60 82 +5 34 +19 14 +56 31 +67 57 +80 66 +11 55 +67 38 +82 23 +81 37 +70 59 +58 63 +54 58 +70 35 +82 66 +8 13 +62 12 +4 38 +67 16 +25 5 +72 20 +70 82 +31 8 +76 69 +73 71 +20 14 +1 35 +33 55 +7 17 +46 45 +83 53 +58 16 +21 61 +53 45 +76 78 +49 19 +54 76 +15 41 +40 47 +25 27 +33 1 +40 75 +35 30 +44 42 +46 46 +1 43 +55 15 +59 76 +32 68 +35 64 +17 40 +82 70 +30 53 +68 27 +15 7 +53 4 +49 50 +78 84 +79 79 +82 39 +39 39 +39 9 +54 54 +41 85 +78 32 +64 10 +71 17 +79 58 +70 61 +84 84 +24 8 +44 73 +57 36 +28 7 +71 24 +3 25 +62 41 +75 72 +51 30 +29 43 +61 49 +52 3 +65 3 +60 49 +20 58 +4 44 +66 47 +73 79 +40 57 +1 25 +80 3 +6 13 +85 80 +85 50 +66 70 +49 41 +33 16 +44 12 +60 60 +18 79 +33 21 +79 55 +25 66 +48 21 +37 5 +2 73 +7 8 +1 48 +44 42 +12 25 +26 61 +22 58 +33 65 +26 7 +40 43 +85 29 +21 79 +83 2 +16 2 +22 10 +7 23 +39 55 +72 81 +18 31 +37 71 +12 19 +3 33 +33 77 +55 16 +83 51 +58 40 +36 35 +75 75 +36 47 +76 14 +13 39 +79 52 +51 65 +47 68 +52 41 +10 63 +16 55 +53 49 +46 64 +64 44 +29 78 +40 64 +28 29 +53 20 +32 85 +76 45 +39 69 +11 4 +5 14 +28 57 +54 79 +76 70 +48 85 +75 9 +63 10 +9 48 +2 48 +68 71 +33 77 +48 21 +77 38 +65 72 +63 32 +32 67 +3 16 +80 56 +9 71 +82 57 +27 28 +22 5 +37 30 +9 81 +34 77 +66 23 +68 70 +43 16 +22 65 +2 84 +53 75 +23 55 +5 17 +68 56 +2 21 +69 71 +49 5 +75 42 +76 40 +37 66 +31 60 +45 14 +44 44 +71 23 +23 73 +63 76 +19 85 +2 24 +17 69 +79 60 +5 19 +45 53 +23 76 +9 55 +31 3 +35 18 +62 36 +73 62 +79 59 +84 59 +46 62 +6 64 +18 7 +44 76 +76 79 +51 80 +12 52 +4 76 +85 54 +45 72 +56 36 +4 74 +71 77 +51 65 +50 6 +38 52 +24 43 +72 42 +6 31 +32 81 +66 39 +32 78 +48 77 +25 47 +46 70 +33 58 +20 36 +4 48 +69 11 +69 33 +16 21 +84 40 +20 28 +38 25 +58 26 +63 80 +65 9 +29 27 +1 54 +30 3 +38 19 +17 14 +54 20 +18 38 +30 1 +27 3 +21 68 +42 82 +10 79 +22 24 +19 84 +18 40 +49 47 +23 6 +15 9 +50 9 +27 67 +64 81 +43 82 +75 30 +82 16 +32 60 +40 30 +56 49 +65 34 +72 40 +74 5 +37 38 +8 59 +43 22 +68 8 +72 51 +31 50 +46 30 +46 77 +59 43 +50 47 +17 4 +76 29 +53 12 +63 81 +52 51 +85 3 +3 7 +18 3 +70 42 +52 56 +8 39 +21 10 +68 23 +44 42 +65 8 +45 38 +53 78 +67 62 +4 1 +58 12 +51 57 +56 11 +21 74 +55 47 +72 21 +18 36 +59 80 +46 41 +17 46 +39 39 +53 84 +33 62 +76 56 +39 36 +56 11 +48 64 +24 18 +74 1 +48 43 +48 77 +20 22 +27 35 +16 29 +75 74 +74 71 +69 83 +26 17 +60 58 +72 13 +8 85 +23 12 +63 3 +72 51 +4 34 +50 51 +67 26 +72 9 +60 44 +79 49 +74 68 +76 58 +65 16 +31 81 +73 59 +8 38 +58 72 +49 35 +75 35 +42 35 +26 48 +85 7 +73 28 +57 47 +28 51 +53 58 +75 43 +30 54 +16 17 +7 45 +76 14 +82 48 +43 3 +40 74 +37 81 +23 62 +1 22 +26 73 +6 82 +35 33 +47 44 +47 78 +1 77 +4 58 +50 10 +18 40 +65 56 +45 22 +58 84 +10 52 +36 32 +70 36 +10 10 +66 15 +7 57 +4 10 +15 51 +3 57 +84 6 +30 5 +57 4 +45 36 +59 46 +58 74 +44 24 +40 36 +57 94 +47 9 961 +22 8 287 +55 8 678 +29 25 182 +45 48 324 +2 54 955 +49 8 43 +51 44 920 +57 8 470 +45 56 977 +17 45 134 +9 25 957 +14 22 667 +36 9 913 +48 54 903 +57 14 3 +21 6 719 +34 15 378 +50 14 574 +42 17 126 +39 49 497 +4 1 154 +33 30 981 +13 8 949 +17 15 30 +27 14 161 +18 50 720 +31 27 903 +47 35 727 +12 35 141 +33 17 939 +17 36 432 +25 12 906 +13 24 392 +10 56 422 +19 25 672 +1 2 96 +44 32 89 +4 37 570 +49 48 711 +54 40 434 +9 56 280 +21 39 500 +21 51 465 +13 20 87 +35 54 916 +13 14 12 +57 16 388 +12 19 774 +18 10 743 +2 22 125 +17 46 64 +11 9 713 +32 30 405 +19 1 735 +20 36 436 +5 7 670 +6 7 803 +38 34 90 +49 51 961 +9 11 558 +9 44 817 +22 54 523 +17 45 580 +37 22 379 +19 1 46 +54 5 900 +4 26 387 +26 6 949 +25 54 507 +50 21 418 +39 29 821 +16 10 995 +34 42 438 +24 21 318 +15 39 18 +15 51 157 +6 14 746 +3 39 172 +48 23 560 +30 15 653 +39 53 926 +33 27 92 +40 4 567 +34 43 51 +50 57 334 +8 31 500 +44 36 569 +47 54 343 +15 45 264 +35 33 940 +35 30 632 +7 6 805 +3 45 684 +139 +22 39 +57 14 +55 14 +21 28 +5 23 +6 25 +13 19 +42 27 +6 25 +20 54 +21 14 +27 29 +20 32 +22 38 +35 18 +37 56 +15 53 +28 12 +9 8 +39 29 +30 4 +53 42 +22 37 +27 43 +4 6 +39 25 +19 24 +12 54 +14 33 +34 49 +9 30 +6 23 +25 50 +51 49 +57 32 +20 29 +51 15 +30 31 +10 15 +32 30 +20 30 +13 38 +53 24 +34 10 +15 27 +17 23 +15 22 +4 55 +14 54 +46 29 +45 8 +1 54 +38 46 +28 6 +3 2 +35 23 +31 47 +19 43 +29 53 +52 43 +38 11 +24 52 +48 28 +49 21 +24 37 +49 27 +3 8 +24 56 +53 51 +20 15 +11 55 +37 1 +3 55 +43 32 +9 53 +17 46 +22 57 +40 12 +27 47 +48 9 +42 56 +52 44 +6 18 +1 18 +27 21 +32 37 +34 11 +53 52 +24 38 +26 49 +49 2 +37 13 +1 36 +41 43 +41 31 +10 26 +29 4 +12 51 +21 29 +11 6 +8 1 +2 57 +27 54 +51 50 +51 20 +41 42 +37 37 +55 53 +31 38 +38 14 +27 6 +39 56 +10 10 +8 46 +54 34 +52 4 +34 53 +3 3 +8 12 +11 1 +47 52 +43 26 +47 40 +21 36 +20 17 +49 46 +39 47 +3 7 +15 26 +52 11 +2 5 +14 35 +16 32 +37 24 +2 48 +24 49 +1 9 +17 6 +7 54 +83 14 +29 31 978 +59 44 465 +66 18 108 +46 17 741 +47 34 588 +10 56 794 +15 50 621 +38 8 372 +11 19 535 +82 70 568 +80 19 68 +19 77 434 +9 63 133 +4 25 524 +691 +74 59 +44 83 +34 10 +17 3 +44 55 +10 78 +68 29 +45 69 +18 38 +65 39 +62 3 +33 50 +15 12 +61 21 +39 2 +12 29 +63 55 +29 14 +65 45 +19 28 +19 29 +22 3 +60 66 +72 77 +24 56 +33 2 +62 68 +54 79 +82 31 +16 37 +36 28 +65 15 +2 13 +31 66 +61 50 +13 79 +81 38 +2 57 +23 76 +53 46 +51 5 +48 29 +75 21 +27 73 +55 46 +29 10 +76 14 +27 77 +26 58 +63 3 +27 75 +2 24 +29 3 +83 52 +78 55 +14 45 +60 64 +77 51 +5 23 +44 59 +68 72 +71 60 +5 14 +54 31 +74 36 +36 17 +27 37 +43 56 +42 45 +27 36 +17 40 +1 76 +24 80 +46 28 +19 6 +6 7 +81 76 +69 2 +6 39 +35 80 +77 74 +16 21 +27 59 +79 69 +20 22 +24 39 +64 27 +31 4 +23 80 +34 45 +2 39 +51 2 +34 36 +7 40 +78 44 +39 71 +34 57 +11 61 +35 6 +49 58 +27 72 +13 8 +19 47 +14 41 +43 48 +5 47 +3 58 +49 37 +11 58 +79 8 +18 37 +81 55 +10 9 +35 48 +14 83 +22 44 +74 34 +51 12 +80 64 +53 39 +28 60 +3 34 +35 54 +73 48 +31 68 +55 51 +24 55 +22 36 +63 56 +83 80 +58 21 +40 52 +55 7 +63 54 +73 35 +10 21 +12 15 +54 49 +71 43 +13 18 +30 67 +68 56 +38 10 +8 21 +68 8 +17 46 +28 56 +17 2 +65 82 +56 54 +34 68 +77 48 +82 47 +16 69 +9 28 +6 41 +14 73 +13 54 +2 21 +74 70 +31 10 +32 58 +65 48 +60 49 +46 35 +20 82 +19 16 +49 17 +63 64 +5 74 +8 10 +35 24 +2 47 +78 4 +70 68 +76 17 +78 24 +78 62 +74 57 +28 36 +8 50 +38 26 +65 6 +45 47 +70 49 +38 80 +61 75 +21 62 +38 15 +68 28 +2 60 +47 79 +3 41 +61 76 +14 5 +32 21 +57 72 +49 41 +77 10 +5 63 +58 45 +63 38 +36 83 +20 76 +17 4 +23 18 +67 70 +17 72 +30 77 +65 44 +1 16 +67 57 +4 36 +14 83 +45 21 +63 23 +65 45 +60 20 +44 79 +16 60 +3 38 +77 72 +24 10 +60 54 +6 41 +17 6 +59 3 +65 65 +38 82 +65 3 +19 47 +25 4 +8 4 +26 51 +83 41 +30 5 +79 26 +76 22 +36 52 +78 44 +13 11 +50 71 +17 31 +56 54 +29 37 +59 51 +83 83 +57 7 +4 82 +60 6 +40 6 +13 38 +31 5 +59 69 +59 54 +30 71 +67 82 +62 83 +29 37 +57 61 +73 32 +31 75 +35 4 +81 41 +5 60 +49 44 +65 61 +81 15 +65 60 +4 43 +33 33 +34 16 +31 15 +19 62 +51 75 +42 40 +26 75 +31 63 +78 31 +20 83 +7 68 +46 74 +48 47 +8 32 +26 11 +75 58 +46 25 +73 79 +39 8 +58 6 +2 19 +48 31 +11 81 +10 8 +28 33 +10 37 +20 56 +27 68 +22 34 +19 47 +48 10 +21 10 +37 13 +6 78 +24 66 +3 25 +4 50 +58 14 +47 71 +25 77 +23 34 +30 42 +9 59 +29 30 +10 48 +79 60 +60 16 +69 14 +32 77 +11 55 +62 14 +82 66 +66 57 +82 33 +44 23 +26 66 +60 59 +27 68 +34 56 +18 46 +23 16 +22 2 +35 11 +15 66 +4 29 +37 66 +42 35 +51 27 +8 49 +59 54 +75 5 +39 51 +63 66 +38 16 +41 58 +62 66 +74 3 +67 25 +13 2 +7 17 +30 43 +2 74 +80 52 +17 5 +20 76 +61 11 +83 17 +64 65 +2 19 +80 42 +79 61 +27 69 +64 10 +13 76 +11 19 +12 43 +64 16 +33 61 +70 50 +68 7 +45 48 +17 47 +64 81 +28 68 +19 27 +29 14 +5 55 +83 71 +68 15 +66 78 +34 81 +41 17 +13 73 +80 83 +42 67 +6 6 +32 25 +55 15 +25 82 +83 43 +29 31 +60 33 +3 62 +23 70 +76 5 +67 26 +5 24 +46 18 +17 45 +20 61 +29 28 +70 63 +52 41 +77 80 +40 79 +39 71 +27 15 +20 32 +76 45 +18 69 +52 4 +14 57 +31 62 +74 47 +24 13 +27 55 +40 13 +34 11 +54 30 +7 13 +29 49 +83 58 +66 22 +6 62 +69 26 +47 37 +32 63 +10 62 +45 3 +28 68 +15 55 +39 57 +67 75 +68 40 +21 77 +55 49 +42 57 +26 25 +81 31 +6 66 +59 55 +20 8 +34 29 +72 81 +32 17 +65 49 +71 23 +23 57 +17 10 +17 38 +3 71 +6 48 +45 32 +75 45 +65 80 +28 44 +51 47 +54 4 +78 42 +2 26 +58 69 +78 48 +12 17 +22 28 +26 38 +68 31 +28 77 +81 75 +28 72 +37 12 +68 64 +55 38 +30 28 +42 24 +70 46 +50 47 +31 44 +12 45 +63 36 +73 8 +73 60 +41 20 +53 39 +12 80 +27 51 +9 15 +31 66 +55 60 +11 13 +83 83 +61 52 +46 12 +15 57 +56 80 +12 48 +4 1 +25 48 +24 77 +3 38 +77 29 +5 5 +46 38 +70 18 +14 80 +33 16 +82 11 +71 45 +22 5 +21 77 +5 33 +42 11 +36 69 +58 59 +62 60 +13 58 +9 20 +62 54 +57 49 +71 73 +48 24 +6 47 +34 79 +11 55 +3 31 +51 7 +63 12 +18 19 +80 75 +80 62 +52 10 +36 63 +29 15 +33 6 +66 24 +78 33 +47 3 +82 80 +81 9 +54 1 +43 24 +10 25 +36 27 +43 32 +22 40 +13 73 +52 49 +52 83 +66 4 +5 51 +27 83 +3 76 +2 2 +75 3 +13 45 +6 55 +72 15 +80 24 +42 39 +58 66 +81 71 +58 49 +39 29 +49 24 +32 56 +77 62 +55 79 +54 60 +80 49 +62 10 +13 67 +67 1 +81 63 +24 42 +22 82 +24 19 +72 81 +71 30 +26 39 +53 61 +11 49 +39 66 +44 12 +42 44 +60 20 +56 73 +6 39 +73 3 +19 17 +48 43 +18 71 +61 6 +72 51 +35 17 +6 7 +77 17 +55 32 +2 18 +47 46 +61 23 +65 33 +15 73 +75 5 +75 10 +21 42 +55 38 +33 35 +46 21 +3 83 +37 8 +9 31 +27 66 +65 28 +83 28 +73 61 +54 57 +13 68 +46 4 +72 41 +16 12 +82 70 +52 34 +25 17 +54 27 +19 11 +34 27 +44 64 +9 25 +8 12 +56 81 +75 26 +54 4 +13 20 +11 5 +60 29 +16 61 +19 71 +12 43 +4 68 +69 26 +78 22 +52 41 +2 64 +69 10 +75 41 +10 66 +69 66 +72 81 +5 2 +2 67 +31 21 +45 49 +8 59 +8 14 +46 79 +42 44 +17 11 +1 22 +77 69 +34 71 +29 43 +53 17 +28 44 +15 33 +46 19 +16 76 +39 63 +44 49 +41 51 +66 4 +46 24 +47 65 +37 47 +6 30 +36 39 +17 67 +1 72 +1 32 +33 15 +64 81 +33 82 +76 75 +62 36 +43 19 +3 25 +22 51 +52 71 +35 5 +38 41 +38 73 +82 57 +56 3 +18 11 +16 9 328 +5 15 801 +9 7 775 +13 11 832 +12 10 480 +12 10 20 +8 7 747 +13 8 970 +4 3 529 +18 2 197 +13 17 167 +130 +1 15 +4 9 +3 14 +2 11 +14 13 +2 9 +4 9 +18 9 +15 6 +3 5 +2 4 +5 16 +2 4 +8 14 +2 6 +1 2 +18 3 +8 2 +16 9 +12 9 +1 11 +17 3 +17 14 +9 11 +2 12 +13 1 +13 17 +16 14 +2 3 +9 1 +8 8 +18 7 +8 6 +6 3 +12 15 +12 11 +5 8 +13 1 +2 3 +11 1 +12 6 +17 7 +2 14 +2 2 +14 9 +2 3 +16 18 +7 5 +5 10 +5 16 +6 16 +6 8 +4 18 +8 3 +1 16 +1 10 +3 17 +16 3 +12 16 +4 7 +6 3 +7 1 +2 11 +3 4 +2 7 +18 5 +3 5 +12 6 +5 17 +6 3 +14 6 +12 15 +4 8 +17 13 +5 2 +17 10 +4 3 +10 4 +13 12 +7 14 +18 6 +16 18 +11 7 +3 13 +5 8 +15 16 +11 6 +12 14 +13 8 +6 17 +9 4 +6 11 +6 13 +14 16 +4 18 +9 4 +6 6 +1 14 +10 4 +8 14 +11 2 +10 4 +7 1 +15 18 +9 3 +16 17 +4 2 +7 10 +14 2 +5 18 +2 14 +1 5 +17 1 +18 9 +4 5 +2 13 +6 11 +16 10 +12 10 +9 2 +12 5 +16 16 +6 5 +5 1 +4 9 +16 3 +2 16 +5 1 +15 4 +9 18 +63 78 +3 29 17 +34 30 438 +53 20 967 +8 15 22 +5 18 670 +52 44 752 +32 5 606 +60 28 831 +51 15 430 +5 41 444 +4 42 462 +22 10 902 +60 62 871 +61 5 519 +39 7 425 +31 59 621 +24 27 848 +17 21 901 +8 7 826 +44 9 951 +6 12 879 +59 33 305 +14 27 652 +51 24 348 +35 61 744 +39 26 959 +21 47 951 +6 63 970 +19 6 513 +45 49 848 +46 54 350 +23 49 737 +9 60 152 +57 47 855 +44 19 221 +38 55 271 +26 11 108 +37 16 690 +7 32 494 +44 11 654 +26 54 909 +18 13 424 +43 20 102 +31 11 163 +40 55 127 +45 27 770 +13 52 711 +26 25 502 +36 29 43 +53 7 513 +51 31 212 +41 46 20 +12 25 592 +43 53 931 +58 30 737 +23 11 753 +43 21 290 +8 44 297 +51 16 97 +59 3 200 +12 53 159 +18 28 323 +35 40 75 +8 19 272 +55 11 767 +25 34 781 +24 13 936 +9 21 341 +16 6 387 +50 62 217 +26 10 186 +29 28 852 +15 60 341 +24 5 754 +22 57 255 +49 18 673 +19 39 73 +9 47 222 +390 +63 6 +26 47 +4 13 +9 12 +48 36 +37 50 +50 33 +26 10 +35 19 +31 28 +20 14 +44 54 +32 19 +35 39 +3 37 +16 63 +40 41 +44 41 +51 51 +52 36 +23 25 +20 7 +56 44 +17 27 +60 45 +53 16 +57 33 +4 25 +51 38 +61 51 +9 14 +48 48 +52 27 +26 38 +14 12 +10 34 +35 27 +40 27 +7 54 +53 3 +34 42 +16 27 +9 19 +49 58 +55 47 +45 63 +60 28 +46 46 +54 6 +20 2 +15 27 +35 49 +54 11 +12 58 +63 63 +61 33 +39 11 +59 46 +28 44 +40 19 +27 19 +16 21 +44 59 +4 34 +1 21 +35 14 +48 4 +62 38 +15 9 +32 14 +6 27 +46 42 +38 39 +24 2 +19 63 +18 46 +17 33 +1 60 +27 4 +29 25 +25 61 +38 7 +2 37 +44 14 +43 10 +25 48 +35 5 +26 7 +43 50 +6 61 +47 23 +41 63 +53 42 +60 16 +43 25 +39 2 +22 13 +8 21 +49 51 +34 28 +59 58 +10 28 +62 36 +34 41 +20 39 +37 3 +59 14 +1 46 +53 60 +60 33 +19 35 +34 38 +47 42 +59 31 +27 29 +56 20 +22 3 +47 20 +36 17 +59 55 +53 32 +57 46 +43 57 +27 33 +51 23 +2 4 +55 33 +42 36 +11 35 +3 36 +61 57 +55 19 +59 39 +37 29 +53 30 +20 41 +61 11 +21 38 +3 47 +7 53 +4 6 +55 56 +37 31 +29 47 +2 29 +17 60 +22 9 +14 15 +45 48 +43 32 +14 60 +9 9 +8 28 +46 10 +9 51 +60 13 +54 49 +3 27 +16 31 +9 15 +60 25 +10 16 +31 23 +31 12 +7 8 +44 20 +5 50 +28 10 +14 8 +19 23 +58 13 +33 47 +62 35 +10 12 +3 16 +25 60 +41 34 +12 6 +56 40 +18 60 +48 61 +16 50 +47 41 +59 61 +48 12 +18 41 +22 50 +24 18 +21 31 +30 21 +45 52 +17 20 +22 27 +25 14 +3 42 +8 48 +37 23 +34 21 +61 27 +16 43 +38 31 +20 58 +17 41 +12 35 +7 39 +56 51 +27 7 +5 46 +33 29 +57 34 +8 1 +18 44 +21 50 +62 18 +13 12 +61 49 +42 15 +41 56 +54 52 +28 58 +26 18 +43 50 +24 47 +33 55 +12 26 +25 17 +27 40 +59 47 +26 55 +63 37 +4 60 +20 43 +9 60 +36 62 +48 63 +54 8 +17 33 +58 38 +16 25 +27 26 +50 49 +42 11 +26 35 +58 49 +27 55 +20 28 +49 39 +7 57 +35 42 +54 18 +41 44 +25 55 +14 17 +28 29 +41 54 +54 28 +38 31 +36 63 +2 28 +46 26 +19 3 +53 4 +39 60 +61 11 +38 49 +28 14 +29 50 +3 42 +4 28 +6 44 +19 57 +6 56 +24 42 +53 24 +6 33 +49 25 +33 39 +28 9 +33 23 +17 7 +8 44 +18 37 +30 19 +13 31 +46 16 +12 62 +10 15 +54 31 +56 41 +52 60 +9 36 +21 41 +11 46 +47 41 +4 63 +45 11 +43 63 +45 8 +16 56 +38 61 +8 47 +60 15 +62 48 +44 52 +24 30 +48 32 +2 3 +7 10 +47 54 +50 50 +53 32 +60 31 +29 40 +36 44 +32 8 +41 37 +55 35 +50 51 +20 30 +39 41 +59 22 +9 59 +24 13 +5 7 +3 55 +56 54 +23 51 +21 51 +27 54 +29 56 +61 6 +29 50 +39 15 +37 56 +42 11 +33 36 +32 39 +31 53 +51 33 +60 54 +24 50 +42 44 +35 60 +29 59 +50 57 +51 47 +61 15 +34 36 +27 5 +28 4 +15 60 +39 46 +35 4 +34 20 +36 30 +8 58 +14 49 +38 47 +45 4 +42 29 +58 28 +11 55 +40 42 +27 1 +46 52 +4 59 +48 40 +39 17 +43 9 +35 14 +36 42 +8 50 +28 43 +33 7 +44 9 +34 39 +36 44 +28 10 +22 53 +11 2 +41 14 +60 24 +52 36 +38 29 +44 9 +42 17 +51 47 +1 13 +27 31 +17 7 +57 72 +57 20 869 +49 29 585 +39 18 320 +1 24 389 +15 12 208 +51 11 495 +47 5 838 +26 25 661 +29 39 59 +41 13 614 +9 28 247 +17 35 47 +27 16 154 +34 33 445 +50 6 568 +47 56 10 +47 46 620 +34 30 224 +57 18 607 +18 1 759 +29 25 542 +42 41 819 +43 11 729 +5 44 674 +5 52 566 +33 42 254 +14 47 625 +15 24 434 +40 23 732 +6 57 850 +41 28 511 +22 28 937 +21 14 359 +51 18 448 +16 22 594 +27 54 355 +52 26 225 +25 40 746 +27 39 226 +5 44 722 +24 44 552 +26 8 610 +28 44 295 +40 53 112 +55 27 154 +7 53 43 +32 7 790 +46 47 308 +27 32 878 +46 36 754 +23 18 693 +27 43 941 +17 14 316 +5 12 546 +25 9 306 +26 31 511 +40 5 416 +22 10 701 +2 36 95 +21 24 33 +42 46 12 +8 31 895 +54 47 321 +45 10 296 +31 51 621 +44 35 887 +12 17 450 +1 54 885 +37 15 938 +5 35 186 +9 35 350 +45 1 981 +382 +13 33 +45 57 +43 51 +30 36 +24 33 +29 27 +44 5 +51 3 +1 43 +55 15 +13 3 +8 6 +27 1 +3 14 +1 46 +24 13 +22 27 +28 23 +36 1 +17 2 +33 45 +45 35 +49 54 +37 9 +40 35 +39 52 +53 6 +1 38 +6 19 +10 23 +24 33 +51 45 +19 22 +26 54 +38 42 +56 29 +45 43 +6 37 +39 1 +4 37 +51 42 +32 5 +6 48 +1 12 +25 11 +50 48 +2 43 +35 20 +7 3 +17 3 +3 31 +31 48 +32 52 +43 29 +12 46 +9 5 +46 56 +26 52 +46 26 +22 13 +52 14 +20 54 +56 54 +32 22 +16 7 +24 34 +37 55 +24 27 +49 25 +56 3 +29 23 +24 18 +37 8 +28 41 +49 49 +53 44 +5 31 +56 19 +28 30 +40 2 +37 7 +51 32 +4 34 +2 11 +1 16 +30 30 +54 12 +6 33 +35 33 +16 26 +24 27 +28 44 +1 26 +5 44 +56 45 +4 35 +10 54 +9 29 +30 26 +39 47 +41 27 +19 53 +54 24 +28 31 +15 43 +57 38 +13 27 +40 29 +53 44 +15 10 +31 18 +3 40 +14 27 +27 3 +53 9 +49 52 +51 10 +48 48 +49 18 +21 6 +20 36 +2 48 +6 41 +19 17 +43 33 +42 33 +9 44 +31 38 +13 1 +40 24 +9 31 +19 18 +56 25 +8 6 +42 29 +27 20 +23 28 +10 28 +27 28 +3 13 +19 44 +45 27 +30 34 +8 2 +34 47 +25 1 +37 43 +19 51 +10 26 +57 11 +13 26 +30 36 +13 56 +22 39 +26 41 +10 4 +27 13 +30 16 +47 53 +17 23 +2 41 +24 38 +43 42 +31 11 +26 46 +37 55 +15 26 +49 27 +24 13 +24 8 +53 50 +11 39 +5 57 +54 10 +52 29 +33 53 +28 15 +49 13 +15 39 +40 40 +27 19 +53 57 +3 44 +42 26 +57 9 +34 11 +17 3 +49 21 +2 4 +47 13 +32 38 +24 3 +52 32 +31 9 +13 13 +7 55 +48 19 +55 50 +5 39 +19 4 +6 11 +31 22 +13 22 +2 31 +42 48 +43 16 +28 9 +18 38 +40 49 +5 11 +20 27 +9 10 +45 22 +19 50 +19 37 +12 41 +6 42 +5 34 +23 22 +7 7 +12 49 +38 55 +17 15 +35 15 +22 39 +26 41 +9 50 +10 53 +30 28 +45 48 +23 16 +31 28 +57 52 +20 38 +16 27 +3 44 +34 41 +41 9 +55 19 +24 19 +16 8 +18 40 +57 43 +36 45 +13 39 +35 51 +54 25 +37 13 +19 57 +9 50 +26 12 +36 18 +11 36 +27 8 +13 50 +42 28 +16 18 +11 15 +4 5 +18 32 +2 52 +26 56 +35 21 +27 12 +20 35 +21 4 +5 56 +22 15 +50 7 +38 5 +56 38 +49 14 +56 18 +44 18 +22 4 +8 23 +14 49 +37 8 +13 22 +19 48 +57 55 +52 4 +54 32 +35 5 +38 15 +10 52 +53 17 +24 10 +34 26 +43 14 +45 50 +52 17 +42 32 +24 54 +12 2 +3 11 +56 54 +31 11 +44 8 +16 40 +38 41 +34 33 +16 16 +1 49 +41 43 +21 28 +36 15 +45 36 +5 11 +48 17 +28 50 +43 27 +6 32 +53 49 +39 11 +48 36 +10 24 +27 25 +56 28 +32 39 +29 52 +10 23 +26 13 +1 46 +39 7 +5 10 +57 7 +52 5 +38 47 +12 36 +17 2 +14 42 +42 56 +10 40 +26 41 +21 55 +52 46 +36 20 +17 37 +24 56 +43 45 +24 1 +51 18 +5 47 +23 33 +41 55 +34 13 +40 18 +12 8 +16 37 +7 37 +50 1 +41 29 +36 1 +24 3 +15 25 +47 38 +26 56 +14 46 +45 52 +37 29 +50 14 +41 48 +47 52 +55 6 +48 20 +1 56 +37 57 +43 15 +16 9 +33 30 +50 38 +10 18 +52 23 +22 56 +34 2 +43 42 +31 42 +32 36 +37 45 +57 43 +7 16 +42 87 +28 4 196 +13 42 912 +31 35 208 +8 23 968 +26 15 79 +8 32 601 +10 29 126 +23 14 532 +35 29 981 +9 35 421 +34 20 922 +33 31 744 +32 17 926 +39 24 567 +21 7 113 +33 12 986 +34 21 540 +11 41 113 +18 33 291 +34 40 482 +26 29 751 +22 19 497 +15 6 237 +42 3 993 +6 21 665 +26 9 489 +35 40 309 +26 8 436 +31 25 984 +23 14 769 +4 38 829 +5 17 711 +35 29 327 +38 26 235 +22 32 403 +10 15 261 +10 6 763 +29 31 328 +4 19 841 +7 40 632 +10 1 475 +40 3 643 +1 38 231 +11 31 813 +21 10 658 +7 17 174 +1 25 403 +35 9 532 +35 10 24 +15 16 523 +10 25 158 +41 21 382 +1 21 693 +32 29 327 +2 5 628 +3 11 261 +16 11 361 +33 2 941 +38 34 788 +17 6 181 +34 13 594 +7 9 854 +24 10 672 +35 39 374 +33 38 546 +41 38 942 +21 9 822 +23 41 949 +33 36 2 +10 9 173 +42 40 742 +15 2 886 +6 23 601 +13 15 765 +8 6 894 +5 2 997 +12 20 896 +26 42 344 +42 32 226 +6 39 564 +16 38 529 +37 9 334 +27 12 8 +23 25 597 +14 30 130 +41 33 235 +22 42 820 +965 +25 37 +40 23 +24 19 +28 20 +4 41 +13 26 +36 21 +7 20 +33 9 +40 13 +27 11 +42 4 +10 32 +24 29 +32 19 +39 14 +13 36 +34 36 +11 19 +13 12 +16 23 +36 9 +2 40 +26 34 +6 21 +4 30 +32 1 +33 39 +33 12 +25 20 +30 19 +31 40 +10 23 +33 20 +39 1 +30 12 +24 23 +20 23 +18 1 +14 24 +22 15 +11 9 +13 42 +3 1 +11 25 +20 39 +1 7 +34 8 +27 25 +28 23 +23 13 +35 2 +33 10 +24 8 +9 35 +31 28 +5 42 +36 18 +39 36 +18 5 +18 36 +41 16 +42 33 +23 26 +13 6 +4 35 +16 38 +37 6 +4 18 +14 10 +9 42 +37 13 +39 30 +30 35 +21 6 +40 36 +39 38 +7 38 +28 27 +19 40 +33 22 +31 6 +16 23 +10 17 +38 21 +26 4 +20 20 +17 17 +5 4 +7 25 +7 2 +16 3 +40 22 +38 23 +6 14 +19 36 +34 5 +42 5 +27 7 +21 22 +27 2 +26 4 +19 42 +18 23 +1 25 +3 8 +24 18 +10 21 +37 6 +42 42 +17 16 +36 6 +20 33 +10 2 +39 28 +23 21 +29 4 +24 5 +1 40 +25 2 +20 25 +9 1 +40 16 +20 34 +19 17 +32 34 +32 25 +39 7 +13 5 +8 9 +32 28 +29 19 +30 8 +21 30 +3 2 +31 22 +26 37 +21 24 +9 40 +13 27 +14 2 +16 1 +24 13 +5 36 +17 10 +42 4 +35 26 +22 22 +34 41 +10 36 +42 38 +14 23 +33 34 +2 41 +29 13 +23 40 +14 39 +40 38 +7 2 +29 21 +9 29 +24 1 +12 2 +23 1 +40 30 +35 37 +25 6 +17 15 +37 17 +11 23 +29 32 +20 40 +26 15 +35 32 +14 20 +10 22 +6 31 +22 17 +32 42 +16 27 +29 8 +21 12 +13 38 +24 7 +10 33 +27 38 +22 4 +35 5 +16 26 +34 29 +3 41 +6 6 +29 27 +20 17 +25 35 +1 11 +42 22 +22 10 +15 2 +14 24 +34 40 +17 13 +41 7 +15 14 +30 6 +40 30 +4 3 +35 32 +28 11 +4 10 +3 5 +20 1 +24 40 +10 36 +41 24 +17 32 +21 31 +42 18 +37 14 +31 25 +19 27 +12 22 +29 3 +9 12 +13 13 +21 15 +15 39 +15 38 +36 23 +29 34 +4 1 +21 22 +31 20 +39 23 +33 26 +5 7 +10 15 +28 36 +15 34 +6 27 +4 26 +39 16 +22 10 +9 13 +32 37 +2 33 +37 22 +12 25 +39 9 +4 27 +32 6 +33 41 +20 16 +32 34 +8 37 +16 9 +19 13 +23 38 +22 31 +9 9 +26 8 +41 18 +30 10 +41 24 +16 2 +7 5 +7 39 +1 25 +11 33 +14 16 +25 30 +22 1 +42 2 +39 19 +33 3 +27 14 +8 25 +31 35 +34 27 +17 6 +28 23 +10 33 +17 9 +15 27 +41 28 +40 23 +15 20 +22 12 +21 16 +30 9 +16 12 +22 23 +36 9 +16 26 +35 32 +31 19 +10 38 +9 26 +2 21 +9 42 +6 6 +21 19 +25 42 +28 2 +13 14 +10 28 +25 30 +8 17 +36 23 +42 26 +10 28 +2 19 +21 8 +1 23 +28 9 +20 32 +12 40 +8 35 +37 35 +36 7 +6 1 +34 29 +30 40 +3 23 +20 2 +5 28 +27 6 +4 3 +12 2 +25 39 +10 1 +28 22 +38 33 +14 33 +26 5 +37 29 +5 27 +15 35 +24 17 +13 41 +16 15 +26 40 +21 28 +41 32 +29 21 +26 39 +21 10 +16 17 +42 27 +5 25 +31 41 +10 33 +25 22 +23 6 +37 34 +5 8 +6 30 +4 26 +13 2 +13 42 +22 37 +36 1 +4 9 +17 3 +33 21 +26 19 +17 33 +9 42 +12 32 +3 6 +23 7 +12 28 +35 15 +10 5 +16 20 +2 37 +14 37 +35 15 +3 7 +18 33 +25 41 +9 42 +31 18 +41 40 +7 41 +2 29 +6 13 +12 38 +27 21 +40 40 +39 42 +32 10 +36 25 +23 37 +31 40 +27 14 +36 36 +11 22 +11 7 +19 15 +5 20 +41 8 +30 10 +3 14 +29 41 +9 25 +40 41 +32 31 +23 12 +25 9 +7 8 +20 42 +41 30 +21 7 +36 38 +21 41 +15 17 +6 1 +26 7 +12 10 +5 21 +34 42 +19 22 +30 39 +33 11 +5 40 +18 23 +37 16 +10 14 +20 2 +9 40 +40 21 +12 1 +21 37 +7 33 +3 9 +11 34 +8 27 +13 36 +23 4 +4 25 +41 19 +5 35 +32 13 +4 9 +14 12 +4 11 +33 15 +11 9 +7 16 +41 9 +24 7 +41 30 +33 11 +23 11 +12 24 +36 8 +40 38 +41 29 +8 2 +35 19 +14 38 +27 2 +8 38 +10 14 +9 9 +21 30 +15 19 +15 4 +27 35 +14 39 +16 5 +2 13 +1 42 +39 6 +2 31 +25 13 +24 9 +14 31 +2 23 +3 8 +29 21 +38 42 +39 8 +3 23 +1 16 +17 14 +21 19 +27 21 +16 21 +24 17 +10 4 +27 31 +11 40 +20 12 +19 20 +18 3 +40 11 +2 34 +18 4 +14 18 +20 29 +32 40 +3 14 +16 18 +34 37 +33 41 +41 17 +28 9 +13 5 +18 29 +24 35 +31 19 +3 33 +10 19 +36 23 +36 11 +7 23 +6 9 +34 19 +25 24 +14 15 +22 12 +29 7 +20 39 +9 35 +25 30 +28 14 +6 28 +2 15 +4 37 +36 38 +4 40 +16 9 +7 8 +28 29 +31 41 +1 8 +8 27 +13 25 +24 21 +17 4 +9 42 +17 12 +28 16 +25 29 +11 18 +22 12 +15 38 +20 19 +3 3 +5 33 +1 3 +40 6 +28 10 +30 9 +29 5 +12 35 +2 27 +4 29 +42 28 +14 8 +1 35 +19 14 +28 37 +32 30 +39 35 +18 38 +35 14 +1 20 +21 31 +28 7 +33 38 +41 34 +20 1 +19 17 +26 32 +25 27 +22 41 +40 8 +35 27 +35 30 +17 11 +25 10 +24 25 +29 2 +11 13 +7 1 +6 3 +33 25 +1 9 +41 27 +38 21 +9 15 +20 4 +22 10 +28 13 +39 3 +21 19 +12 2 +42 38 +1 10 +8 5 +11 13 +6 1 +35 6 +7 34 +32 2 +10 38 +16 27 +41 36 +37 27 +4 31 +29 24 +6 38 +23 5 +33 21 +14 39 +26 22 +7 31 +20 42 +34 26 +31 24 +25 40 +17 39 +25 16 +30 17 +42 33 +3 26 +12 8 +19 34 +12 9 +10 24 +3 35 +3 10 +21 21 +9 13 +4 39 +34 27 +34 8 +21 16 +21 8 +30 18 +38 33 +41 5 +40 17 +38 8 +24 5 +31 26 +38 31 +33 14 +9 41 +24 11 +35 13 +37 27 +19 13 +40 39 +18 28 +13 13 +16 11 +15 13 +28 10 +18 9 +12 4 +32 5 +35 23 +19 1 +19 40 +9 12 +11 1 +36 29 +13 31 +23 30 +14 35 +40 29 +4 12 +40 31 +19 15 +37 29 +19 24 +33 9 +4 7 +7 21 +5 16 +32 13 +16 23 +41 27 +11 21 +14 25 +12 10 +11 15 +21 6 +1 38 +21 35 +24 37 +16 12 +3 18 +19 9 +36 21 +24 25 +33 38 +3 29 +22 11 +5 33 +33 16 +42 42 +28 19 +5 26 +14 25 +18 35 +19 32 +4 19 +5 20 +28 40 +38 9 +20 26 +4 20 +12 23 +30 15 +14 21 +30 13 +18 14 +29 22 +39 42 +3 13 +32 19 +2 34 +38 4 +11 23 +1 5 +29 18 +30 31 +37 40 +11 24 +12 22 +42 39 +35 17 +10 21 +39 5 +19 39 +17 6 +15 16 +39 10 +19 6 +30 19 +10 17 +36 37 +5 30 +34 13 +9 3 +35 9 +42 25 +23 7 +1 17 +11 17 +13 25 +23 28 +40 17 +35 16 +22 23 +32 29 +39 23 +24 41 +8 13 +9 17 +16 1 +23 13 +23 3 +17 24 +20 26 +38 30 +8 18 +15 6 +35 8 +21 12 +30 11 +39 24 +31 20 +22 39 +32 28 +13 3 +27 35 +13 7 +35 28 +28 10 +11 24 +40 16 +39 10 +21 29 +17 40 +41 2 +6 37 +25 36 +12 2 +32 41 +28 2 +42 12 +34 10 +18 25 +37 2 +32 3 +23 29 +19 19 +37 39 +6 11 +34 2 +11 39 +36 33 +33 3 +33 20 +41 18 +20 40 +29 9 +6 2 +33 40 +1 23 +1 23 +7 19 +42 1 +13 3 +10 3 +2 18 +41 35 +8 29 +35 38 +7 33 +11 24 +29 37 +32 34 +39 21 +29 37 +41 29 +18 5 +3 15 +4 14 +17 11 +16 16 +28 12 +8 33 +41 42 +29 3 +30 39 +26 16 +34 13 +5 28 +33 34 +22 31 +18 37 +36 21 +9 37 +32 25 +5 5 +38 30 +16 3 +20 12 +42 4 +12 30 +1 35 +1 32 +6 6 +15 38 +37 36 +25 12 +29 16 +32 37 +10 21 +18 12 +23 13 +41 37 +14 16 +4 13 +20 16 +40 18 +6 39 +7 11 +2 21 +5 36 +12 29 +5 40 +2 35 +35 9 +11 8 +20 34 +20 16 +26 31 +31 29 +42 8 +2 39 +25 8 +35 31 +16 34 +7 18 +27 17 +4 30 +12 3 +22 2 +11 32 +9 28 +21 29 +1 4 +17 32 +33 16 +39 32 +11 20 +37 1 +6 9 +33 13 +26 15 +27 30 +2 38 +30 21 +40 39 +11 6 +24 29 +32 23 +33 5 +12 23 +20 6 +10 28 +25 5 +27 29 +13 17 +41 38 +31 23 +23 31 +18 9 +9 15 +5 17 +21 26 +4 10 +6 34 +14 17 +12 32 +21 21 +15 1 +23 41 +29 33 +15 25 +27 2 +5 7 +32 23 +13 38 +35 17 +13 13 +1 14 +21 6 +3 32 +21 14 +19 39 +34 34 +39 13 +32 24 +3 3 +6 29 +2 9 +34 33 +29 4 +26 21 +21 36 +34 19 +5 10 +22 7 +41 42 +20 16 +38 10 +46 51 +20 40 862 +32 46 33 +3 4 169 +26 29 73 +39 5 334 +27 10 77 +31 11 934 +21 25 802 +24 35 487 +22 46 383 +44 19 935 +7 44 18 +31 40 239 +30 19 763 +28 12 279 +13 32 679 +37 17 401 +10 37 487 +6 8 781 +30 29 868 +43 20 820 +43 26 876 +42 5 625 +38 28 866 +17 9 677 +39 22 414 +25 6 436 +15 16 236 +24 15 732 +20 38 942 +16 34 66 +17 24 963 +22 20 723 +15 11 810 +26 21 649 +2 14 924 +3 32 359 +15 1 240 +16 18 720 +25 37 638 +11 46 727 +10 11 923 +40 32 594 +17 40 626 +26 19 839 +38 20 158 +25 17 613 +18 25 605 +19 40 972 +35 13 847 +2 17 744 +972 +26 42 +2 13 +28 33 +29 21 +23 3 +34 33 +40 7 +44 19 +17 40 +30 41 +31 2 +29 38 +36 41 +30 31 +5 16 +15 30 +11 16 +36 32 +3 19 +1 19 +15 34 +45 8 +34 42 +20 45 +29 3 +33 13 +5 15 +45 34 +3 22 +19 7 +31 33 +30 36 +42 20 +15 38 +32 15 +10 46 +42 8 +1 24 +43 21 +16 20 +23 2 +32 21 +17 24 +9 13 +40 21 +20 24 +1 43 +7 36 +16 22 +28 41 +30 31 +34 20 +33 35 +43 29 +9 12 +2 25 +7 28 +40 23 +45 2 +36 38 +16 3 +10 10 +45 16 +45 9 +37 26 +43 21 +11 31 +40 43 +13 30 +19 15 +35 15 +39 41 +36 26 +12 34 +27 41 +26 36 +37 35 +45 35 +4 44 +37 35 +23 34 +3 27 +12 36 +17 24 +19 36 +38 1 +44 24 +41 33 +4 46 +20 24 +40 39 +14 24 +21 6 +13 19 +3 43 +7 20 +24 3 +40 35 +38 11 +12 4 +40 43 +4 37 +15 38 +17 12 +32 30 +29 19 +23 36 +43 43 +42 3 +9 38 +45 9 +11 23 +11 45 +11 2 +9 17 +5 42 +7 2 +32 15 +34 2 +26 19 +31 3 +31 1 +38 27 +38 33 +29 46 +19 28 +9 23 +44 19 +21 8 +15 29 +18 13 +18 19 +9 3 +33 36 +44 7 +2 23 +9 32 +17 46 +13 8 +27 41 +2 39 +16 4 +15 13 +16 36 +15 24 +12 26 +37 30 +44 39 +26 31 +28 18 +37 29 +40 39 +14 4 +32 26 +6 12 +15 7 +4 30 +4 13 +37 19 +2 45 +37 7 +24 27 +36 22 +19 10 +6 46 +27 36 +28 14 +22 35 +17 7 +15 22 +13 23 +22 10 +46 19 +22 36 +32 17 +34 22 +24 12 +42 7 +27 14 +16 26 +7 42 +15 28 +3 30 +16 20 +36 24 +35 42 +46 5 +6 46 +17 21 +35 2 +38 17 +23 9 +22 18 +15 2 +25 31 +27 25 +20 35 +6 23 +18 22 +36 1 +39 18 +43 39 +16 42 +38 33 +16 20 +34 1 +30 5 +9 5 +16 24 +6 35 +2 32 +13 15 +14 19 +31 31 +34 20 +32 26 +32 22 +12 1 +17 43 +33 32 +11 15 +33 40 +13 35 +39 28 +12 38 +16 7 +24 23 +22 31 +41 6 +16 22 +20 41 +41 5 +16 7 +45 32 +43 26 +11 7 +34 37 +41 46 +26 33 +21 31 +24 31 +38 41 +7 7 +26 41 +6 35 +16 25 +29 4 +23 38 +10 22 +23 1 +41 27 +7 28 +18 1 +27 37 +27 41 +15 5 +25 6 +39 25 +6 18 +19 12 +6 28 +30 28 +32 7 +19 35 +22 35 +35 16 +16 42 +37 27 +36 17 +11 17 +5 25 +15 30 +25 7 +8 30 +19 27 +35 18 +2 19 +46 33 +19 12 +22 40 +1 4 +3 10 +39 39 +30 29 +3 40 +39 7 +18 7 +30 36 +7 38 +14 25 +12 2 +43 7 +14 36 +40 32 +1 9 +19 1 +12 15 +4 5 +1 33 +27 43 +26 19 +4 38 +19 27 +21 25 +18 34 +4 23 +30 40 +30 43 +29 17 +23 29 +19 35 +24 30 +44 21 +28 44 +8 2 +41 27 +20 38 +12 32 +18 33 +11 30 +20 8 +46 43 +1 23 +34 29 +33 10 +5 5 +38 22 +29 35 +43 10 +27 4 +12 15 +24 25 +6 36 +11 17 +22 21 +46 35 +22 40 +32 22 +16 13 +44 3 +22 42 +7 7 +18 29 +36 8 +39 10 +5 44 +24 28 +22 23 +11 26 +39 32 +40 33 +15 15 +26 40 +36 35 +6 27 +31 21 +23 32 +21 34 +14 10 +41 6 +19 45 +43 42 +20 19 +12 31 +38 5 +10 32 +37 24 +46 10 +11 30 +38 16 +10 23 +30 26 +8 5 +13 21 +14 7 +21 27 +45 17 +16 13 +29 28 +43 21 +32 6 +6 16 +24 45 +19 34 +28 10 +44 38 +32 27 +17 33 +31 30 +2 39 +30 22 +19 23 +32 34 +35 9 +9 25 +23 34 +24 28 +43 1 +20 15 +29 2 +19 26 +39 4 +46 3 +31 25 +26 32 +17 4 +7 29 +26 32 +10 8 +40 19 +32 16 +6 9 +37 3 +4 11 +17 32 +12 29 +5 44 +27 44 +46 11 +22 20 +42 32 +23 42 +14 2 +21 24 +3 15 +42 34 +24 41 +36 15 +43 39 +19 8 +18 24 +36 16 +21 16 +14 14 +20 29 +33 15 +15 9 +4 28 +4 25 +45 6 +39 40 +39 10 +35 23 +24 25 +15 36 +32 27 +13 16 +42 27 +25 3 +41 45 +32 21 +7 46 +30 11 +21 27 +35 20 +33 21 +7 19 +30 35 +41 2 +14 4 +37 39 +24 44 +2 13 +24 27 +16 12 +25 1 +33 31 +40 10 +35 14 +36 23 +27 16 +37 34 +35 15 +22 23 +16 35 +20 46 +22 37 +43 23 +4 15 +3 19 +26 21 +13 12 +6 6 +21 40 +13 5 +11 40 +20 1 +27 2 +9 2 +19 24 +31 32 +18 6 +23 8 +28 26 +22 31 +38 2 +45 4 +7 4 +9 22 +38 21 +26 42 +8 45 +36 34 +41 45 +30 13 +16 14 +44 33 +19 20 +35 40 +39 10 +18 30 +5 17 +33 6 +14 35 +27 5 +4 6 +40 11 +44 30 +39 32 +28 22 +44 43 +35 36 +24 1 +9 12 +34 42 +15 6 +25 14 +16 6 +19 29 +40 45 +28 37 +44 21 +42 35 +44 34 +21 25 +9 12 +16 37 +1 39 +31 4 +44 18 +45 12 +17 17 +19 26 +22 37 +3 10 +29 30 +46 20 +44 41 +9 42 +28 23 +20 30 +28 29 +20 29 +15 44 +26 12 +10 18 +18 20 +34 36 +46 10 +27 2 +19 3 +25 18 +23 22 +7 25 +11 34 +41 25 +12 22 +7 31 +44 22 +23 17 +33 32 +34 44 +45 22 +34 38 +31 8 +39 43 +10 11 +14 26 +33 14 +44 43 +2 38 +15 13 +8 22 +37 5 +43 7 +16 23 +32 3 +15 31 +24 2 +22 2 +3 9 +44 6 +19 6 +32 45 +19 29 +36 20 +15 4 +26 22 +25 11 +20 15 +17 35 +32 3 +38 46 +33 9 +41 2 +11 37 +10 8 +42 29 +13 21 +21 32 +44 10 +45 12 +14 19 +33 32 +29 46 +1 45 +29 26 +1 20 +19 27 +22 13 +29 32 +3 32 +34 38 +8 46 +13 29 +25 10 +38 24 +21 45 +36 1 +31 18 +40 25 +16 22 +4 11 +35 22 +31 11 +28 7 +42 24 +33 23 +15 40 +23 27 +22 41 +36 8 +12 4 +6 1 +44 30 +18 38 +2 28 +13 5 +32 2 +20 16 +12 41 +17 1 +18 3 +24 27 +42 40 +7 12 +34 37 +13 40 +34 12 +40 32 +42 12 +23 43 +33 35 +42 18 +30 9 +27 35 +44 43 +36 9 +39 7 +35 29 +46 36 +40 27 +20 6 +20 7 +17 8 +32 6 +13 2 +43 45 +31 32 +10 14 +40 36 +3 37 +27 32 +40 13 +38 28 +41 31 +17 34 +5 30 +33 25 +37 44 +26 16 +3 38 +18 45 +36 2 +30 45 +15 18 +28 11 +2 2 +42 41 +15 27 +17 9 +11 27 +37 16 +11 23 +34 41 +14 13 +10 17 +44 27 +9 33 +28 33 +25 37 +44 6 +1 39 +8 43 +28 16 +23 44 +24 28 +24 8 +37 34 +25 18 +28 38 +24 32 +2 21 +12 11 +7 34 +37 25 +24 28 +30 18 +20 31 +8 1 +46 31 +38 18 +6 16 +25 42 +43 3 +7 19 +35 30 +4 36 +4 9 +40 4 +42 30 +28 13 +5 5 +31 19 +30 32 +19 29 +16 11 +40 15 +20 13 +4 16 +9 10 +34 43 +39 31 +33 36 +40 26 +39 29 +4 14 +36 8 +19 20 +20 2 +45 39 +24 15 +43 12 +23 16 +24 27 +25 26 +36 13 +23 23 +37 9 +12 30 +28 45 +13 31 +6 2 +33 18 +15 6 +19 13 +38 37 +21 28 +42 44 +43 13 +18 16 +38 7 +22 14 +29 12 +16 41 +42 38 +33 2 +16 38 +43 2 +10 5 +2 22 +11 33 +6 32 +15 1 +23 5 +13 40 +14 45 +40 35 +6 23 +1 22 +11 42 +13 37 +37 28 +28 33 +24 31 +31 19 +7 41 +45 6 +20 7 +7 42 +6 13 +29 19 +5 17 +8 11 +39 8 +26 43 +43 32 +27 27 +7 8 +7 30 +33 37 +42 39 +31 35 +44 5 +41 44 +40 46 +5 17 +13 9 +33 20 +13 19 +21 38 +15 17 +23 41 +43 30 +42 43 +7 28 +33 43 +14 17 +31 6 +15 19 +3 3 +19 1 +19 31 +4 5 +44 16 +23 18 +8 31 +28 24 +19 18 +7 14 +14 8 +36 46 +4 3 +10 34 +8 25 +46 5 +27 12 +45 39 +36 2 +43 33 +18 13 +4 19 +43 31 +42 15 +2 3 +22 9 +4 11 +8 7 +8 18 +34 15 +36 33 +13 10 +45 12 +2 34 +13 44 +15 24 +10 12 +42 46 +43 38 +14 38 +34 35 +1 37 +40 2 +37 1 +19 24 +9 2 +4 22 +11 42 +27 12 +30 39 +3 38 +11 6 +3 6 +5 39 +37 12 +31 18 +41 25 +8 34 +20 38 +28 33 +15 36 +34 13 +5 39 +8 31 +44 31 +18 1 +22 28 +46 25 +27 45 +17 18 +4 41 +35 44 +13 37 +25 33 +28 6 +19 37 +36 6 +3 40 +38 10 +19 36 +41 36 +30 16 +17 23 +40 43 +21 5 +8 25 +45 43 +16 12 +27 41 +44 8 +40 10 +44 29 +9 46 +17 1 +4 35 +36 44 +24 19 +7 34 +41 41 +24 10 +45 32 +28 37 +22 43 +2 2 +37 39 +9 25 +2 1 +7 11 +40 23 +5 43 +5 40 +34 28 +6 35 +9 40 +29 33 +43 21 +18 24 +11 33 +21 7 +34 5 +39 36 +29 35 +30 36 +39 24 +6 43 +20 11 +36 2 +32 35 +36 41 +22 18 +27 19 +32 38 +39 34 +38 36 136 +36 23 589 +32 16 615 +23 4 687 +8 37 293 +37 35 542 +36 31 726 +10 23 201 +21 3 715 +1 16 105 +11 3 712 +38 39 54 +31 32 439 +36 3 426 +26 10 529 +28 35 178 +36 21 253 +38 30 65 +5 12 762 +37 1 941 +37 11 178 +34 10 864 +13 29 942 +25 15 719 +2 29 472 +14 18 401 +11 3 424 +38 2 496 +37 34 971 +39 20 92 +7 18 295 +16 12 365 +23 13 890 +11 38 539 +257 +28 2 +16 30 +8 27 +1 11 +19 27 +12 1 +14 34 +23 13 +14 34 +19 31 +5 34 +31 25 +7 33 +23 6 +31 35 +33 8 +25 37 +37 33 +24 27 +4 3 +3 4 +32 16 +37 4 +29 39 +26 36 +20 30 +20 11 +4 26 +4 26 +20 23 +10 13 +30 24 +11 17 +17 23 +4 9 +15 34 +1 7 +11 26 +10 28 +25 24 +24 5 +14 32 +16 18 +7 8 +32 26 +20 31 +39 10 +15 38 +15 20 +10 7 +28 24 +2 17 +19 12 +3 17 +39 27 +1 12 +32 15 +33 36 +21 39 +32 2 +26 12 +21 25 +11 35 +12 25 +4 21 +32 31 +34 33 +36 13 +33 38 +30 21 +26 19 +21 7 +33 14 +3 3 +14 34 +33 39 +35 14 +13 6 +10 13 +30 2 +22 11 +33 16 +32 18 +18 25 +17 36 +34 3 +15 16 +9 37 +18 39 +28 31 +22 21 +19 17 +35 20 +22 33 +32 2 +34 15 +12 16 +19 5 +34 36 +18 11 +32 13 +2 36 +17 38 +33 34 +26 21 +15 8 +3 33 +14 26 +14 24 +19 34 +25 2 +9 37 +18 28 +30 1 +13 36 +11 34 +9 1 +30 14 +38 12 +37 24 +32 12 +20 23 +33 33 +9 35 +18 16 +30 31 +7 27 +17 24 +15 7 +13 17 +4 12 +11 1 +12 29 +4 38 +1 1 +22 32 +12 30 +5 5 +13 2 +29 19 +7 19 +10 13 +6 27 +25 10 +22 37 +26 14 +9 25 +15 9 +14 18 +7 14 +7 17 +34 18 +7 38 +11 8 +1 39 +26 35 +18 25 +8 13 +12 21 +22 22 +18 36 +36 15 +21 39 +23 34 +6 29 +8 12 +6 2 +18 1 +29 28 +9 18 +17 34 +13 23 +19 20 +35 19 +29 6 +30 7 +2 26 +10 22 +14 32 +16 8 +10 12 +8 15 +14 25 +15 31 +2 23 +9 18 +7 21 +30 14 +29 25 +33 18 +31 12 +13 32 +26 22 +4 39 +14 8 +35 23 +20 3 +26 22 +16 29 +13 17 +2 21 +24 8 +30 3 +10 19 +27 31 +25 7 +3 37 +39 28 +19 31 +16 21 +38 11 +32 18 +13 7 +28 17 +35 29 +23 25 +10 35 +32 28 +37 31 +7 24 +22 31 +31 25 +17 19 +2 24 +38 18 +33 36 +28 25 +4 30 +20 31 +7 5 +21 18 +29 19 +13 11 +8 10 +2 3 +23 12 +23 3 +36 39 +21 27 +24 19 +5 17 +4 21 +31 7 +11 11 +27 7 +4 36 +24 33 +15 37 +4 11 +35 33 +14 18 +5 36 +20 30 +24 1 +17 8 +8 21 +14 12 +62 58 +8 54 609 +29 16 136 +10 45 858 +59 11 904 +4 23 224 +26 10 386 +19 47 290 +24 19 629 +45 14 53 +23 38 866 +14 45 291 +9 10 790 +62 17 186 +45 13 817 +30 15 433 +13 38 762 +26 55 798 +52 16 33 +30 58 842 +37 19 309 +58 30 541 +6 38 566 +31 37 745 +38 17 933 +56 46 273 +32 58 887 +18 20 33 +49 9 510 +35 38 865 +32 10 201 +6 3 827 +21 8 54 +44 38 19 +20 12 577 +9 5 985 +7 35 168 +45 52 161 +11 36 605 +52 7 129 +27 38 784 +17 42 789 +35 62 784 +29 41 560 +57 61 301 +39 5 175 +3 11 615 +23 54 734 +1 62 34 +48 52 842 +4 14 351 +33 28 222 +1 2 347 +37 27 292 +48 21 448 +8 57 804 +32 58 928 +29 18 411 +12 16 989 +69 +61 4 +54 2 +15 55 +33 42 +32 31 +40 7 +5 4 +22 52 +22 33 +59 15 +48 27 +10 11 +53 25 +26 62 +40 40 +29 37 +41 20 +38 53 +12 6 +30 42 +37 8 +48 41 +9 7 +29 29 +37 23 +43 22 +49 52 +30 37 +12 53 +37 51 +28 3 +23 4 +22 61 +56 32 +2 24 +9 38 +29 56 +15 35 +60 43 +1 34 +1 43 +53 48 +30 20 +22 41 +11 56 +28 38 +58 50 +42 16 +46 33 +45 48 +54 51 +21 18 +44 33 +53 39 +11 53 +8 12 +32 60 +59 59 +17 18 +38 25 +10 1 +61 3 +48 38 +18 30 +8 60 +13 60 +48 33 +15 27 +2 5 diff --git a/spoj/KAUSANDNIHA output file #1 b/spoj/KAUSANDNIHA output file #1 new file mode 100644 index 0000000..b2ccb62 --- /dev/null +++ b/spoj/KAUSANDNIHA output file #1 @@ -0,0 +1,4412 @@ +2042 +-1 +2115 +-1 +-1 +1807 +2111 +1272 +1569 +2074 +1496 +-1 +-1 +-1 +2317 +3814 +1826 +1330 +2550 +2653 +-1 +1569 +-1 +1683 +1315 +-1 +1381 +3409 +-1 +3277 +1359 +2719 +1544 +-1 +2911 +1225 +-1 +1666 +-1 +3706 +-1 +-1 +1219 +2009 +1305 +-1 +2609 +3106 +1346 +-1 +2373 +2077 +1347 +2085 +-1 +-1 +0 +1765 +2799 +2349 +1437 +-1 +-1 +-1 +-1 +2070 +2726 +2458 +2354 +1482 +0 +2939 +0 +-1 +0 +-1 +1868 +2518 +-1 +2156 +-1 +0 +2985 +-1 +-1 +2840 +2302 +1233 +-1 +2107 +-1 +-1 +2659 +2261 +2277 +-1 +199 +2920 +1296 +-1 +1492 +765 +1920 +794 +990 +2003 +-1 +-1 +1497 +1648 +0 +2894 +2076 +3329 +1582 +-1 +940 +-1 +2787 +-1 +-1 +1217 +-1 +1420 +3247 +-1 +2115 +-1 +1699 +-1 +-1 +1246 +-1 +2929 +2456 +2924 +983 +1584 +2628 +-1 +2509 +1497 +1721 +-1 +0 +-1 +2171 +3433 +2910 +2728 +2624 +-1 +1509 +2509 +2561 +-1 +3183 +-1 +2033 +-1 +1690 +1793 +-1 +2150 +2099 +2401 +2410 +1514 +-1 +-1 +-1 +1509 +-1 +-1 +1542 +-1 +-1 +-1 +1784 +1148 +1270 +1431 +2645 +-1 +2641 +2322 +1931 +-1 +-1 +-1 +-1 +-1 +1615 +1461 +-1 +2467 +-1 +-1 +3177 +-1 +1994 +3190 +-1 +2002 +1307 +-1 +-1 +0 +-1 +-1 +1593 +229 +-1 +-1 +-1 +1796 +-1 +-1 +-1 +2281 +-1 +730 +-1 +3591 +1933 +-1 +2875 +3114 +2898 +2860 +379 +1488 +2710 +1263 +-1 +-1 +-1 +-1 +2728 +1988 +3309 +3122 +-1 +1142 +2308 +2062 +1868 +-1 +2878 +-1 +3206 +-1 +-1 +2344 +3175 +879 +800 +2025 +2382 +-1 +1617 +-1 +-1 +544 +-1 +2133 +-1 +1116 +3016 +-1 +2334 +842 +-1 +2405 +2022 +1348 +1786 +3581 +-1 +-1 +-1 +1633 +3405 +3007 +-1 +2065 +-1 +-1 +3737 +-1 +1084 +-1 +1277 +2853 +1814 +2458 +2050 +2284 +-1 +-1 +2264 +2457 +-1 +-1 +1186 +1547 +2498 +2184 +1051 +2301 +-1 +874 +812 +1076 +-1 +-1 +2907 +-1 +2285 +-1 +1908 +1407 +2458 +3255 +-1 +1022 +493 +-1 +1804 +-1 +-1 +0 +1238 +-1 +1030 +-1 +3255 +-1 +2205 +-1 +-1 +-1 +1221 +-1 +-1 +-1 +-1 +1484 +-1 +-1 +2720 +2039 +-1 +690 +2050 +-1 +2112 +-1 +-1 +-1 +2944 +-1 +929 +2050 +3138 +-1 +2689 +1743 +-1 +-1 +-1 +-1 +2002 +-1 +2803 +2207 +1889 +2741 +-1 +-1 +-1 +2171 +-1 +2380 +-1 +1569 +-1 +899 +-1 +307 +-1 +3246 +3305 +-1 +2429 +1631 +1786 +3626 +-1 +1459 +2287 +-1 +-1 +0 +2161 +3058 +2255 +1367 +2007 +1392 +-1 +1740 +-1 +-1 +-1 +3219 +-1 +827 +3 +1151 +-1 +2363 +2208 +946 +1157 +2208 +1289 +722 +1900 +1094 +1313 +2250 +2465 +944 +-1 +1921 +821 +1747 +1100 +379 +1490 +1336 +1003 +1338 +1057 +253 +893 +1311 +2385 +1921 +672 +1196 +1737 +157 +1711 +1663 +405 +1333 +1453 +1744 +2041 +1061 +1178 +845 +1340 +1190 +933 +822 +744 +562 +-1 +1124 +2379 +1653 +1541 +1747 +-1 +2401 +-1 +-1 +997 +1450 +677 +712 +2077 +1101 +898 +3157 +600 +1390 +1487 +2319 +64 +670 +1491 +1694 +1581 +1397 +-1 +1803 +1945 +883 +2239 +2311 +-1 +1304 +1092 +455 +1058 +1423 +-1 +-1 +2815 +1054 +1583 +1321 +2752 +508 +795 +1351 +883 +1055 +-1 +0 +2144 +1526 +1465 +907 +1259 +0 +652 +1746 +-1 +1322 +0 +1328 +2233 +-1 +2036 +777 +980 +868 +609 +1693 +2196 +1607 +-1 +1548 +1193 +1584 +1450 +1166 +920 +1675 +1267 +1570 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +465 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +741 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +0 +-1 +-1 +-1 +524 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +0 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +0 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +535 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +0 +-1 +-1 +-1 +-1 +978 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +502 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +0 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +0 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +0 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +568 +-1 +-1 +-1 +535 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +328 +-1 +-1 +-1 +-1 +3324 +-1 +-1 +167 +-1 +-1 +-1 +0 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +1884 +-1 +0 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +529 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +167 +-1 +-1 +529 +-1 +-1 +-1 +-1 +-1 +2549 +-1 +-1 +-1 +-1 +-1 +970 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +0 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +2987 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +20 +-1 +-1 +0 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +970 +1628 +-1 +1721 +-1 +2646 +2997 +186 +1844 +1690 +3504 +1671 +992 +1917 +1820 +1357 +1782 +2041 +0 +2353 +1363 +1480 +-1 +3361 +2675 +1425 +2540 +-1 +1413 +1621 +2771 +0 +2495 +1146 +3211 +1469 +2540 +2465 +1914 +2345 +-1 +1293 +787 +4056 +2287 +3420 +831 +0 +1876 +-1 +1626 +2459 +1017 +2548 +0 +2759 +948 +2151 +1491 +1769 +1920 +1361 +1438 +-1 +-1 +3192 +-1 +3055 +493 +2860 +1680 +-1 +1986 +-1 +1483 +1134 +3303 +-1 +-1 +1611 +2323 +2411 +-1 +2597 +2223 +-1 +1263 +1384 +1871 +2105 +2273 +3000 +-1 +868 +1682 +-1 +2855 +856 +1865 +3244 +3350 +2147 +2597 +2562 +1593 +1820 +2681 +-1 +1646 +1909 +1844 +2429 +-1 +621 +2246 +-1 +2180 +955 +3120 +1551 +1007 +2602 +1708 +2334 +1128 +-1 +1856 +-1 +969 +60 +3164 +1642 +1630 +1837 +1970 +3024 +1713 +2677 +2074 +513 +-1 +-1 +999 +2057 +-1 +1394 +1332 +2278 +-1 +1938 +2619 +0 +1194 +1445 +923 +1578 +2157 +2229 +309 +493 +1756 +766 +916 +1365 +770 +1545 +2912 +2147 +2300 +1628 +4225 +2283 +2986 +1280 +1130 +1756 +2562 +879 +-1 +1154 +-1 +1956 +2642 +2454 +-1 +1114 +2572 +1360 +1476 +3191 +2656 +1293 +2767 +2833 +-1 +-1 +1915 +2753 +2121 +1651 +1201 +3674 +3662 +2171 +425 +-1 +2418 +464 +522 +2626 +-1 +1814 +1581 +2025 +2647 +1862 +-1 +-1 +2423 +4419 +2191 +1871 +1493 +1856 +1094 +2873 +2465 +1978 +875 +2047 +-1 +102 +152 +2597 +-1 +1844 +3303 +3604 +1082 +1679 +2915 +-1 +1077 +4056 +2338 +1716 +2438 +2362 +-1 +1484 +2041 +1377 +4013 +852 +370 +1807 +1201 +2547 +-1 +1259 +1757 +-1 +708 +1713 +2528 +3183 +2771 +-1 +-1 +734 +1864 +-1 +-1 +1870 +1622 +2100 +1935 +983 +1842 +2527 +297 +2495 +2704 +1496 +1663 +2676 +1099 +1180 +-1 +1412 +1878 +2761 +1367 +2642 +-1 +2338 +2901 +2418 +-1 +1217 +737 +341 +-1 +752 +2552 +-1 +-1 +1570 +2537 +0 +1007 +983 +1895 +1698 +1264 +2333 +202 +1859 +2937 +1969 +1980 +1756 +936 +1100 +1751 +-1 +1128 +1264 +2416 +-1 +2105 +2771 +367 +-1 +-1 +565 +919 +1524 +1138 +2163 +2207 +-1 +2115 +217 +2317 +1145 +2051 +2435 +1602 +-1 +341 +1989 +-1 +2499 +2873 +3393 +2270 +2558 +-1 +-1 +4419 +767 +-1 +-1 +2269 +-1 +-1 +2102 +631 +3192 +-1 +1451 +1614 +2360 +812 +2242 +1698 +2147 +2341 +-1 +2698 +1119 +2353 +2039 +812 +-1 +1145 +-1 +1408 +2527 +1687 +2347 +1224 +1689 +1591 +285 +722 +-1 +2181 +2217 +-1 +3421 +1240 +-1 +1514 +1972 +748 +1931 +2268 +2098 +2761 +2125 +1225 +1993 +602 +1487 +2994 +-1 +-1 +2688 +1591 +2188 +-1 +1843 +-1 +971 +2686 +3977 +1079 +-1 +1990 +1361 +-1 +1031 +1864 +-1 +2774 +3053 +-1 +-1 +-1 +-1 +1927 +1226 +1692 +536 +318 +225 +1937 +2062 +1115 +2377 +331 +1626 +1822 +2036 +3155 +1629 +1127 +-1 +1072 +1148 +3093 +511 +0 +1250 +1302 +-1 +2253 +2411 +2263 +1872 +-1 +3322 +1394 +0 +1705 +3253 +1562 +1642 +1629 +295 +2121 +722 +2197 +-1 +1804 +848 +2872 +902 +1815 +-1 +1274 +1725 +3004 +-1 +2429 +1288 +1250 +2100 +1069 +-1 +1301 +-1 +1064 +2013 +2443 +0 +964 +2638 +3760 +-1 +3442 +-1 +2191 +254 +542 +-1 +2361 +1357 +1478 +-1 +1513 +3421 +1281 +2022 +1931 +1638 +1380 +-1 +-1 +1745 +224 +3396 +1019 +1680 +3942 +-1 +2852 +1550 +2339 +1689 +1763 +974 +1725 +-1 +2429 +2073 +1366 +1381 +1680 +-1 +1937 +1116 +1937 +3155 +1545 +870 +1972 +2342 +3562 +1263 +2370 +1804 +1428 +1940 +1281 +2805 +1902 +0 +-1 +2144 +-1 +1949 +1834 +3184 +-1 +2145 +-1 +1753 +-1 +-1 +1927 +1478 +0 +1822 +-1 +2725 +1443 +-1 +2400 +2363 +2062 +3297 +-1 +1095 +247 +-1 +1873 +2418 +2022 +1885 +997 +-1 +-1 +1605 +2999 +1857 +1987 +0 +2280 +-1 +658 +705 +974 +1725 +3252 +2949 +2253 +-1 +1393 +1725 +2412 +-1 +154 +-1 +1518 +758 +-1 +-1 +2252 +1425 +2094 +3249 +2279 +2025 +1182 +3344 +-1 +3252 +1337 +2284 +3227 +2098 +4624 +1330 +700 +2525 +-1 +1424 +2561 +1639 +722 +1980 +3053 +-1 +848 +2218 +3605 +-1 +-1 +2146 +1232 +1700 +-1 +2549 +2146 +3093 +2062 +-1 +1307 +-1 +1233 +186 +-1 +2987 +761 +1666 +2648 +2242 +3765 +799 +1874 +1274 +2541 +-1 +331 +1116 +2119 +1727 +-1 +445 +0 +1723 +2756 +880 +2513 +3249 +2418 +-1 +3499 +941 +2881 +1985 +1263 +-1 +1666 +827 +1595 +1104 +1428 +2688 +2339 +1514 +1502 +2421 +2187 +566 +-1 +2446 +2098 +945 +330 +2837 +1725 +1814 +1712 +3760 +1596 +1027 +2686 +389 +448 +838 +2489 +1969 +2132 +1425 +1947 +3155 +2263 +2784 +1606 +2268 +-1 +1361 +-1 +1639 +933 +2877 +2841 +3565 +-1 +1404 +2157 +-1 +1216 +3127 +3004 +1287 +669 +-1 +1995 +1714 +1434 +1560 +1937 +2460 +2616 +2742 +2094 +1822 +665 +1088 +2025 +2735 +1610 +844 +619 +1575 +1149 +1076 +1342 +1408 +453 +798 +900 +1922 +1627 +1159 +2368 +2412 +1361 +1151 +1480 +1023 +468 +2880 +928 +1326 +986 +1895 +3007 +517 +755 +1882 +873 +3069 +1427 +2492 +1068 +2196 +1052 +1218 +912 +1382 +1203 +2087 +806 +1459 +2128 +2177 +1603 +1171 +976 +1448 +197 +1832 +1552 +293 +1328 +1906 +293 +474 +1125 +917 +1002 +1428 +529 +1005 +1666 +1524 +833 +1533 +2052 +1678 +468 +1254 +973 +906 +2565 +1686 +1754 +730 +1361 +679 +924 +1064 +0 +0 +2272 +929 +1478 +622 +1189 +1152 +1370 +2218 +1538 +1552 +1724 +1514 +1935 +1064 +1126 +1475 +403 +1660 +1939 +658 +1005 +0 +941 +1087 +1882 +1147 +1998 +1069 +1530 +2023 +808 +1305 +1895 +648 +1117 +922 +1826 +1268 +611 +919 +1894 +925 +1830 +1227 +1867 +1968 +1550 +1058 +823 +1330 +506 +2420 +2493 +760 +1698 +1617 +679 +1408 +364 +0 +922 +978 +579 +769 +1157 +1176 +1152 +1088 +1922 +908 +1478 +784 +299 +1147 +1927 +1000 +1987 +531 +656 +418 +1186 +1062 +327 +1404 +79 +477 +3261 +856 +730 +1329 +226 +1703 +902 +1603 +1079 +1443 +976 +1540 +1338 +1414 +602 +941 +374 +0 +2066 +1749 +182 +1121 +629 +856 +886 +2196 +482 +1183 +495 +1607 +1500 +1987 +1980 +477 +1915 +1404 +1754 +1941 +1005 +978 +1712 +926 +890 +1416 +2031 +390 +3210 +2740 +1102 +2135 +0 +705 +659 +314 +1186 +941 +1060 +1514 +1921 +1153 +781 +885 +261 +1573 +1076 +2079 +1064 +1182 +856 +1199 +960 +941 +1363 +2120 +571 +2369 +886 +235 +2239 +1268 +1259 +957 +2038 +1152 +1058 +0 +436 +526 +1654 +1712 +1409 +885 +919 +403 +348 +2130 +1496 +1331 +1309 +1751 +609 +2947 +934 +208 +1826 +181 +2177 +976 +852 +1854 +1806 +1088 +1998 +2740 +856 +1827 +1695 +1611 +1151 +602 +477 +1555 +575 +489 +1558 +833 +0 +2011 +837 +2225 +2372 +1600 +1496 +933 +1186 +344 +1600 +2435 +1220 +1000 +1749 +2190 +2238 +800 +531 +732 +782 +941 +1987 +1323 +2823 +2468 +2079 +1980 +1927 +556 +475 +1534 +546 +1953 +1208 +633 +2609 +285 +1312 +1516 +523 +673 +1949 +1493 +784 +738 +658 +941 +2119 +1548 +926 +976 +1014 +601 +1322 +1644 +1500 +1064 +1651 +912 +1363 +779 +1553 +1043 +617 +1470 +904 +833 +2337 +1224 +956 +2557 +285 +1390 +2239 +1654 +2031 +285 +869 +291 +1198 +833 +1035 +1017 +495 +1273 +1002 +1532 +1611 +0 +1077 +453 +1136 +1262 +517 +2947 +0 +1871 +608 +1549 +2460 +1452 +1654 +2092 +1166 +331 +1017 +655 +2170 +331 +1107 +2146 +1848 +113 +548 +382 +418 +782 +671 +1962 +998 +1224 +497 +2052 +348 +1517 +1475 +1291 +1524 +2823 +506 +745 +1763 +1156 +730 +1149 +1035 +2211 +1627 +1981 +1463 +2393 +1414 +1138 +1553 +2939 +1719 +860 +1218 +969 +1204 +1443 +1848 +348 +1062 +2634 +1219 +908 +1166 +1401 +1377 +1921 +1935 +671 +1524 +0 +1968 +1549 +1143 +1946 +1922 +1652 +1651 +810 +564 +1379 +1184 +845 +1756 +1724 +1660 +784 +579 +1174 +1323 +760 +1551 +2011 +1611 +856 +1312 +1404 +1738 +904 +896 +3090 +900 +904 +1962 +1666 +2244 +1863 +786 +2092 +1000 +1322 +235 +669 +1749 +1894 +1363 +696 +1555 +609 +1353 +1186 +350 +956 +671 +2168 +830 +1607 +2740 +897 +2087 +197 +1496 +2946 +1576 +886 +1887 +548 +1737 +957 +1107 +1726 +926 +902 +2211 +1184 +1330 +1561 +833 +1890 +1554 +284 +639 +2740 +314 +3090 +0 +1615 +1382 +831 +1600 +1827 +1516 +1938 +1935 +1530 +1604 +1737 +499 +2877 +2083 +2107 +374 +837 +1548 +1941 +890 +1931 +546 +922 +1941 +1826 +570 +2128 +1896 +1109 +1946 +1678 +782 +158 +830 +1273 +1629 +806 +1224 +1134 +648 +1229 +924 +434 +2539 +856 +2104 +1326 +2011 +1927 +579 +475 +1644 +1629 +782 +522 +653 +1535 +575 +1703 +237 +2477 +1636 +798 +551 +1493 +617 +1922 +973 +1003 +2146 +1023 +904 +491 +745 +942 +1681 +1125 +1224 +2203 +2168 +2135 +672 +952 +976 +0 +1199 +1802 +1826 +1459 +856 +1220 +2374 +546 +1380 +806 +671 +2023 +572 +807 +1953 +1204 +1717 +1050 +2477 +2038 +683 +1862 +0 +361 +765 +1600 +1440 +2361 +1637 +779 +1828 +1686 +2135 +1121 +1074 +1258 +899 +1548 +459 +2361 +517 +1549 +633 +2025 +1149 +1735 +113 +1652 +1138 +1361 +1229 +495 +1366 +1962 +884 +468 +231 +682 +1179 +1695 +900 +1526 +619 +830 +546 +1102 +1871 +1615 +709 +0 +1037 +1208 +1366 +1243 +900 +841 +2460 +1933 +724 +1945 +2539 +2170 +1737 +1838 +2502 +2244 +730 +1077 +1719 +900 +1962 +829 +1062 +1674 +1363 +1886 +840 +1717 +2740 +1077 +703 +658 +1456 +1751 +181 +523 +398 +1786 +3007 +679 +1485 +2392 +594 +1149 +197 +837 +956 +963 +782 +1184 +2177 +806 +808 +1611 +327 +1153 +1712 +1280 +852 +760 +1603 +1323 +1312 +1945 +2051 +1508 +237 +800 +1603 +1961 +567 +1921 +1254 +1830 +1719 +1946 +1247 +1624 +1600 +1717 +1117 +398 +784 +806 +1176 +1005 +1136 +1927 +1493 +2225 +2111 +815 +1425 +1654 +1219 +881 +0 +905 +963 +1962 +1395 +2 +609 +1882 +526 +1404 +299 +1123 +1252 +1000 +1000 +2000 +810 +1719 +976 +1232 +1064 +902 +599 +730 +1717 +633 +1268 +1032 +633 +1166 +1906 +1145 +2750 +782 +0 +2557 +1217 +1360 +1102 +2052 +602 +594 +2468 +1157 +1058 +1774 +619 +334 +611 +0 +2051 +622 +896 +1408 +3069 +499 +928 +0 +314 +1485 +2120 +910 +960 +658 +1277 +1603 +1538 +2130 +1908 +2239 +1543 +564 +608 +1558 +1617 +2058 +1517 +1171 +197 +1399 +922 +2239 +572 +328 +780 +1545 +934 +208 +1317 +1021 +1898 +2880 +1595 +1938 +1468 +1749 +784 +1060 +926 +709 +851 +1957 +982 +671 +1625 +79 +3077 +1200 +1968 +683 +963 +798 +1208 +1615 +2170 +1930 +1600 +1548 +2066 +1183 +781 +987 +987 +1440 +434 +711 +784 +1404 +1008 +1551 +2337 +0 +545 +949 +1072 +419 +1935 +885 +1208 +1079 +703 +0 +1769 +468 +1219 +1838 +1751 +0 +1424 +1125 +0 +624 +1320 +1157 +1530 +784 +619 +2168 +1390 +1503 +1360 +2239 +575 +3792 +2643 +-1 +722 +-1 +-1 +1925 +935 +626 +-1 +1609 +1927 +-1 +1974 +2904 +3718 +1046 +-1 +1925 +3195 +302 +-1 +3595 +-1 +2837 +-1 +2668 +-1 +775 +953 +-1 +-1 +2096 +2801 +1570 +1650 +4839 +972 +1525 +2879 +-1 +2635 +963 +2576 +2041 +2451 +3703 +-1 +2156 +-1 +1974 +2945 +-1 +949 +3468 +1357 +3811 +-1 +-1 +-1 +2165 +0 +-1 +-1 +2089 +1525 +934 +1682 +3008 +2955 +1219 +-1 +-1 +4248 +-1 +-1 +1851 +-1 +3029 +1851 +-1 +2119 +-1 +963 +-1 +3041 +3496 +-1 +561 +2451 +1424 +2631 +1238 +2245 +2318 +2787 +2372 +2076 +1991 +2970 +1682 +2149 +2801 +2791 +2329 +912 +-1 +0 +2148 +2323 +-1 +-1 +-1 +2543 +677 +625 +3295 +1570 +2741 +839 +1192 +1984 +2611 +-1 +2511 +2858 +-1 +935 +2019 +3085 +3022 +2816 +2256 +-1 +18 +-1 +1897 +1253 +3729 +-1 +2794 +2334 +2066 +-1 +732 +2999 +2762 +3331 +2050 +3730 +2162 +1424 +3416 +2405 +3840 +3908 +2857 +1207 +1999 +-1 +2952 +1928 +-1 +2486 +2302 +-1 +4180 +1942 +2551 +1920 +-1 +2033 +1599 +-1 +1220 +2222 +3754 +4308 +2633 +2776 +4308 +3667 +2688 +2879 +-1 +3315 +1131 +2302 +1415 +2194 +1646 +-1 +2854 +2439 +1478 +1202 +2665 +-1 +2854 +-1 +3268 +1957 +3529 +-1 +2879 +542 +3493 +3061 +968 +2499 +1964 +2066 +3266 +0 +2945 +2405 +416 +4186 +2308 +-1 +810 +-1 +847 +2161 +1145 +4144 +-1 +1249 +-1 +2156 +-1 +-1 +4144 +-1 +876 +3098 +2029 +-1 +-1 +2280 +1828 +-1 +0 +-1 +2499 +1325 +3006 +-1 +2033 +-1 +-1 +3811 +1196 +564 +-1 +2668 +436 +2663 +1041 +3137 +3561 +3621 +2519 +3048 +1942 +1455 +3529 +564 +-1 +1799 +2997 +3718 +3164 +3609 +2563 +2175 +2342 +-1 +3137 +1010 +2338 +2042 +0 +868 +953 +3349 +3769 +-1 +2945 +2281 +3535 +2668 +-1 +594 +2612 +3195 +3946 +1692 +-1 +3273 +839 +1825 +2563 +802 +786 +-1 +1735 +1817 +2137 +-1 +3048 +3324 +2423 +3793 +2574 +-1 +158 +2442 +-1 +2908 +3318 +1926 +-1 +2915 +-1 +0 +881 +3587 +3196 +2288 +3946 +1576 +-1 +1799 +3051 +1559 +1010 +416 +2302 +2860 +1373 +0 +2129 +-1 +2447 +3665 +3475 +-1 +2984 +830 +-1 +0 +1811 +-1 +1638 +2280 +-1 +2193 +2556 +-1 +-1 +2916 +1834 +2404 +1629 +1683 +1364 +1650 +2908 +3037 +-1 +941 +4214 +3314 +4219 +2004 +-1 +2302 +2793 +1525 +2269 +1761 +-1 +3257 +3400 +2927 +1760 +-1 +1974 +2794 +2745 +-1 +1872 +2127 +1290 +-1 +3475 +3703 +2643 +2881 +839 +1358 +392 +1478 +2405 +1748 +1865 +2405 +2342 +972 +1806 +1726 +1980 +1288 +1220 +3072 +3665 +3498 +727 +723 +1789 +-1 +924 +2378 +1929 +3595 +-1 +-1 +1957 +3428 +1688 +-1 +2127 +0 +1769 +-1 +2372 +2691 +2361 +-1 +1424 +2447 +-1 +1576 +-1 +1760 +2302 +3483 +2192 +-1 +2635 +2552 +2908 +2004 +2665 +-1 +953 +3811 +-1 +3416 +2451 +3496 +2643 +1928 +4182 +1801 +-1 +1514 +3118 +-1 +2046 +2029 +1219 +-1 +1455 +1106 +2037 +-1 +2098 +1925 +649 +3121 +0 +2041 +1843 +1173 +2883 +1709 +1421 +2561 +833 +1041 +-1 +2720 +1249 +2390 +-1 +3047 +2313 +2503 +3792 +-1 +-1 +-1 +3008 +3599 +-1 +1834 +2076 +2447 +2997 +2384 +-1 +3118 +2858 +2797 +1173 +1698 +830 +1747 +2650 +-1 +972 +3468 +3595 +1997 +2281 +1761 +912 +-1 +2913 +2423 +3315 +4192 +802 +3468 +1963 +2574 +1361 +3751 +-1 +0 +839 +2037 +2042 +868 +1106 +-1 +3686 +-1 +2597 +2793 +1769 +3890 +2999 +1730 +2706 +-1 +1650 +1709 +1925 +605 +-1 +3164 +1112 +-1 +2026 +2164 +2917 +-1 +-1 +4192 +-1 +3103 +2695 +1957 +923 +3732 +-1 +2650 +2390 +2066 +3466 +2785 +2668 +-1 +359 +1744 +1707 +2380 +2256 +3582 +2647 +-1 +912 +-1 +2098 +2419 +2048 +2643 +1450 +359 +1264 +-1 +-1 +1410 +2342 +3865 +3314 +2635 +3421 +-1 +3266 +-1 +2511 +-1 +73 +2883 +2563 +1095 +2478 +359 +3103 +3083 +3157 +1125 +2609 +-1 +-1 +2083 +1239 +2156 +1288 +1942 +934 +3811 +3802 +-1 +1983 +-1 +-1 +-1 +2970 +2237 +1698 +2864 +3256 +1843 +1964 +2879 +-1 +1935 +2797 +1928 +2383 +4090 +2029 +1273 +4248 +594 +3399 +-1 +-1 +4227 +3038 +2415 +2650 +-1 +3349 +3587 +-1 +1591 +2537 +2787 +1830 +2269 +2643 +-1 +833 +2556 +-1 +1980 +1760 +1273 +866 +-1 +1997 +3493 +-1 +2934 +2776 +1656 +-1 +-1 +-1 +956 +2857 +0 +-1 +1810 +677 +1000 +1963 +-1 +-1 +3567 +888 +3498 +-1 +-1 +638 +3582 +2574 +3544 +3903 +-1 +3475 +2793 +2029 +605 +866 +2013 +2159 +3136 +4210 +638 +3475 +2997 +1101 +3018 +866 +2864 +1761 +3622 +2318 +953 +3811 +-1 +2425 +1122 +4118 +2842 +0 +1211 +2329 +912 +1046 +1983 +1818 +2334 +1565 +3718 +1663 +-1 +1811 +2906 +3416 +-1 +1834 +2232 +-1 +732 +2123 +-1 +1928 +1451 +-1 +0 +1078 +3900 +-1 +1512 +1793 +-1 +1997 +2245 +2047 +3369 +4290 +2638 +720 +2945 +3304 +3072 +-1 +2254 +-1 +3037 +3052 +2781 +2380 +-1 +2269 +240 +-1 +1273 +-1 +2076 +-1 +2160 +2483 +2300 +2913 +-1 +1828 +1211 +-1 +-1 +2787 +4308 +2948 +912 +2384 +3265 +3880 +876 +1959 +0 +4381 +1716 +-1 +959 +2315 +3665 +-1 +627 +2384 +2576 +-1 +2245 +2503 +1695 +-1 +1817 +2916 +3811 +-1 +1668 +1914 +2955 +0 +3195 +1211 +1692 +4126 +-1 +2695 +3475 +2816 +4219 +3498 +-1 +169 +2035 +1217 +1131 +3756 +-1 +-1 +-1 +3022 +2094 +1921 +3293 +2323 +2313 +1288 +4381 +1822 +302 +-1 +2362 +-1 +2741 +3180 +732 +3679 +1756 +978 +3314 +1521 +2336 +1370 +2336 +2561 +1421 +944 +2483 +3756 +3159 +1656 +2484 +2628 +334 +3192 +2083 +-1 +2608 +158 +-1 +-1 +2368 +334 +2695 +2146 +1196 +1747 +1866 +-1 +1218 +-1 +3983 +2300 +-1 +3561 +1999 +-1 +953 +2534 +-1 +-1 +3717 +-1 +1682 +3799 +1217 +-1 +4182 +-1 +4363 +1514 +1847 +1930 +1935 +2054 +-1 +2561 +4210 +0 +1851 +-1 +2913 +1543 +0 +2451 +1290 +2679 +3098 +-1 +2291 +1758 +3969 +2499 +1303 +-1 +1525 +1688 +-1 +2441 +2970 +-1 +3587 +-1 +2843 +2763 +1833 +-1 +1526 +-1 +2854 +2563 +1297 +1933 +1828 +-1 +1119 +-1 +470 +-1 +890 +-1 +-1 +3144 +-1 +-1 +-1 +2121 +-1 +-1 +-1 +-1 +1702 +1702 +615 +2129 +1022 +1319 +211 +685 +1417 +1417 +871 +1091 +-1 +-1 +-1 +-1 +-1 +-1 +1994 +2363 +-1 +-1 +-1 +-1 +-1 +2484 +1008 +980 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +470 +-1 +-1 +443 +1797 +3464 +-1 +720 +-1 +1529 +439 +-1 +1479 +-1 +454 +-1 +-1 +-1 +0 +-1 +-1 +-1 +-1 +1091 +561 +-1 +-1 +-1 +-1 +-1 +1573 +-1 +-1 +-1 +2299 +-1 +-1 +1405 +-1 +1797 +-1 +365 +-1 +1654 +-1 +2644 +632 +-1 +-1 +1572 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +1723 +1479 +1149 +-1 +-1 +2128 +-1 +980 +871 +0 +-1 +-1 +927 +-1 +-1 +-1 +-1 +3421 +1119 +3096 +1412 +0 +-1 +2193 +0 +1414 +-1 +-1 +1091 +-1 +-1 +-1 +-1 +-1 +-1 +401 +696 +-1 +-1 +-1 +471 +1712 +2714 +-1 +2625 +2398 +0 +-1 +-1 +443 +1065 +-1 +1704 +-1 +-1 +2405 +-1 +-1 +890 +-1 +-1 +-1 +-1 +1951 +-1 +-1 +1339 +2935 +-1 +-1 +-1 +1221 +-1 +-1 +-1 +-1 +-1 +1419 +2644 +-1 +1466 +-1 +1984 +708 +-1 +2731 +-1 +885 +-1 +627 +-1 +-1 +-1 +602 +1491 +-1 +2033 +539 +-1 +-1 +-1 +2227 +-1 +2185 +2381 +1579 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +-1 +1477 +1008 +-1 +-1 +-1 +2154 +1936 +1058 +2734 +1015 +190 +-1 +-1 +-1 +1529 +-1 +0 +-1 +1276 +-1 +-1 +1951 +-1 +401 +2907 +211 +-1 +-1 +1399 +-1 +2672 +3100 +3287 +-1 +4203 +-1 +3275 +-1 +-1 +7196 +2788 +4189 +-1 +2486 +0 +2407 +1004 +-1 +2750 +4745 +3285 +1571 +1938 +0 +1942 +-1 +2319 +4927 +-1 +-1 +-1 +224 +-1 +-1 +3514 +2971 +-1 +3419 +-1 +-1 +-1 +-1 +3302 +-1 +-1 +-1 +-1 +2089 +-1 +1003 +-1 +1870 +-1 +-1 +-1 +2366 +-1 +0 +1847 +-1 +2134 +4707 +2004 +3269 +-1 +-1 +-1 +5068 +4256 diff --git a/spoj/KAUSANDNIHA.cpp b/spoj/KAUSANDNIHA.cpp new file mode 100644 index 0000000..4d9380c --- /dev/null +++ b/spoj/KAUSANDNIHA.cpp @@ -0,0 +1,75 @@ +#include +using namespace std; +#define SIZE 10005 +#define ll long long +#define INF 1000000 + +int n,m; +ll dist[SIZE][SIZE]; + +void clear() +{ + for(int i=0;i +using namespace std; +#define ll long long + +ll a[100005]; + +int main() +{ + int t; + scanf("%d", &t); + + while(t--) + { + ll n,s; + scanf("%lld %lld", &n, &s); + + for(int i=1;i<=n;i++) + { + scanf("%lld", &a[i]); + } + + + } +} \ No newline at end of file diff --git a/spoj/KGSS b/spoj/KGSS new file mode 100755 index 0000000..1fa75e1 Binary files /dev/null and b/spoj/KGSS differ diff --git a/spoj/KGSS.cpp b/spoj/KGSS.cpp new file mode 100644 index 0000000..1d28cb2 --- /dev/null +++ b/spoj/KGSS.cpp @@ -0,0 +1,101 @@ +#include +using namespace std; +#define SIZE 100005 +#define ll long long + +struct trees +{ + ll max,maxsum; +}; + +trees tree[SIZE<<3]; + +trees merge(trees a,trees b) +{ + trees res; + res.max=max(a.max,b.max); + res.maxsum=max(max(a.maxsum,b.maxsum),(a.max+b.max)); + return res; +} + +void build(int node,int start,int end) +{ + if(start==end) + { + int x; + scanf("%d",&x); + tree[node].max=tree[node].maxsum=x; + return; + } + + int mid=(start+end)>>1; + build(2*node,start,mid); + build(2*node+1,mid+1,end); + + tree[node]=merge(tree[2*node],tree[2*node+1]); +} + +void update(int node,int start, int end, int x, int val) +{ + if(start==end) + { + tree[node].max=tree[node].maxsum=val; + } + else + { + int mid=(start+end)>>1; + + if(start<=x && x<=mid) + { + update(2*node,start,mid,x,val); + } + else + { + update(2*node+1,mid+1,end,x,val); + } + tree[node]=merge(tree[2*node],tree[2*node+1]); + } +} + +trees query(int node,int start,int end, int l,int r) +{ + if(start==l && end==r) + { + return tree[node]; + } + int mid=(start+end)>>1; + int p1=node<<1; + int p2=node<<1|1; + + if(r<=mid) return query(p1,start,mid,l,r); + else if(l>mid) return query(p2,mid+1,end,l,r); + else return (merge(query(p1,start,mid,l,mid),query(p2,mid+1,end,mid+1,r))); +} + +int main() +{ + int n; + if(scanf("%d",&n)) + { + build(1,1,n); + } + + int q; + scanf("%d",&q); + while(q--) + { + char c; + int x,y; + cin>>c; + scanf("%d%d",&x,&y); + if(c=='U') + { + update(1,1,n,x,y); + } + else if(c=='Q') + { + printf("%lld\n", query(1,1,n,x,y).maxsum); + } + } + +} \ No newline at end of file diff --git a/spoj/KGSStest b/spoj/KGSStest new file mode 100755 index 0000000..7000e4d Binary files /dev/null and b/spoj/KGSStest differ diff --git a/spoj/KGSStest.cpp b/spoj/KGSStest.cpp new file mode 100644 index 0000000..453180a --- /dev/null +++ b/spoj/KGSStest.cpp @@ -0,0 +1,77 @@ + #include +#include +#define MAX 100000 + +using namespace std; + +struct sum { + long long int msum; + long long int m; +}; + +int array[ MAX + 1 ]; +sum tree[ 4 * MAX + 1 ]; + +void init( int node, int i, int j ) { + if ( i == j ) { + tree[ node ] = ( ( sum ) { array[ i ], array[ i ] } ); + } + else { + init( node * 2, i, ( i + j ) / 2 ); + init( node * 2 + 1, ( i + j ) / 2 + 1, j ); + sum left = tree[ node * 2 ], right = tree[ node * 2 + 1 ]; + tree[ node ].msum = max( left.msum, max( right.msum, left.m + right.m ) ); + tree[ node ].m = max( left.m, right.m ); + } +} + +sum query( int node, int a, int b, int i, int j ) { + if ( a > b || a > j || b < i ) { + return ( ( sum ) { 0, 0 } ); + } + if ( a >= i && b <= j ) { + return tree[ node ]; + } + sum left = query( node * 2, a, ( a + b ) / 2, i, j ); + sum right = query( node * 2 + 1, ( a + b ) / 2 + 1, b, i, j ); + return ( ( sum ) { + max( left.msum, max( right.msum, left.m + right.m ) ), + max( left.m, right.m ) } ); +} + +void update( int node, int a, int b, int pos, int val ) { + if ( a == b && a == pos ) { + tree[ node ] = ( ( sum ) { val, val } ); + return; + } + if ( pos <= ( a + b ) / 2 ) { + update( node * 2, a, ( a + b ) / 2, pos, val ); + } + if ( pos > ( a + b ) / 2 ) { + update( node * 2 + 1, ( a + b ) / 2 + 1, b, pos, val ); + } + sum left = tree[ node * 2 ], right = tree[ node * 2 + 1 ]; + tree[ node ].msum = max( left.msum, max( right.msum, left.m + right.m ) ); + tree[ node ].m = max( left.m, right.m ); +} + +int main() { + int N, Q, l, r, i; + char c; + scanf( "%d", &N ); + for ( i = 0; i < N; ++i ) { + scanf( "%d", array + i ); + } + init( 1, 0, N - 1 ); + scanf( "%d", &Q ); + for ( i = 0; i < Q; ++i ) { + scanf( "%*c%c%d%d", &c, &l, &r ); + if ( c == 'U' ) { + update( 1, 0, N - 1, l - 1, r ); + } + else { + printf( "%lld\n", query( 1, 0, N - 1, l - 1, r - 1 ).msum ); + } + } + return 0; +} \ No newline at end of file diff --git a/spoj/KNAPSACK b/spoj/KNAPSACK new file mode 100755 index 0000000..2ecfb5e Binary files /dev/null and b/spoj/KNAPSACK differ diff --git a/spoj/KNAPSACK.cpp b/spoj/KNAPSACK.cpp new file mode 100644 index 0000000..c3da21c --- /dev/null +++ b/spoj/KNAPSACK.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; +#define ll long long + +ll dp[2005][2005]; +ll weight[2005]; +ll value[2005]; + +int main() +{ + ll S,N,x,y; + cin>>S>>N; + for(ll i=1;i<=N;i++) + { + scanf("%lld %lld", &weight[i], &value[i]); + } + + dp[0][0]=0; + + for(ll i=1;i<=N;i++) + { + for(ll w=1;w<=S;w++) + { + if(weight[i]<=w) + dp[i][w]=max(dp[i-1][w-weight[i]]+value[i], dp[i-1][w]); + else + dp[i][w]=dp[i-1][w]; + } + } + + printf("%lld\n",dp[N][S]); +} \ No newline at end of file diff --git a/spoj/KOPC12B b/spoj/KOPC12B new file mode 100755 index 0000000..e342819 Binary files /dev/null and b/spoj/KOPC12B differ diff --git a/spoj/KOPC12B.cpp b/spoj/KOPC12B.cpp new file mode 100644 index 0000000..560e683 --- /dev/null +++ b/spoj/KOPC12B.cpp @@ -0,0 +1,81 @@ +#include +using namespace std; + +#define MOD 1000000007 + +//long long int row[10000001]; + +/*long long int nCr(long long int n,long long int r) +{ + long long int i,j; + + row[0]=1; + + for(i=1;i<=n;i++) + { + for(j=i;j>0;j--) + { + row[j]+=row[j-1]; + } + } + + return row[r]; +}*/ + + +long long int nCrModpDP(int n, int r, int p) +{ + // The array C is going to store last row of + // pascal triangle at the end. And last entry + // of last row is nCr + long long int C[r+1]; + memset(C, 0, sizeof(C)); + + C[0] = 1; // Top row of Pascal Triangle + + // One by constructs remaining rows of Pascal + // Triangle from top to bottom + for (int i = 1; i <= n; i++) + { + // Fill entries of current row using previous + // row values + for (int j = min(i, r); j > 0; j--) + + // nCj = (n-1)Cj + (n-1)C(j-1); + C[j] = (C[j] + C[j-1])%p; + } + return C[r]; +} + +int nCrModpLucas(int n, int r, int p) +{ + // Base case + if (r==0) + return 1; + + // Compute last digits of n and r in base p + int ni = n%p, ri = r%p; + + // Compute result for last digits computed above, and + // for remaining digits. Multiply the two results and + // compute the result of multiplication in modulo p. + return (nCrModpLucas(n/p, r/p, p) * // Last digits of n and r + nCrModpDP(ni, ri, p)) % p; // Remaining digits +} + +int main() +{ + int t; + cin>>t; + while(t--) + { + long long int n=0,res=0; + cin>>n; + //memset(row,0,sizeof(row)); + res=nCrModpLucas(2*n-1,n-1,MOD); + res*=n; + + cout< +using namespace std; +#define ll long long +#define SIZE 260 +int arr[SIZE][SIZE]; +// int s[SIZE][SIZE]; +int bigarr[SIZE*3]; +int n,m; +int sum[SIZE], sum_A[SIZE], sum_B_1[SIZE]; +int BIT[SIZE*3]; + +int find(int value, int start, int end) +{ + while(start<=end) + { + int mid=start+end>>1; + if(bigarr[mid]==value) return mid; + else if(bigarr[mid]0;x-=x&-x) + { + res+=BIT[x]; + } + return res; +} + +int main() +{ + scanf("%d %d", &n, &m); + // ll x; + + for(int j=1;j<=m;j++) + arr[0][j]=0; + + for(int i=1;i<=n;i++) + { + for(int j=1;j<=m;j++) + { + /*scanf("%lld", &x); + update(i,j,x);*/ + scanf("%d", &arr[i][j]); + arr[i][j]=arr[i-1][j]+arr[i][j]; //calculating prefix column sum + } + } + + int A,B; + scanf("%d %d", &A, &B); + + /*for(int j=1; j<=m;j++) printf("%d ", arr[0][j]); + printf("\n"); + for(int i=1;i<=n;i++) + { + for(int j=1;j<=m;j++) + { + printf("%d ", arr[i][j]); + } + printf("\n"); + } + + return 0;*/ + + ll res=0; + + for(int i=1;i<=n;i++) + { + for(int j=i;j<=n;j++) + { + //storing all possible values of sum, sum-A & sum-B-1 in bigarr + int count=1; + sum[0]=0; + sum_A[0]=sum[0]-A; + sum_B_1[0]=sum[0]-B-1; + bigarr[count++]=sum[0]; + bigarr[count++]=sum_A[0]; + bigarr[count++]=sum_B_1[0]; + + for(int k=1;k<=m;k++) + { + sum[k]=sum[k-1]+arr[j][k]-arr[i-1][k]; //calculating prefix row sum + sum_A[k]=sum[k]-A; + sum_B_1[k]=sum[k]-B-1; + bigarr[count++]=sum[k]; + bigarr[count++]=sum_B_1[k]; + bigarr[count++]=sum_A[k]; + } + + /*for(int i=1;i +#include +#include + +const int NN = 260 ; +int N,M, A, B; +int map[NN][NN] ; +int sum[NN] ; +int sumB[NN] , sumA[NN] ; +int xx[NN*3] ; +int C[3 * NN] ; + + +int find( int val , int l ,int r ){ + while( l<=r ){ + int mid = (l + r) >> 1 ; + if( xx[mid] == val ) return mid ; + if( xx[mid] < val ) l = mid + 1 ; + else r = mid - 1 ; + } + return -1 ; +} + +inline int lowbit(int a){ return a&(-a) ; } + +void add(int a , int n){ + while( a<=n ){ + C[a] ++ ; a += lowbit(a) ; + } +} + +int cal_sum(int n){ + int res = 0 ; + while( n>=1 ){ + res += C[n] ; + n -= lowbit(n) ; + } + return res ; +} +void solve() +{ + int ans = 0 ; + for(int i=1;i<=N;i++) + { + for(int j=i;j<=N;j++) + { + int cnt = 1 ; + sum[0] = 0 ; + sumA[0] = sum[0] - A ; + sumB[0] = sum[0] - B - 1; + xx[cnt++ ] = sum[0] ; + xx[cnt++ ] = sumA[0] ; + xx[cnt++ ] = sumB[0] ; + + for(int k=1;k<=M;k++) + { + // printf("%d %d %d \n",sum[k-1], map[j][k], map[i-1][k]); + + sum[k] = sum[k-1] + map[j][k] - map[i-1][k] ; + // printf("S %d ", sum[k]); + + // printf("\n"); + + sumA[k] = sum[k] - A ; + // printf("A %d ",sumA[k]); + + // printf("\n"); + + sumB[k] = sum[k] - B - 1; + // printf("B %d ",sumB[k]); + + // printf("\n"); + + xx[cnt ++] = sum[k] ; + // printf("xx %d\n", xx[p--]); + + xx[cnt ++] = sumB[k] ; + // printf("xx %d\n", xx[p--]); + + xx[cnt ++] = sumA[k] ; + } + + /*for(int k=1;k +using namespace std; + +int sieve[100005]; + +void sievefunc() +{ + for(int i=2;i<=100000;i++) + { + if(sieve[i]==0) + { + sieve[i]=1; + for(int j=2*i;j<=100000;j+=i) + { + sieve[j]++; + } + } + } +} + +int main() +{ + sievefunc(); + int t; + scanf("%d", &t); + + while(t--) + { + int a,b,x; + scanf("%d %d %d",&a,&b,&x); + int count=0; + for(int i=a;i<=b;i++) + { + if(sieve[i]==x) + count++; + } + printf("%d\n",count); + } + return 0; +} \ No newline at end of file diff --git a/spoj/KQUERY b/spoj/KQUERY new file mode 100755 index 0000000..1ece893 Binary files /dev/null and b/spoj/KQUERY differ diff --git a/spoj/KQUERY#2 b/spoj/KQUERY#2 new file mode 100755 index 0000000..497ac19 Binary files /dev/null and b/spoj/KQUERY#2 differ diff --git a/spoj/KQUERY#2.cpp b/spoj/KQUERY#2.cpp new file mode 100644 index 0000000..abbb7a1 --- /dev/null +++ b/spoj/KQUERY#2.cpp @@ -0,0 +1,131 @@ +//using segment and offline query : individual property of elements in the query + +#include +using namespace std; +#define SIZE 30005 + +int BIT[SIZE]; +int n,qu; + +struct trees +{ + int sum; +}; + +trees tree[SIZE<<3]; + +struct kquery +{ + int l; + int r; + int k; + int num; +}q[200005]; + +struct num +{ + int index; + int val; +}a[SIZE]; + +trees merge(trees a, trees b) +{ + trees res; + res.sum=a.sum+b.sum; + return res; +} + +bool cmp(num a, num b) +{ + return a.val>b.val; +} + +bool cmp1(kquery a,kquery b) +{ + if(a.k==b.k) + { + return a.r>b.r; + } + return a.k>b.k; +} + +/*void build(int node,int start,int end) +{ + if(start==end) + { + tree[node].sum=0; + return; + } + int mid=start+end>>1; + build(2*node,start,mid); + build(2*node+1,mid+1,end); + tree[node]=merge(tree[2*node],tree[2*node+1]); +} +*/ +void update(int node,int start,int end,int x) +{ + if(start==x && end==x) + { + tree[node].sum+=1; + return; + } + if(start>end || start>x || end>1; + update(2*node,start,mid,x); + update(2*node+1,mid+1,end,x); + tree[node]=merge(tree[2*node],tree[2*node+1]); +} + +trees query(int node,int start,int end, int l, int r) +{ + if(start>end || start>r || l>end) + return (trees){0}; + if(l<=start && end<=r) + return tree[node]; + int mid=start+end>>1; + return merge(query(2*node,start,mid,l,r),query(2*node+1,mid+1,end,l,r)); +} + +int main() +{ + scanf("%d",&n); + + for(int i=1;i<=n;i++) + { + scanf("%d",&a[i].val); + a[i].index=i; + //BIT[i]=0; + } + sort(a+1,a+1+n,cmp); + + scanf("%d",&qu); + + int result[qu+5]; + + for(int i=1;i<=qu;i++) + { + scanf("%d %d %d",&q[i].l,&q[i].r,&q[i].k); + q[i].num=i; + } + + sort(q+1,q+1+qu,cmp1); + + int j=1; + for(int i=1;i<=qu;i++) + { + while(j<=n && a[j].val>q[i].k) + { + update(1,1,n,a[j].index); + j++; + } + result[q[i].num]=query(1,1,n,q[i].l,q[i].r).sum; + } + + for(int i=1;i<=qu;i++) + { + printf("%d\n", result[i]); + } + + return 0; +} \ No newline at end of file diff --git a/spoj/KQUERY.cpp b/spoj/KQUERY.cpp new file mode 100644 index 0000000..e65a395 --- /dev/null +++ b/spoj/KQUERY.cpp @@ -0,0 +1,112 @@ +//using BIT and offline query : individual property of elements in the query + +#include +using namespace std; +#define SIZE 30005 + +int BIT[SIZE]; +int n,qu; + +struct kquery +{ + int l; + int r; + int k; + int num; +}q[200005]; + +struct num +{ + int index; + int val; +}a[SIZE]; + +bool cmp(num a, num b) +{ + return a.val>b.val; +} + +bool cmp1(kquery a,kquery b) +{ + if(a.k==b.k) + { + return a.r>b.r; + } + return a.k>b.k; +} + +void update(int x,int val) +{ + for(;x<=n;x+=x&-x) + { + BIT[x]+=val; + } +} + +int query(int x) +{ + int sum=0; + for(;x>0;x-=x&-x) + { + sum+=BIT[x]; + } + return sum; +} + +int main() +{ + scanf("%d",&n); + + for(int i=1;i<=n;i++) + { + scanf("%d",&a[i].val); + a[i].index=i; + BIT[i]=0; + } + sort(a+1,a+1+n,cmp); + + scanf("%d",&qu); + + int result[qu+5]; + + for(int i=1;i<=qu;i++) + { + scanf("%d %d %d",&q[i].l,&q[i].r,&q[i].k); + q[i].num=i; + } + + sort(q+1,q+1+qu,cmp1); + + /*for(int i=1;i<=n;i++) + { + printf("%d %d\n",a[i].val, a[i].index); + }*/ +/* + for(int i=1;i<=qu;i++) + { + printf("%d %d %d %d\n",q[i].l,q[i].r,q[i].k,q[i].num); + }*/ + + int j=1; + for(int i=1;i<=qu;i++) + { + while(j<=n && a[j].val>q[i].k) + { + update(a[j].index,1); /*marking the contribution of a number at a time + for all the queries that is being and are not yet + dealt with as the queries are in descending order*/ + j++; + } + result[q[i].num]=query(q[i].r)-query(q[i].l-1); + } + + /*for(int i=1;i<=n;i++) + { + printf("%d\n", query(i)); + }*/ + for(int i=1;i<=qu;i++) + { + printf("%d\n", result[i]); + } + return 0; +} \ No newline at end of file diff --git a/spoj/KQUERYMOtry b/spoj/KQUERYMOtry new file mode 100755 index 0000000..856c42a Binary files /dev/null and b/spoj/KQUERYMOtry differ diff --git a/spoj/KQUERYMOtry.cpp b/spoj/KQUERYMOtry.cpp new file mode 100644 index 0000000..584639b --- /dev/null +++ b/spoj/KQUERYMOtry.cpp @@ -0,0 +1,102 @@ +// using Mo's algorithm (SQRT Decomposition) +// correction : using SQRT decomposition not Mo's algo +// try not to use struct or vector when upper_bound or lower_bound is involved +#include +using namespace std; + +// #define ll long long +#define SIZE 30005 + +struct elements +{ + int value; + int index; +}; + +elements arr[SIZE]; + +// pair arr[SIZE]; + +struct cmp +{ + bool operator()(elements a, elements b) const + { + return a.value=l && arr[i].index<=r &&arr[i].value>k) s++; + } + + if(lblock!=rblock) + { + for(int i=rstart; i=l && arr[i].index<=r && arr[i].value>k) s++; + } + for(int i=lblock+1;i +using namespace std; +#define SIZE 30005 +#define ll long long +int n,qu; + +int a[SIZE]; + +struct kqueryo +{ + int l,r; + ll k; +}q[200005]; + +struct trees +{ + vector v; + // int count; +}; + +trees tree[300005<<3]; + +/*trees merges(trees a,trees b) +{ + trees res; + merge(a.v.begin(), a.v.end(),b.v.begin(), b.v.end(),res.v.begin()); + // res.count=a.count+b.count; + return res; +}*/ + +void build(int node,int start,int end) +{ + if(start==end) + { + tree[node].v.push_back(a[start]); + // tree[node].count=0; + return ; + } + int mid=start+end>>1; + build(2*node,start,mid); + build(2*node+1,mid+1,end); + tree[node].v.resize(tree[2*node].v.size()+tree[2*node+1].v.size()); + merge(tree[2*node].v.begin(),tree[2*node].v.end(),tree[2*node+1].v.begin(),tree[2*node+1].v.end(),tree[node].v.begin()); +} + +/* + +without sorting the elements in the vectors + +void update(int node, int start, int end, int l, int r, int k) +{ + if(start>end || start>r || l>end) + return; + if(start==end) + { + if(tree[node].v[0]>k) + tree[node].count=1; + else + tree[node].count=0; + return; + } + int mid=start+end>>1; + if(r<=mid) update(2*node,start,mid,l,r,k); + else if(l>mid) update(2*node+1,mid+1,end,l,r,k); + else + { + update(2*node,start,mid,l,r,k); + update(2*node+1,mid+1,end,l,r,k); + } + tree[node]=merge(tree[2*node],tree[2*node+1]); +}*/ + +int query(int node,int start, int end, int l, int r,int k) +{ + if(start>end || r>1; + return query(2*node,start,mid,l,r,k)+query(2*node+1,mid+1,end,l,r,k); +} + +int main() +{ + int s=0; + scanf("%d", &n); + for(int i=1;i<=n;i++) + { + scanf("%d",&a[i]); + } + + build(1,1,n); + + scanf("%d",&qu); + for(int i=1;i<=qu;i++) + { + int a,b; + ll c; + scanf("%d%d%lld",&a,&b,&c); + q[i].l=a^s; + q[i].r=b^s; + q[i].k=c^s; + + if(q[i].l<1) q[i].l=1; + if(q[i].r>n) q[i].r=n; + + if(q[i].l>q[i].r) s=0; + else + { + // update(1,1,n,q[i].l,q[i].r,q[i].k); + s=query(1,1,n,q[i].l,q[i].r,q[i].k); + } + printf("%d\n", s); + } +} \ No newline at end of file diff --git a/spoj/KQUERYOMo b/spoj/KQUERYOMo new file mode 100755 index 0000000..90a7217 Binary files /dev/null and b/spoj/KQUERYOMo differ diff --git a/spoj/KQUERYOMo.cpp b/spoj/KQUERYOMo.cpp new file mode 100644 index 0000000..38a8454 --- /dev/null +++ b/spoj/KQUERYOMo.cpp @@ -0,0 +1,78 @@ +// using Mo's algorithm (SQRT Decomposition) +// correction : using SQRT decomposition not Mo's algo +// try not to use struct or vector when upper_bound or lower_bound is involved +#include +using namespace std; + +// #define ll long long +#define SIZE 30005 + +pair arr[SIZE]; + +int n,q,bucket,s=0; + +int main() +{ + scanf("%d",&n); + + bucket=ceil(sqrt(n)); + + for(int i=0;i=l && arr[i].second<=r &&arr[i].first>k) s++; + } + + if(lblock!=rblock) + { + for(int i=rstart; i=l && arr[i].second<=r && arr[i].first>k) s++; + } + for(int i=lblock+1;i +#define MAX 30000 +using namespace std; + +vector tree[MAX << 4]; +int a[MAX]; + + +void build(int i, int l, int r) { + if (l == r) { + tree[i].push_back(a[l]); + } + else { + int mid = (l + r) / 2; + build(2*i, l, mid); + build(2*i+1, mid+1, r); + tree[i].resize(tree[2*i].size()+tree[2*i+1].size()); + merge(tree[2*i].begin(), tree[2*i].end(), tree[2*i+1].begin(), tree[2*i+1].end(), tree[i].begin()); + } +} + +int query(int l, int r, int i, int cl, int cr, int k) { + if (cl > r || cr < l) + return 0; + else if (cl >= l && cr <= r) { + return tree[i].end() - upper_bound(tree[i].begin(), tree[i].end(), k); + } + else { + int mid = (cl + cr) / 2; + return query(l, r, 2*i, cl, mid, k) + query(l, r, 2*i+1, mid+1, cr, k); + } +} + +int main(void) { + int n; + scanf("%d", &n); + int i; + for (i = 0; i < n; i++) + scanf("%d", a+i); + build(1, 0, n-1); + int ans = 0; + int q; + scanf("%d", &q); + while (q--) { + int a, b, k; + scanf("%d %d %d", &a, &b, &k); + a = a ^ ans; + b = b ^ ans; + k = k ^ ans; + ans = query(a-1, b-1, 1, 0, n-1, k); + printf("%d\n", ans); + } + return 0; +} \ No newline at end of file diff --git a/spoj/KQUERYOtest2 b/spoj/KQUERYOtest2 new file mode 100755 index 0000000..fb7637c Binary files /dev/null and b/spoj/KQUERYOtest2 differ diff --git a/spoj/KQUERYOtest2.cpp b/spoj/KQUERYOtest2.cpp new file mode 100644 index 0000000..fee1d06 --- /dev/null +++ b/spoj/KQUERYOtest2.cpp @@ -0,0 +1,46 @@ +#include + +using namespace std; + +int BUCKET; +const int N = 30010; + +int n, q, res; +pair a[N]; + +int main (int argc, char const *argv[]) { + scanf("%d", &n); + for (int i = 1; i <= n; ++i) + scanf("%d", &a[i].first), a[i].second = i; + BUCKET = sqrt(n); + + for (int i = 1; i <= n; i += BUCKET) + sort(a + i, a + min(n + 1, i + BUCKET)); + + scanf("%d", &q); while (q--) { + int l, r, x; + scanf("%d %d %d", &l, &r, &x); + l ^= res, r ^= res, x ^= res, res = 0; + l = max(l, 1), r = min(r, n); + + int blockL = (l - 1)/BUCKET, blockR = (r - 1)/BUCKET; + int startL = 1 + BUCKET * blockL, startR = 1 + BUCKET * blockR; + + for (int i = startL; i <= min(n, startL + BUCKET - 1); ++i) + if (a[i].second >= l and a[i].second <= r and a[i].first > x) ++res; + + if (blockL != blockR) { + for (int i = startR; i <= min(n, startR + BUCKET - 1); ++i) + if (a[i].second >= l and a[i].second <= r and a[i].first > x) ++res; + + for (int i = blockL + 1; i < blockR; ++i) { + int start = 1 + BUCKET * i; + int tot = upper_bound(a + start, a + start + BUCKET, make_pair(x, n + 1)) - a - start; + res += max(0, BUCKET - tot); + } + } + + printf("%d\n", res); + } + return 0; +} \ No newline at end of file diff --git a/spoj/KQUERYtest b/spoj/KQUERYtest new file mode 100755 index 0000000..453ebd9 Binary files /dev/null and b/spoj/KQUERYtest differ diff --git a/spoj/KQUERYtest.cpp b/spoj/KQUERYtest.cpp new file mode 100644 index 0000000..5171b35 --- /dev/null +++ b/spoj/KQUERYtest.cpp @@ -0,0 +1,78 @@ +#include +#include + +int bit[30005]; +int maxval; + +void update(int id, int val) { + while (id <= maxval) { + bit[id] += val; + id += (id & (-id)); + } +} + +int query(int id) { + int sum = 0; + while (id > 0) { + sum += bit[id]; + id -= (id & (-id)); + } + return sum; +} + +struct kquery { + int i; + int j; + int k; + int num; +} queries[200001]; + +int cmp(const void* a, const void* b) { + struct kquery* x = (struct kquery*) a; + struct kquery* y = (struct kquery*) b; + if (y->k == x->k) + return y->j - x->j; + return (y->k) - (x->k); +} + +struct num { + int val, index; +} arr[30005]; + +int cmp1(const void* a, const void* b) { + struct num* x = (struct num*) a; + struct num* y = (struct num*) b; + return (y->val) - (x->val); +} + +int main(void) { + int n; + scanf("%d", &n); + maxval = n; + int i; + for (i = 0; i < n; i++) { + scanf("%d", &arr[i].val); + arr[i].index = i+1; + bit[i] = 0; + } + qsort(arr, n, sizeof(struct num), cmp1); + int q; + scanf("%d", &q); + int res[q]; + for (i = 0; i < q; i++) { + scanf("%d %d %d", &queries[i].i, &queries[i].j, &queries[i].k); + queries[i].num = i; + } + qsort(queries, q, sizeof(struct kquery), cmp); + int j = 0; + for (i = 0; i < q; i++) { + while (j < n && arr[j].val > queries[i].k) { + update(arr[j].index, 1); + j++; + } + res[queries[i].num] = query(queries[i].j) - query(queries[i].i - 1); + } + for (i = 0; i < q; i++) + printf("%d\n", res[i]); + return 0; +} \ No newline at end of file diff --git a/spoj/LCMSUM b/spoj/LCMSUM new file mode 100755 index 0000000..4b3e251 Binary files /dev/null and b/spoj/LCMSUM differ diff --git a/spoj/LCMSUM.cpp b/spoj/LCMSUM.cpp new file mode 100644 index 0000000..23e1acd --- /dev/null +++ b/spoj/LCMSUM.cpp @@ -0,0 +1,141 @@ +#include +using namespace std; + +long long int s[1000001]={0}; +void fastscan(long long int &number) +{ + //variable to indicate sign of input number + bool negative = false; + register int c; + + number = 0; + + // extract current character from buffer + c = getchar(); + if (c=='-') + { + // number is negative + negative = true; + + // extract the next character from the buffer + c = getchar(); + } + + // Keep on extracting characters if they are integers + // i.e ASCII Value lies from '0'(48) to '9' (57) + for (; (c>47 && c<58); c=getchar()) + number = number *10 + c - 48; + + // if scanned input has a negative sign, negate the + // value of the input number + if (negative) + number *= -1; +} + +void spf(long long int n) +{ + // long long int s[n+1]; + + s[1]=1; + for(long long int i=2;i<=n;i++) + { + if(s[i]==0) + { + s[i]=i; + for(long long int j=2*i;j<=n;j+=i) + { + if(s[j]==0) + { + s[j]=i; + } + } + } + } + // return s; +} + +map primefactorisation(long long int n) +{ + map map; + + int curr=s[n]; + int count=1; + + map.insert(make_pair(1,1)); + while(n>1) + { + n=n/s[n]; + if(curr==s[n]) + { + count++; + continue; + } + map.insert(make_pair(curr,count)); + curr=s[n]; + count=1; + } + return map; +} + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + + long long int t; + fastscan(t); + while(t--) + { + + long long int n; + fastscan(n); + // long long int* s; + spf(n); + + map m; + m=primefactorisation(n); + + mapm1; + map::iterator it; + + long long int sum=0; + /*for(it=m.begin();it!=m.end();++it) + { + cout<first<<" "<second<<"\n"; + }*/ + // cout<<"size of map : "<first<<" "<second<<"\n"; + m1=primefactorisation(i); + for(it=m1.begin();it!=m1.end();++it) + { + // cout<first<<" "<second<<"\n"; + if(!m[it->first]) + { + sum+=n*(pow(it->first,it->second)); + // cout<<"sum : "<first]; + s=m[it->first]; + if((k-s)>0) + { + sum+=n*pow(it->first,(k-s)); + // cout<<"sum : "< +using namespace std; + +long long int res[1000010]; +long long int phi[1000010]; + +void precal(int n) +{ + for(long long i=1;i<=n;i++) + { + phi[i]=i; + } + for(long long i=2;i<=n;i++) + { + if(phi[i]==i) + { + for(int j=i;j<=n;j+=i) + { + phi[j]/=i; + phi[j]*=i-1; + + // cout<<"i = "< +using namespace std; +#define ll long long +#define SIZE 1050 + +ll BIT[SIZE][SIZE]; +int R,C; + +void update(int x,int y,int val) +{ + int x1,y1; + for(x1=x; x1<=R; x1+=x1&-x1) + { + for(y1=y; y1<=C; y1+= y1&-y1) + { + BIT[x1][y1]+=val; + } + } +} + +ll query(int x,int y) +{ + ll sum=0; + int x1,y1; + for(x1=x;x1>0;x1-=x1&-x1) + { + for(y1=y;y1>0;y1-=y1&-y1) + { + sum+=BIT[x1][y1]; + } + } + return sum; +} + +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + int n; + scanf("%d",&n); + R=n; + C=n; + memset(BIT,0,sizeof(BIT)); + // memset(data,0,sizeof(data)); + + while(true) + { + char s[50]; + scanf("%s",s); + if(s[1]=='E') + { + int x,y; + int num; + scanf("%d %d %d", &x,&y,&num); + x++; + y++; + ll previous=query(x,y)-query(x,y-1)-query(x-1,y)+query(x-1,y-1); + update(x,y,num-previous); + } + else if(s[1]=='U') + { + int x1,x2,y1,y2; + ll ans=0; + scanf("%d %d %d %d",&x1,&y1,&x2,&y2); + x1++; + x2++; + y1++; + y2++; + ans=query(x2,y2)-query(x2,y1-1)-query(x1-1,y2)+query(x1-1,y1-1); + printf("%lld\n", ans); + } + else + { + break; + } + } + printf("\n"); + } + return 0; +} \ No newline at end of file diff --git a/spoj/MATSUMtest b/spoj/MATSUMtest new file mode 100755 index 0000000..50334fa Binary files /dev/null and b/spoj/MATSUMtest differ diff --git a/spoj/MATSUMtest.cpp b/spoj/MATSUMtest.cpp new file mode 100644 index 0000000..407cc52 --- /dev/null +++ b/spoj/MATSUMtest.cpp @@ -0,0 +1,68 @@ +#include +using namespace std; +#define LL long long +LL tree[1050][1050]; +void update(int x,int y,int val,int MAX) +{ + while(x<=MAX) + { + int ty = y; + while(ty <= MAX) + { + tree[x][ty] += val; + ty += (ty & -ty); + } + x += (x & -x); + } +} +LL read(int x,int y) +{ + LL sum = 0; + while( x ) + { + int ty = y; + while( ty ) + { + sum += tree[x][ty]; + ty -= (ty & -ty); + } + x -= (x & -x); + } + return sum; +} +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + int n; + scanf("%d",&n); + memset(tree,0,sizeof tree); + while(1) + { + char s[10]; + scanf("%s",s); + if(s[1] == 'E'){ + int x,y,val; + scanf(" %d%d%d",&x,&y,&val); + LL p_val = read(x+1,y+1) + read(x,y) - read(x+1,y) - read(x,y+1); + update(x+1,y+1,val - p_val,n+9); + } + else if(s[1] == 'U') + { + LL sum = 0; + int x1,y1,x,y; + scanf(" %d%d%d%d",&x,&y,&x1,&y1); + sum = read(x1+1,y1+1) + read(x,y) - read(x,y1+1) - read(x1+1 , y); + printf("%lld\n",sum); + } + else{ + //printf("\n"); + break; + } + } + printf("\n"); + } + return 0; +} diff --git a/spoj/MCHAOS b/spoj/MCHAOS new file mode 100755 index 0000000..ce82d17 Binary files /dev/null and b/spoj/MCHAOS differ diff --git a/spoj/MCHAOS.cpp b/spoj/MCHAOS.cpp new file mode 100644 index 0000000..7e3a452 --- /dev/null +++ b/spoj/MCHAOS.cpp @@ -0,0 +1,92 @@ +/*why use BIT? + +1. time limit is pretty small +2. the strings are atmost of 10 letters +3. we can see that we need to find inverses +*/ + +#include +using namespace std; +#define ll long long + +ll n; +ll BIT[100000]; + +vector >v; +vector a; + +long long func(string &st) +{ + long long res = 0; + for (int i = 0; i < st.size(); i++) + { + res = res * 32 + st[i] - 'a' + 1; + } + for (int i = st.size(); i <= 10; i++) + res = res * 32; + return res; +} + +/*bool comp(const pair &p, const pair &q) +{ + return p.first0;x-=x&-x) + { + sum+=BIT[x]; + } + return sum; +} + +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + + // ll n; + cin>>n; + + string s,r; + for(int i=0;i>r; + s=r; + reverse(r.begin(),r.end()); + v.push_back(make_pair(func(s),func(r))); + a.push_back(v[i].second); + } + + sort(v.begin(),v.end()); + sort(a.begin(),a.end()); + + for(int i=0;i=0;i--) + { + inverses+=sum(v[i].second-1); + update(v[i].second,1); + } + printf("%lld\n", inverses); +} \ No newline at end of file diff --git a/spoj/MCHAOStest b/spoj/MCHAOStest new file mode 100755 index 0000000..0753507 Binary files /dev/null and b/spoj/MCHAOStest differ diff --git a/spoj/MCHAOStest.cpp b/spoj/MCHAOStest.cpp new file mode 100644 index 0000000..1b4ae35 --- /dev/null +++ b/spoj/MCHAOStest.cpp @@ -0,0 +1,78 @@ +#include + +using namespace std; + +const int N = 100000; + +int n; +string st; +vector > v; +vector nd; + +int t[N]; + +long long func(string &st) +{ + long long res = 0; + for (int i = 0; i < st.size(); i++) + { + res = res * 32 + st[i] - 'a' + 1; + } + for (int i = st.size(); i <= 10; i++) + res = res * 32; + return res; +} + +int sum(int r) +{ + int res = 0; + for (; r >= 0; r = (r&(r + 1)) - 1) + res += t[r]; + return res; +} + +void inc(int i, int delta) +{ + for (; i < n; i = (i | (i + 1))) + t[i] += delta; +} + +inline void parse(string &st,pair&res) +{ + res.first = func(st); + reverse(st.begin(), st.end()); + res.second = func(st); +} + +int main(){ + ios_base::sync_with_stdio(0); + //cin.tie(0); + + cin >> n; + pair P; + + for (int i = 1; i <= n; i++) + { + cin >> st; + parse(st,P); + v.push_back(P); + nd.push_back(P.second); + } + + sort(nd.begin(), nd.end()); + + sort(v.begin(), v.end()); + + long long ans = 0; + + for (int i = v.size() - 1; i >= 0; i--) + { + int whr = lower_bound(nd.begin(), nd.end(), v[i].second) - nd.begin(); + ans += sum(whr); + inc(whr, 1); + } + + cout << ans << endl; + + return 0; +} \ No newline at end of file diff --git a/spoj/MSE06H b/spoj/MSE06H new file mode 100755 index 0000000..0c59922 Binary files /dev/null and b/spoj/MSE06H differ diff --git a/spoj/MSE06H.cpp b/spoj/MSE06H.cpp new file mode 100644 index 0000000..f8b12cd --- /dev/null +++ b/spoj/MSE06H.cpp @@ -0,0 +1,62 @@ +#include +using namespace std; + +long long n,m,k; +long long BIT[1009]; + +struct node{ + long long first; + long long second; +}; + +node arr[1000009]; + +bool compare(const node a, const node b) +{ + return ((a.first==b.first)? (a.second < b.second) : (a.first < b.first)); +} + +void update(long long x,long long val) +{ + for(;x<=m;x+= x&-x) + { + BIT[x]+=val; + } +} + +long long query(long long x) +{ + long long sum=0; + for(;x>0;x-= x&-x) + { + sum+=BIT[x]; + } + return sum; +} + +int main() +{ + long long i,j,t,count=1,ans; + scanf("%lld", &t); + while(t--) + { + memset(BIT,0,sizeof(BIT)); + scanf("%lld %lld %lld", &n, &m, &k); + + for(i=0;i= 0; i = j) + { + for(j = i; j >= 0 && arr[j].first == arr[i].first; j--) ans += query(arr[j].second - 1); + for(j = i; j >= 0 && arr[j].first == arr[i].first; j--) update(arr[j].second, 1); + } + // count++; + printf("Test case %lld: %lld\n",count++, ans); + } + return 0; +} \ No newline at end of file diff --git a/spoj/MSE06Htest b/spoj/MSE06Htest new file mode 100755 index 0000000..6ed2754 Binary files /dev/null and b/spoj/MSE06Htest differ diff --git a/spoj/MSE06Htest.cpp b/spoj/MSE06Htest.cpp new file mode 100644 index 0000000..5493dce --- /dev/null +++ b/spoj/MSE06Htest.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +using namespace std; + +typedef long long i64; +const int RMAX = 1000009; +const int NMAX = 1009; + +struct Road { int u, v; }; + +i64 BIT[NMAX], m, n,k; +Road roads[RMAX]; + +i64 read(int idx) { + i64 sum = 0; + while(idx > 0) { + sum += BIT[idx]; + idx -= (idx & -idx); + } + return sum; +} + +void add(int idx, int v) { + while(idx <= m) { + BIT[idx] += v; + idx += (idx & -idx); + } +} + +bool comp(const Road a, const Road b) { + return ((a.u==b.u)? (a.v < b.v) : (a.u < b.u)); +} + +int main() { + int t, i, j, cs = 1; + i64 res; + scanf("%d", &t); + while(t--) { + memset(BIT, 0, sizeof(BIT)); + res = 0; + scanf("%lld%lld%lld", &n, &m, &k); + for(i = 0; i < k; i++) scanf("%d%d", &roads[i].u, &roads[i].v); + sort(roads, roads + k, comp); + for(i = k-1; i >= 0; i = j) { + for(j = i; j >= 0 && roads[j].u == roads[i].u; j--) res += read(roads[j].v - 1); + for(j = i; j >= 0 && roads[j].u == roads[i].u; j--) add(roads[j].v, 1); + } + printf("Test case %d: %lld\n", cs++, res); + } + return 0; +} \ No newline at end of file diff --git a/spoj/Max_And b/spoj/Max_And new file mode 100755 index 0000000..596738b Binary files /dev/null and b/spoj/Max_And differ diff --git a/spoj/Max_And.cpp b/spoj/Max_And.cpp new file mode 100644 index 0000000..f84edf8 --- /dev/null +++ b/spoj/Max_And.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; +#define ll long long +int main() +{ + int t; + scanf("%d", &t); + + while(t--) + { + ll a, b; + scanf("%lld %lld", &a, &b); + + if(b&1) + { + printf("%lld\n",b-1); + } + else + { + printf("%lld\n",b-2); + } + } +} \ No newline at end of file diff --git a/spoj/Max_Power b/spoj/Max_Power new file mode 100755 index 0000000..2f02ff3 Binary files /dev/null and b/spoj/Max_Power differ diff --git a/spoj/Max_Power.cpp b/spoj/Max_Power.cpp new file mode 100644 index 0000000..1167ae0 --- /dev/null +++ b/spoj/Max_Power.cpp @@ -0,0 +1,30 @@ +#include +using namespace std; +#define ll long long + +int main() +{ + int t; + + scanf("%d", &t); + + while(t--) + { + ll x,y; + scanf("%lld %lld", &x, &y); + + if((x&1) && (y&1)) //both odd + { + printf("2\n"); + } + else if((x&1 && y&1==0) || (y&1 && x&1==0)) //one even one odd + { + printf("4\n"); + } + else //both even + { + printf("4\n"); + } + } + return 0; +} \ No newline at end of file diff --git a/spoj/Max_Product b/spoj/Max_Product new file mode 100755 index 0000000..464daee Binary files /dev/null and b/spoj/Max_Product differ diff --git a/spoj/Max_Product.cpp b/spoj/Max_Product.cpp new file mode 100644 index 0000000..159d693 --- /dev/null +++ b/spoj/Max_Product.cpp @@ -0,0 +1,38 @@ +#include +using namespace std; +#define ll long long + +int main() +{ + int t; + + scanf("%d", &t); + + while(t--) + { + int x,k; + + scanf("%d %d", &x, &k); + + int a=x/k; + int rem=x%k; + + ll prod=1; + + while(k--) + { + if(rem) + { + prod=(prod*(a+1))%100000007; + rem--; + } + else + { + prod=(prod*(a))%100000007; + } + } + + printf("%lld\n",prod); + + } +} \ No newline at end of file diff --git a/spoj/Max_Sum b/spoj/Max_Sum new file mode 100755 index 0000000..8cf30be Binary files /dev/null and b/spoj/Max_Sum differ diff --git a/spoj/Max_Sum.cpp b/spoj/Max_Sum.cpp new file mode 100644 index 0000000..3c318c4 --- /dev/null +++ b/spoj/Max_Sum.cpp @@ -0,0 +1,92 @@ +#include +using namespace std; +#define ll long long + + +ll sieve[100000005]; + + +void sievefunc() +{ + for(ll i=2;i<=100000000;i++) + { + if(sieve[i]==0) + { + // sieve[i]=i; + for(ll j=i;j*j<=100000000;j+=i) + { + if(sieve[j]==0) + sieve[j]=i; + } + } + } +} + +vector primefactors(int n) +{ + vector v; + ll k=sieve[n]; + + v.push_back(k); + + while(n!=k) + { + n/=k; + k=sieve[n]; + v.push_back(k); + } + return v; +} + +int main() +{ + sievefunc(); + int t; + scanf("%d", &t); + + while(t--) + { + ll x; + ll k; + ll sum=0; + + scanf("%lld %lld",&x,&k); + + if(k==1) + { + printf("%lld\n", x); + } + else if(sieve[x]==x && k>1) + { + printf("-1\n"); + } + else if(k>x) + { + printf("-1\n"); + } + else + { + vector v=primefactors(x); + + /*for(int i=0;iv.size()) + printf("-1\n"); + else + { + + for(int i=0;i<(k-1);i++) + { + sum+=v[i]; + x/=v[i]; + } + if(x!=1) + sum+=x; + printf("%lld\n", sum); + } + } + } + return 0; +} \ No newline at end of file diff --git a/spoj/Modular_GCD b/spoj/Modular_GCD new file mode 100755 index 0000000..eeef9b7 Binary files /dev/null and b/spoj/Modular_GCD differ diff --git a/spoj/Modular_GCD.cpp b/spoj/Modular_GCD.cpp new file mode 100644 index 0000000..bb01976 --- /dev/null +++ b/spoj/Modular_GCD.cpp @@ -0,0 +1,50 @@ +#include +using namespace std; +#define ll long long +const int M = 1e9+7; +ll A,B,N,d,x,y; + +ll prod(ll a,ll b,ll m) //returns (a*b)%m +{ + ll res=0; + while(b) + { + if(b&1) + res=(res+a)%m; + a=(a+a)%m; + b>>=1; + } + return res; +} + +ll funcpow(ll a, ll b, ll mod=M) // returns (a^b) +{ + ll res=1; + while(b) + { + if(b&1) + res=prod(res, a, mod); + a=prod(a, a, mod); + b>>=1; + } + return res; +} + +int main() +{ + int t; + scanf("%d", &t); + while(t--) + { + scanf("%lld %lld %lld", &A, &B, &N); + if(A==B) + { + cout<<(funcpow(A,N)+funcpow(B,N))%M< +using namespace std; +// #define MAX 100005 +int m,n; //matrix of m by n +char a[105][105]; +int vis[105][105]; +int dist[105][105]; + +struct coordinate +{ + int row; + int column; +}; + +coordinate start; +coordinate dest; + +int X[]={1,0,0,-1}; +int Y[]={0,1,-1,0}; + +bool safe(int x, int y) +{ + if (x > m || y> n || x<1 || y<1) + return false; + if (a[x][y] == '*') + return false; + return true; +} + +int bfs() +{ + queueq; + q.push(start); + + dist[start.row][start.column]=0; + vis[start.row][start.column]=1; + + while(!q.empty()) + { + coordinate k=q.front(); + q.pop(); + // vis[k.row][k.column]=1; + + for(int i=0;i<4;i++) + { + int x=k.row+X[i]; + int y=k.column+Y[i]; + + if(safe(x,y)) + { + if(vis[x][y]) + continue; + + // printf("%d %d\n",x,y); + + vis[x][y]=1; + dist[x][y]=dist[k.row][k.column]+1; + q.push((coordinate){x,y}); + } + } + } + + if(dist[dest.row][dest.column]!=0) + return dist[dest.row][dest.column]; + else + return -1; + // return dist[end.row][end.column]; +} + +int main() +{ + int t; + scanf("%d",&t); + + while(t--) + { + memset(vis,0,sizeof(vis)); + memset(a,0,sizeof(a)); + memset(dist,0,sizeof(dist)); + scanf("%d %d",&m,&n); + for(int i=1;i<=m;i++) + { + for (int j=1;j<=n;j++) + { + /* code */ + cin>>a[i][j]; + if(a[i][j]=='$') + { + start.row=i; + start.column=j; + } + if(a[i][j]=='#') + { + dest.row=i; + dest.column=j; + } + } + } + + int count = bfs(); + printf("%d\n", count); + } +} \ No newline at end of file diff --git a/spoj/NATALIAGtest b/spoj/NATALIAGtest new file mode 100755 index 0000000..f073787 Binary files /dev/null and b/spoj/NATALIAGtest differ diff --git a/spoj/NATALIAGtest.cpp b/spoj/NATALIAGtest.cpp new file mode 100644 index 0000000..a944518 --- /dev/null +++ b/spoj/NATALIAGtest.cpp @@ -0,0 +1,83 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#define INF 100000000 +#define in_range(x, y, r, c) (x >= 0 && x < r && y >= 0 && y < c) + +typedef long long int LLD; +typedef unsigned long long int LLU; + +using namespace std; + +char mat[100][100]; +int dis[100][100]; + +void init(int r, int c){ + for(int i=0;i q; + int a[] = {-1, 0, 1, 0}, b[] = {0, 1, 0, -1}; + q.push(sx); + q.push(sy); + dis[sx][sy] = 0; + while(!q.empty()){ + int x = q.front(); + q.pop(); + int y = q.front(); + q.pop(); + if(x == ex && y == ey) + return dis[x][y]; + for(int i=0;i<4;i++){ + int tx = x + a[i]; + int ty = y + b[i]; + if(in_range(tx, ty, r, c) && mat[tx][ty] != '*' && dis[tx][ty] > dis[x][y] + 1){ + dis[tx][ty] = dis[x][y] + 1; + q.push(tx); + q.push(ty); + } + } + } + return -1; +} + +int main(){ + + int t, r, c, sx, sy, ex, ey; + scanf("%d", &t); + while(t--){ + scanf("%d%d", &r, &c); + init(r, c); + for(int i=0;i> mat[i][j]; + if(mat[i][j] == '$'){ + sx = i; + sy = j; + } + if(mat[i][j] == '#'){ + ex = i; + ey = j; + } + } + } + printf("%d\n", bfs(sx, sy, ex, ey, r, c)); + } + return 0; +} \ No newline at end of file diff --git a/spoj/NINJA7 b/spoj/NINJA7 new file mode 100755 index 0000000..4c9a4e9 Binary files /dev/null and b/spoj/NINJA7 differ diff --git a/spoj/NINJA7.cpp b/spoj/NINJA7.cpp new file mode 100644 index 0000000..687a810 --- /dev/null +++ b/spoj/NINJA7.cpp @@ -0,0 +1,101 @@ +#include +using namespace std; + +long long int limit; +// vector dp; + +void solve(long long int mask,long long int *arr,long long int *arr1) +{ + // cout<>t; + while(t--) + { + long long int n=0; + cin>>n; + long long a[n],b[n]; + limit=(1<>a[i]; + } + + for(long long int i=0;i>b[i]; + } + + /*for(int i=0;i=0;k--) + { + if(a1[k]>=b1[k]) + break; + } + + long long int count=0; + + for(long long int i=0;i +using namespace std; + +#define size 100025 + +vector< long long int> active; +int a[size],b[size]; + +int main() +{ + ios_base::sync_with_stdio(0); + cin.tie(0); + int t; + cin>>t; + + while(t--) + { + int n; + cin>>n; + for(int i=0;i>a[i]; + } + + for(int i=0;i>b[i]; + } + active.clear(); + + long long int sum=0,length=0,d; + + for(int i=0;i0) + { + length++; + sum+=d; + } + else active.push_back(-d); + } + + sort(active.begin(),active.end()); + + for(int i:active) + { + if(i>sum) + break; + length++; + sum-=i; + } + cout< +using namespace std; + +int main() +{ + int t; + scanf("%d",&t); + + while(t--) + { + int n,m; + scanf("%d %d",&n,&m); + + printf("%d\n",2*n*m-(n+m)); + } +} \ No newline at end of file diff --git a/spoj/ORDERSET b/spoj/ORDERSET new file mode 100755 index 0000000..59bc1eb Binary files /dev/null and b/spoj/ORDERSET differ diff --git a/spoj/ORDERSET.cpp b/spoj/ORDERSET.cpp new file mode 100644 index 0000000..5058286 --- /dev/null +++ b/spoj/ORDERSET.cpp @@ -0,0 +1,133 @@ +#include +#include +using namespace std; +#define ll long long + +unordered_map m; +vector > v; //storing pair of values of character and x +vector a; //storing the x for every query in sorted manner +vector bit(200001,0); + +void update(int x,int val,int n) //sets the BIT[x] to number of numbers less than x +{ + for(;x<=n;x+= x&-x) + { + bit[x]+=val; + } +} + + +int query(int x) //returns the number of elements smaller than any x +{ + int sum=0; + for(;x>0;x-= x&-x) + { + sum+=bit[x]; + } + return sum; +} + + +int search(int val) //doing a binary search in a for the val-th smallest element +{ + int x,y,z,ans=a.size(); + x=0; + y=a.size()-1; + while(x<=y){ + + z=(x+y)/2; + + if(query(m[a[z]])>=val){ + ans=z; + y=z-1; + } + else + { + x=z+1; + } + } + return ans; +} + +int main() +{ + int q; + int x,j; + scanf("%d", &q); + char ch; + + v.clear(); + a.clear(); + m.clear(); + + for(int i=0;i>ch; + scanf("%d",&x); + v.push_back(make_pair(ch,x)); //making a vector storing every query pair + m[x]=1; //marking all the coordinates to 1 initially + } + + for(auto u:m) + { + // cout< +#include +using namespace std; + +#define pb(x) push_back(x) +#define mk(x,y) make_pair(x,y) + +vector > v; +unordered_map m; +vector bit(200001,0); +vector a; + +void insert(int val,int x,int n){ + if(x>n) + return ; + + bit[x]+=val; + insert(val,x+ (x&(-x)),n); +} + +int query(int x) //returns the sum of first x elements in given array a[] +{ + int sum = 0; + for(; x > 0; x -= x&-x) + sum += bit[x]; + return sum; +} + +int search(int val){ + int i,j,k,x,y,z,ans=a.size(); + + x=0,y=a.size()-1; + while(x<=y){ + + z=(x+y)/2; + + if(query(m[a[z]])>=val){ + ans=z; + y=z-1; + }else{ + x=z+1; + } + } + + return ans; +} + +int main(){ + int i,j,k,x,y,z,n; + scanf("%d",&n); + + v.clear(); + a.clear(); + m.clear(); + + char c; + for(i=0;i>c; + scanf("%d",&j); + v.pb(mk(c,j)); + m[j]=1; + } + + for(auto u:m){ + a.push_back(u.first); + } + + sort(a.begin(),a.end()); + + for(i=0;i +using namespace std; + +int n,m; +int a[1005][1005]; +int row[1005]; +int column[1005]; +int res[1005][1005]; +int main() +{ + int t; + scanf("%d",&t); + while(t--) + { + memset(a,0,sizeof(a)); + memset(row,0,sizeof(a)); + memset(column,0,sizeof(a)); + memset(res,0,sizeof(a)); + + + scanf("%d %d",&n,&m); + + for(int i=0;i +using namespace std; +#define ll long long + +ll n; +const int maxn=4e4+7; +vector > points(maxn); +map compress; + +int tree[4*maxn]; +int lazy[4*maxn]; + +void update(int node, int start ,int end , int l, int r, int val) +{ + if(lazy[node]) + { + tree[node]=lazy[node]; + if(start!=end) + { + lazy[2*node]=lazy[node]; + lazy[2*node+1]=lazy[node]; + } + lazy[node]=0; + } + + if(start>r || end>1; + update(2*node,start,mid,l,r,val); + update(2*node+1, mid+1,end,l,r,val); + tree[node]=val; +} + +int query(int node, int start, int end, int l, int r) +{ + if(lazy[node]) + { + tree[node]=lazy[node]; + if(start!=end) + { + lazy[2*node]=lazy[node]; + lazy[2*node+1]=lazy[node]; + } + lazy[node]=0; + } + + if(start>r || end>1; + + return max(query(2*node,start,mid,l,r),query(2*node+1,mid+1,end, l,r)); +} + + +int main() +{ + ll t; + cin>>t; + while(t--) + { + compress.clear(); + points.clear(); + + memset(tree,0,sizeof(tree)); + memset(lazy,0,sizeof(lazy)); + + scanf("%lld", &n); + for(int i=0;i ans; + for(int i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long ll; +typedef unsigned long long ull; +typedef long double ld; +typedef pair pii; +typedef pair pll; +typedef vector vi; +typedef vector vll; +#define l(x) (x << 1) + 1 +#define r(x) (x << 1) + 2 +#define mid(l, r) ((l + r) >> 1) +#define mp make_pair +#define pb push_back +#define all(a) a.begin(),a.end() +#define debug(x) {cerr <<#x<<" = " < +inline bool ispow2(T x){return (x!=0 && (x&(x-1))==0);} //0 or 1 + +template inline T powmod(T a,T b,T mod) {ll res = 1; while(b){if(b&1) res = (res*a)%mod;a = (a*a)%mod;b >>= 1;}return res;} +template inline T gcd(T a,T b){ll t;while(b){a=a%b;t=a;a=b;b=t;}return a;} +template inline T lcm(T a,T b){return a/gcd(a,b)*b;} + +inline int nextint(){ int x; scanf("%d",&x); return x; } +inline ll nextll(){ ll x; scanf("%lld",&x); return x; } + +const int mod=1e9+7; + +const ll mx_ll = numeric_limits :: max(); +const int mx_int = numeric_limits :: max(); + +const long double PI = (long double)(3.1415926535897932384626433832795); + +const int maxn = 4e4+7; +vector points(maxn); +map compress; + +int tree[4*maxn]; +int lazy[4*maxn]; + +void range_update(int node ,int left, int right ,int lq ,int rq , int val) +{ + if(lazy[node]) + { + tree[node] = lazy[node]; + if(left != right) + { + lazy[2*node] = lazy[node]; + lazy[2*node+1] = lazy[node]; + } + lazy[node] = 0; + } + if(left > rq || right < lq) + return ; + if(left >= lq && right <= rq) + { + tree[node] = val; + if(left != right) + { + lazy[2*node] = val; + lazy[2*node+1] = val; + } + lazy[node] = 0; + return; + } + int mid = mid(left, right); + range_update(2*node, left , mid , lq ,rq, val); + range_update(2*node+1,mid+1,right, lq ,rq, val); + tree[node] = val; +} + + +int query(int node ,int left ,int right ,int lq,int rq) +{ + if(lazy[node]) + { + tree[node] = lazy[node]; + if(left != right) + { + lazy[2*node] = lazy[node]; + lazy[2*node+1] = lazy[node]; + } + lazy[node] = 0; + } + if(left > rq || right < lq) + return -1; + if(left >= lq && right <= rq) + { + return tree[node]; + } + int mid = mid(left, right); + return max(query(2*node, left , mid , lq ,rq),query(2*node+1,mid+1,right, lq ,rq)); +} + +int main() +{ + int t; scanf("%d",&t); + while(t--) + { + compress.clear(); + points.clear(); + for(int i = 0; i < 4*maxn;i++) + tree[i] = lazy[i] = 0; + + int n ; + scanf("%d",&n); + for(int i = 0; i < n; i++) + { + scanf("%d%d",&points[i].ff,&points[i].ss); + compress[points[i].ff] = compress[points[i].ss] = 1; + } + int a = 0; + for(auto &x: compress) + x.ss = a++; + + for(int i = 0; i < n; i++) + { + range_update(1,0,maxn-1,compress[points[i].ff] ,compress[points[i].ss],i+1); + } + set ans; + for(int i = 0; i < maxn-1; i++) + { + ans.insert(query(1,0,maxn-1,i,i)); + } + int k = ans.size(); + if(ans.find(0) != ans.end()) + k--; + printf("%d\n",k); + } + return 0; +} \ No newline at end of file diff --git a/spoj/PPATH b/spoj/PPATH new file mode 100755 index 0000000..72b2443 Binary files /dev/null and b/spoj/PPATH differ diff --git a/spoj/PPATH.cpp b/spoj/PPATH.cpp new file mode 100644 index 0000000..2c91a2c --- /dev/null +++ b/spoj/PPATH.cpp @@ -0,0 +1,162 @@ +#include +using namespace std; + +bool vis[10010]; +queue >q; +bool p[10001]; + +void clear( queue >&q ) +{ + queue > empty; + swap( q, empty ); +} + +void isprime() +{ + p[0]=false; + p[1]=false; + for(int i=2;i<=10000;i++) + { + p[i]=true; + } + for(int i=2;i<=10000;i++) + { + if(p[i]) + { + for(int j=2*i;j<=10000;j+=i) + { + p[j]=false; + } + } + } +} + + +long long convert(int number,int position,int value) +{ + int ones=number%10; + number/=10; + int tens=number%10; + number/=10; + int hunderds=number%10; + number/=10; + int thousands=number%10; + + if(position==1) + { + return (thousands*1000 + hunderds*100 + tens*10 + value); + } + + if(position==2) + { + return (thousands*1000 + hunderds*100 + value*10 + ones); + } + + if(position==3) + { + return (thousands*1000 + value*100 + tens*10 + ones); + } + + if(position==4) + { + return (value*1000 + hunderds*100 + tens*10 + ones); + } +} + + +long long bfs(int start,int l,int dest) +{ + vis[start]=true; + q.push(make_pair(start,l)); + int flag=0; + + while(!q.empty()) + { + int number=q.front().first; + int level=q.front().second; + q.pop(); + if(number==dest) + { + flag=1; + return level; + + } + + for(int i=0;i<10;i++) + { + long long n1,n2,n3,n4; + //thousands place + if(i>0) + { + n4=convert(number,4,i); + if(p[n4] && !vis[n4]) + { + vis[n4]=true; + q.push(make_pair(n4,level+1)); + } + } + + //hundereds place + + n3=convert(number,3,i); + if(p[n3] && !vis[n3]) + { + vis[n3]=true; + q.push(make_pair(n3,level+1)); + } + + //tens place + + n2=convert(number,2,i); + if(p[n2] && !vis[n2]) + { + vis[n2]=true; + q.push(make_pair(n2,level+1)); + } + + //ones place + n1=convert(number,1,i); + if(p[n1] && !vis[n1]) + { + vis[n1]=true; + q.push(make_pair(n1,level+1)); + } + + } + + } + if(flag==0) + { + return -1; + } +} + +int main() +{ + isprime(); + + int t; + cin>>t; + while(t--) + { + clear(q); + int s,d; + cin>>s>>d; + memset(vis,false,sizeof(vis)); + + /*for(int i=0;i<10000;i++) + { + cout<=0) + { + cout< +using namespace std; + +int n,m; +int arr[10005]; +int size[10005]; + +int root(int x) +{ + while(arr[x]!=x) + { + arr[x]=arr[arr[x]]; //path compression + x=arr[x]; + } + return x; +} + +void weighted_union(int a, int b) +{ + int root_a=root(a); + int root_b=root(b); + + if(size[root_a]=size[root_b]) + { + arr[root_b]=arr[root_a]; + size[root_a]+=size[root_b]; + } + return; +} + +bool find(int x, int y) +{ + if(root(x)==root(y)) + { + return true; + } + else + { + return false; + } +} + +int main() +{ + scanf("%d %d", &n, &m); + + // bool flag=false; + + for(int i=0;i +using namespace std; + +int main() +{ + int t; + scanf("%d", &t); + + while(t--) + { + int N,P; + + + } +} \ No newline at end of file diff --git a/spoj/Problem_sort b/spoj/Problem_sort new file mode 100755 index 0000000..61ef6f2 Binary files /dev/null and b/spoj/Problem_sort differ diff --git a/spoj/Problem_sort.cpp b/spoj/Problem_sort.cpp new file mode 100644 index 0000000..39e886f --- /dev/null +++ b/spoj/Problem_sort.cpp @@ -0,0 +1,98 @@ +#include +using namespace std; + +/*struct elements +{ + int score[35]; + int number[35]; + int count; + int index; +}; + +elements a[100005];*/ + +vector >problem; +vector >cnt; + +/*bool cmp(int a, int b) +{ + return aproblem[j+1].second) + count++; + } + problem.clear(); + cnt.push_back(make_pair(count, i)); + } + sort(cnt.begin(), cnt.end()); + + // for(int i=1;i<=p;i++) + + /*for(int i=1;i<=p;i++) + { + for(int j=1;j<=s;j++) + { + printf("%d ", a[i].score[j]); + } + printf("\n"); + }*/ + + /*int temp; + + for(int i=1;i<=p;i++) + { + // printf("here\n"); + for(int j=1;j<=s-1;j++) + { + if(problem[i].second>problem[i].second) + { + // printf("here\n"); + a[i].count++; + } + } + }*/ + + /*for(int i=1;i<=p;i++) + { + for(int j=1;j<=s;j++) + { + printf("%d ", a[i].number[j]); + } + printf("\n"); + }*/ + + // sort(a+1, a+p+1, cmp1); + + vector >::iterator it=cnt.begin(); + for( ;it!=cnt.end();it++) + { + printf("%d\n", (*it).second); + } + + return 0; +} \ No newline at end of file diff --git a/spoj/RMQ b/spoj/RMQ new file mode 100755 index 0000000..95f9adc Binary files /dev/null and b/spoj/RMQ differ diff --git a/spoj/RMQ.cpp b/spoj/RMQ.cpp new file mode 100644 index 0000000..60d4c30 --- /dev/null +++ b/spoj/RMQ.cpp @@ -0,0 +1,111 @@ +//segment tree implementation +#include +using namespace std; +#define INF 100005 +#define ll long long + +int tree[400005]; +int a[100005]; + +void build(int node,int start,int end) +{ + + if(start==end) + { + tree[node]=a[start]; + } + + else + { + int mid=(start+end)/2; + build(2*node,start,mid); + build(2*node+1,mid+1,end); + if(tree[2*node]>=INF) + { + tree[node]=tree[2*node+1]; + } + else if(tree[2*node+1]>=INF) + { + tree[node]=tree[2*node]; + } + else + tree[node]=min(tree[2*node],tree[2*node+1]); + } +} + +void update(int node,int start,int end,int x,int val) +{ + if(start==end) + { + a[x]=val; + tree[node]=val; + } + else + { + int mid=(start+end)/2; + if(start<=x && x<=mid) + { + update(2*node,start,mid,x,val); + } + else + { + update(2*node+1,mid+1,end,x,val); + } + tree[node]=min(tree[2*node],tree[2*node+1]); + } +} + +int query(int node,int start,int end,int l,int r) +{ + if(r>n>>q; + + // int a[n]; + + for(int i=1;i<=n;i++) + { + cin>>a[i]; + } + memset(tree,INF,sizeof(tree)); + build(1,1,n); + + char c; + int x,y; + + /*for(int i=1;i<=2*n-1;i++) + { + cout<>c>>x>>y; + if(c=='q') + { + int min=query(1,1,n,x,y); + cout< +using namespace std; +#define ll long long +#define INF 210 +ll a[205][205]; +ll b[205][205]; +ll mask[205][205]; +int main() +{ + ll t; + scanf("%lld",&t); + while(t--) + { + ll n; + scanf("%lld",&n); + + memset(a,INF,sizeof(a)); + memset(mask,0,sizeof(mask)); + for(ll i=1;i<=n;i++) + { + for(ll j=1;j<=n;j++) + { + ll k; + scanf("%lld",&k); + b[i][j]=a[i][j]=k; + } + } + + for(ll k=1;k<=n;k++) + { + for(ll i=1;i<=n;i++) + { + for(ll j=1;j<=n;j++) + { + if(a[i][j]==a[i][k]+a[k][j] && k!=i && k!=j) + mask[i][j]=1; + + if(a[i][j]>a[i][k]+a[k][j]) + { + a[i][j]=a[i][k]+a[k][j]; + } + } + } + } + + //how to print?? + + for(ll i=1;i<=n;i++) + { + for(ll j=1;j<=n;j++) + { + if(a[i][j] + +using namespace std; + +int main(){ + int t,n; + bool check; + int M[200][200]; + + scanf("%d",&t); + + for(int tc=1;tc<=t;tc++){ + scanf("%d",&n); + + for(int i=0;i +using namespace std; + +#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) +#define debug(x) do { std::cerr << #x << ": " << x << std::endl; } while (0) +#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) + +#define ll long long + +ll n; + +int32_t main() +{ + +} diff --git a/spoj/Random_function b/spoj/Random_function new file mode 100755 index 0000000..507c182 Binary files /dev/null and b/spoj/Random_function differ diff --git a/spoj/Random_function.cpp b/spoj/Random_function.cpp new file mode 100644 index 0000000..3e16d73 --- /dev/null +++ b/spoj/Random_function.cpp @@ -0,0 +1,25 @@ +#include +using namespace std; +#define ll long long +int main() +{ + ofstream of; + of.open("AMANPNT Input file #2"); + of<<"100\n"; + for(int i=0;i<100;i++) + { + ll n=rand()%10000 + 2 ; + ll m=rand()%10000 + 1; + of< +using namespace std; +#define ll long long +int main() +{ + ofstream of; + of.open("KAUSANDNIHA Input file #1"); + of<<"10\n"; + for(int i=0;i<10;i++) + { + ll n=rand()%100 + 2 ; + ll m=rand()%100 + 1; + of< +int main() +{ int t,sum=0,n; + std::cin>>t; + while(t--) + { + std::cin>>n; + if(n>0) + sum+=n; + } + std::cout< +using namespace std; +#define SIZE 1000005 +int n; +string s; + +struct trees +{ + int ans; + int open; + int close; +}; + +trees tree[SIZE<<3]; + +trees merge(trees a,trees b) +{ + trees res; + int temp=min(a.open,b.close); + res.ans=a.ans+b.ans+2*temp; + res.open=a.open+b.open-temp; + res.close=a.close+b.close-temp; + return res; +} + +void build(int node,int start,int end) +{ + if(start==end) + { + if(s[start-1]=='(') + { + tree[node].ans=0; + tree[node].open=1; + tree[node].close=0; + } + else + { + tree[node].ans=0; + tree[node].open=0; + tree[node].close=1; + } + return; + } + int mid=(start+end)>>1; + build(2*node,start,mid); + build(2*node+1,mid+1,end); + tree[node]=merge(tree[2*node],tree[2*node+1]); +} + +trees query(int node,int start,int end, int l , int r) +{ + if(start>end || start>r || end>1; + return merge(query(2*node,start,mid,l,r),query(2*node+1,mid+1,end,l,r)); +} + +int main() +{ + cin>>s; + n=s.length(); + + build(1,1,n); + + /*for(int i=1;i<=2*n-1;i++) + { + printf("%d %d %d\n", tree[i].ans, tree[i].open, tree[i].close); + }*/ + + int m; + scanf("%d",&m); + + for(int i=0;i +using namespace std; +#define ll long long + +vector v; + +int main() +{ + // sievefunc(); + ll a[36]; + ll mul = 1; + for(int i=0;i<36;i++) + { + a[i] = mul; + mul *= 2; + } + for(int i=0;i<=35;i++) + { + for(int j=0;j<=35;j++) + { + if(i!=j) + v.push_back(a[i]+a[j]); + } + } + sort( v.begin(), v.end() ); + v.erase( unique( v.begin(), v.end() ), v.end() ); + + + int t; + scanf("%d", &t); + + while(t--) + { + ll n; + ll count; + scanf("%lld", &n); + long i = 0, temp = 0; + while(1) + { + if(v[i] < n) + { + temp = i; + i++; + continue; + } + break; + } + // cout<=0) + // { + // printf("%lld\n", n-v[k-1]); + // } + // else if(n-v[k-1]>v[k]-n && (v[k]-n)>=0) + // { + // printf("%lld\n", v[k]-n); + // } + ll lb = v[temp]; + ll ub = v[temp+1]; + ll ans = min(abs(n - lb), abs(ub - n)); + cout< +using namespace std; + +int main() +{ + int t; + scanf("%d", &t); + while(t--) + { + char a,b,c,d,e,f; + cin>>a>>b>>c; + cin>>d>>e>>f; + + // int countb=0, counto=0; + + + if((a=='o' || d=='o') && (b=='b' || e=='b') && (c=='b' || f=='b')) + { + printf("yes\n"); + } + else if((a=='b' || d=='b') && (b=='o' || e=='o') && (c=='b' || f=='b')) + { + printf("yes\n"); + } + else if((a=='b' || d=='b') && (b=='b' || e=='b') && (c=='o' || f=='o')) + { + printf("yes\n"); + } + else + { + printf("no\n"); + } + } + + return 0; +} \ No newline at end of file diff --git a/spoj/UPDATEIT b/spoj/UPDATEIT new file mode 100755 index 0000000..d4eace8 Binary files /dev/null and b/spoj/UPDATEIT differ diff --git a/spoj/UPDATEIT.cpp b/spoj/UPDATEIT.cpp new file mode 100644 index 0000000..bce7a0a --- /dev/null +++ b/spoj/UPDATEIT.cpp @@ -0,0 +1,65 @@ +#include +using namespace std; +#define MAXN 10005 + +long long BIT[MAXN]; +int t,n,u,l,r,val,q,id; +long long a[MAXN]; + + +inline void superFastRead (int *a) +{ + char c = 0; + while(c<33) + c = fgetc(stdin); + *a = 0; + while(c>33) + { + *a = *a*10 + c - '0'; + c = fgetc(stdin); + } +} + +void update(long long x,long long val) +{ + for(;x<=n;x+= x&-x) + { + BIT[x]+=val; + } +} + +long long query(long long x) +{ + long long sum=0; + for(;x>0;x-= x&-x) + { + sum+=BIT[x]; + } + + return sum; +} + +int main() +{ superFastRead(&t); + while(t--){ + superFastRead(&n); + superFastRead(&u); + memset(BIT,0,sizeof(BIT)); + for(long long i=0;i +#include +#include +#include +using namespace std; + +inline void superFastRead (int *a) +{ + char c = 0; + while(c<33) + c = fgetc(stdin); + *a = 0; + while(c>33) + { + *a = *a*10 + c - '0'; + c = fgetc(stdin); + } +} + +int tree[40003]; +int t,n,u,q,id,l,r,val; + +int read(int idx){ + int sum = 0; + while (idx > 0){ + sum += tree[idx]; + idx -= (idx & -idx); + } + return sum; +} + +void update(int idx ,int val){ + while (idx <= n){ + tree[idx] += val; + idx += (idx & -idx); + } +} + +int main() +{ superFastRead(&t); + while(t--) + { superFastRead(&n); + superFastRead(&u); + memset(tree,0,sizeof tree); + for(int i=0;i +using namespace std; +#define ll long long + +int BIT[5][1005][1005]; +ll n,m; + +void update(int no,int x,int y,ll val) +{ + for(;x<=n;x+=x&-x) + { + for(int y1=y;y1<=n;y1+=y1&-y1) + { + BIT[no][x][y1]+=val; + } + } +} + +ll query(int no, int x,int y) +{ + ll sum=0; + for (; x>0 ; x-=x&-x) + { + for(int y1=y;y1>0; y1-=y1&-y1) + { + sum+=BIT[no][x][y1]; + } + } + return sum; +} + +void update_range2D(int x1,int y1,int x2,int y2,int val) +{ + //updating the first tree + update(0, x1, y1, val); + update(0, x1, y2+1, -val); + update(0, x2+1, y1, -val); + update(0, x2+1, y2+1, val); + + // updating second tree + update(1, x1, y1, val*(1-y1)); + update(1, x1, y2+1, val*y2); + update(1, x2+1, y1, val*(y1-1)); + update(1, x2+1, y2+1, -val*y2); + + // updating third tree + update(2, x1, y1, val*(1-x1)); + update(2, x1, y2+1, (x1-1)*val); + update(2, x2+1, y1, val*x2); + update(2, x2+1, y2+1, -x2*val); + + // updating fourth tree + update(3, x1, y1, (x1-1)*(y1-1)*val); + update(3, x1, y2+1, -y2*(x1-1)*val); + update(3, x2+1, y1, -x2*(y1-1)*val); + update(3, x2+1, y2+1, x2*y2*val); +} + +ll query_n(int x,int y) +{ + return query(0,x,y)*x*y+query(1,x,y)*x+query(2,x,y)*y+query(3,x,y); +} + +ll query_range2D(int x1, int y1, int x2, int y2) { + ll sum = 0; + sum += query_n(x2, y2) - query_n(x1-1, y2) - query_n(x2, y1-1) + query_n(x1-1, y1-1); + return sum; +} + +int main() +{ + scanf("%lld %lld", &n, &m); + + int type,x1,x2,y1,y2,k; + while(m--) + { + scanf("%d %d %d %d %d", &type,&x1, &y1, &x2, &y2); + if(type==2) + { + scanf("%d",&k); + update_range2D(x1,y1,x2,y2,k); + + /*for(int k=0;k<4;k++) + { + printf("Tree No. : %d\n", k); + for(int i=0;i +#include +typedef long long int lli; + +/*lli ***bit;*/ +lli bit[5][1005][1005]; +int n, m; + +void update(int no, int x, int y, lli val) { + while (x <= n) { + int y1 = y; + while (y1 <= n) { + bit[no][x][y1] += val; + y1 += y1 & (-y1); + } + x += x & (-x); + } +} + +lli query(int no, int x, int y) { + lli sum = 0; + while (x > 0) { + int y1 = y; + while (y1 > 0) { + sum += bit[no][x][y1]; + y1 -= y1 & (-y1); + } + x -= x & (-x); + } + return sum; +} + +void update_r(int x1, int y1, int x2, int y2, int val) { + // updating first tree + update(0, x1, y1, val); + update(0, x1, y2+1, -val); + update(0, x2+1, y1, -val); + update(0, x2+1, y2+1, val); + + // updating second tree + update(1, x1, y1, val*(1-y1)); + update(1, x1, y2+1, val*y2); + update(1, x2+1, y1, val*(y1-1)); + update(1, x2+1, y2+1, -val*y2); + + // updating third tree + update(2, x1, y1, val*(1-x1)); + update(2, x1, y2+1, (x1-1)*val); + update(2, x2+1, y1, val*x2); + update(2, x2+1, y2+1, -x2*val); + + // updating fourth tree + update(3, x1, y1, (x1-1)*(y1-1)*val); + update(3, x1, y2+1, -y2*(x1-1)*val); + update(3, x2+1, y1, -x2*(y1-1)*val); + update(3, x2+1, y2+1, x2*y2*val); +} + +lli query_n(int x, int y) { + return query(0, x, y) * x * y + query(1, x, y) * x + query(2, x, y) * y + query(3, x, y); +} + +lli query_r(int x1, int y1, int x2, int y2) { + lli sum = 0; + sum += query_n(x2, y2) - query_n(x1-1, y2) - query_n(x2, y1-1) + query_n(x1-1, y1-1); + return sum; +} + +int main(void) { + scanf("%d %d", &n, &m); + /*bit = (lli ***) calloc(5, sizeof(lli***)); + int i, j; + for (i = 0; i < 4; i++) { + bit[i] = (lli **) calloc(n+10, sizeof(lli**)); + for (j = 0; j < n+10; j++) + bit[i][j] = (lli *) calloc(n+10, sizeof(lli)); + }*/ + int type, x1, x2, y1, y2, val; + while (m--) { + scanf("%d %d %d %d %d", &type, &x1, &y1, &x2, &y2); + if (type == 1) { + printf("%lld\n", query_r(x1, y1, x2, y2)); + } + else { + scanf("%d", &val); + update_r(x1, y1, x2, y2, val); + for(int k=0;k<4;k++) + { + printf("Tree No. : %d\n", k); + for(int i=0;i +using namespace std; + +int m,n,c; +int BIT[1005][1005]; +int eq[1005][1005]; + +void update(int x, int y, int val) +{ + for(;x<=n;x+=x&-x) + { + for(int y1=y;y1<=m ;y1+=y1&-y1) + { + BIT[x][y1]+=val; + //BIT[x][y]%=4; + //BIT[x][y]+=1; + } + } +} + +int query(int x, int y) +{ + int sum=0; + int val=eq[x][y]; + for(;x>0;x-=x&-x) + { + for(int y1=y;y1>0;y1-=y1&-y1) + { + sum+=BIT[x][y1]; + } + } + return sum+val; //range update only works for initial value 0 in BIT (or in this case?) +} + +/*void update1(int x, int y, int val) +{ + for(;x<=n;x+=x&-x) + { + for(int y1=y;y1<=m ;y1+=y1&-y1) + { + BIT[x][y1]+=val; + + } + } +}*/ + +int main() +{ + char ch; + scanf("%d %d", &n, &m); + + for(int i=1;i<=n;i++) + { + for(int j=1;j<=m;j++) + { + cin>>ch; + if(ch=='N') + { + // update(i,j,1); + eq[i][j]=1; + } + else if(ch=='E') + { + // update(i,j,2); + eq[i][j]=2; + } + else if(ch=='S') + { + // update(i,j,3); + eq[i][j]=3; + } + else if(ch=='W') + { + // update(i,j,4); + eq[i][j]=4; + } + } + } + + scanf("%d", &c); + + int x1,y1,x2,y2,d,val; + int ans; + + /*for(int i=1;i<=n;i++) + { + for(int j=1;j<=m;j++) + { + printf("%d ",query(i,j)-query(i-1,j)-query(i, j-1)+query(i-1, j-1)); + } + printf("\n"); + }*/ + + char a; + while(c--) + { + cin>>a; + // cout< +using namespace std; +int m, n; +int **bit; +char mat[2000][2000]; +int eq[2000][2000]; + +void update(int x, int y, int val) { + while (x <= m) { + int y1 = y; + while (y1 <= n) { + bit[x][y1] += val; + y1 += y1 & (-y1); + } + x += x & (-x); + } +} + +int query(int x, int y) { + int ans = 0; + int val = eq[x][y]; + while (x > 0) { + int y1 = y; + while (y1 > 0) { + ans += bit[x][y1]; + y1 -= y1 & (-y1); + } + x -= x & (-x); + } + return ans + val; +} + +void update_r(int x1, int y1, int x2, int y2, int val) { + update(x1, y1, val); + update(x1, y2+1, -val); + update(x2+1, y1, -val); + update(x2+1, y2+1, val); +} + +int main(void) { + scanf("%d %d", &m, &n); + bit = (int**) calloc(m+10, sizeof(int*)); + for (int i = 0; i < m+10; i++) + bit[i] = (int*) calloc(n+10, sizeof(int)); + for (int i = 1; i <= m; i++) { + scanf("%s", mat[i]+1); + for (int j = 1; j <= n; j++) { + if (mat[i][j] == 'N') + eq[i][j] = 1; + else if (mat[i][j] == 'E') + eq[i][j] = 2; + else if (mat[i][j] == 'S') + eq[i][j] = 3; + else if (mat[i][j] == 'W') + eq[i][j] = 4; + } + } + int q; + scanf("%d", &q); + char type[10]; + int x1, y1, x2, y2, val; + while (q--) { + scanf("%s", type); + if (type[0] == 'C') { + scanf("%d %d %d %d %d", &x1, &y1, &x2, &y2, &val); + int update; + if (val == 0) + update = 1; + else + update = -1; + update_r(x1, y1, x2, y2, update); + } + else { + scanf("%d %d", &x1, &y1); + int val = query(x1, y1); + int mod = val % 4; + if (mod < 0) + mod += 4; + if (mod == 1) + printf("N\n"); + else if (mod == 2) + printf("E\n"); + else if (mod == 3) + printf("S\n"); + else if (mod == 0) + printf("W\n"); + } + } + return 0; +} \ No newline at end of file diff --git a/spoj/chandan b/spoj/chandan new file mode 100755 index 0000000..565432c Binary files /dev/null and b/spoj/chandan differ diff --git a/spoj/chandan.cpp b/spoj/chandan.cpp new file mode 100644 index 0000000..e69de29 diff --git a/spoj/chandanjava.class b/spoj/chandanjava.class new file mode 100644 index 0000000..e089aa7 Binary files /dev/null and b/spoj/chandanjava.class differ diff --git a/spoj/chandanjava.java b/spoj/chandanjava.java new file mode 100644 index 0000000..3f0633b --- /dev/null +++ b/spoj/chandanjava.java @@ -0,0 +1,14 @@ + +public class chandanjava +{ + public static void main(String args[]) + { + int a=10; + int b= a + ++a + a++; + int c= a++ + a++ + a--; + int d= ++a + --a + a; + int e= ++a + a++ + a++; + int f= a++ + a++ + a; + System.out.println(b+"\n"+c+"\n"+d+"\n"+e+"\n"+f+"\n"); + } +} \ No newline at end of file diff --git a/spoj/courier1 b/spoj/courier1 new file mode 100755 index 0000000..3e807e5 Binary files /dev/null and b/spoj/courier1 differ diff --git a/spoj/courier1.cpp b/spoj/courier1.cpp new file mode 100644 index 0000000..0e19461 --- /dev/null +++ b/spoj/courier1.cpp @@ -0,0 +1,119 @@ +#include +using namespace std; + +#define INF INT_MAX + +int msk=0,n,m,home; + +long long src[20],dest[20]; +long long dist[101][101],dp[1<<12][101]; + +void floyd_warshall(int n) +{ + for(int k=0;k>t; + while(t--) + { + int x,y,c; + clear(); + cin>>n>>m>>home; + for(int i=0;i>x>>y>>c; + dist[x-1][y-1]=dist[y-1][x-1]=c; + } + floyd_warshall(n); + int q;msk=0;int k=0; + cin>>q; + for(int i=0;i>x>>y>>c; + // msk+=c; + while(c--) + { + src[k]=x-1,dest[k]=y-1; + k++; + } + + } + msk=k; + cout< +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace pretty_print +{ + namespace detail + { + // SFINAE type trait to detect whether T::const_iterator exists. + + struct sfinae_base + { + using yes = char; + using no = yes[2]; + }; + + template + struct has_const_iterator : private sfinae_base + { + private: + template static yes & test(typename C::const_iterator*); + template static no & test(...); + public: + static const bool value = sizeof(test(nullptr)) == sizeof(yes); + using type = T; + }; + + template + struct has_begin_end : private sfinae_base + { + private: + template + static yes & f(typename std::enable_if< + std::is_same(&C::begin)), + typename C::const_iterator(C::*)() const>::value>::type *); + + template static no & f(...); + + template + static yes & g(typename std::enable_if< + std::is_same(&C::end)), + typename C::const_iterator(C::*)() const>::value, void>::type*); + + template static no & g(...); + + public: + static bool const beg_value = sizeof(f(nullptr)) == sizeof(yes); + static bool const end_value = sizeof(g(nullptr)) == sizeof(yes); + }; + + } // namespace detail + + + // Holds the delimiter values for a specific character type + + template + struct delimiters_values + { + using char_type = TChar; + const char_type * prefix; + const char_type * delimiter; + const char_type * postfix; + }; + + + // Defines the delimiter values for a specific container and character type + + template + struct delimiters + { + using type = delimiters_values; + static const type values; + }; + + + // Functor to print containers. You can use this directly if you want + // to specificy a non-default delimiters type. The printing logic can + // be customized by specializing the nested template. + + template , + typename TDelimiters = delimiters> + struct print_container_helper + { + using delimiters_type = TDelimiters; + using ostream_type = std::basic_ostream; + + template + struct printer + { + static void print_body(const U & c, ostream_type & stream) + { + using std::begin; + using std::end; + + auto it = begin(c); + const auto the_end = end(c); + + if (it != the_end) + { + for ( ; ; ) + { + stream << *it; + + if (++it == the_end) break; + + if (delimiters_type::values.delimiter != NULL) + stream << delimiters_type::values.delimiter; + } + } + } + }; + + print_container_helper(const T & container) + : container_(container) + { } + + inline void operator()(ostream_type & stream) const + { + if (delimiters_type::values.prefix != NULL) + stream << delimiters_type::values.prefix; + + printer::print_body(container_, stream); + + if (delimiters_type::values.postfix != NULL) + stream << delimiters_type::values.postfix; + } + + private: + const T & container_; + }; + + // Specialization for pairs + + template + template + struct print_container_helper::printer> + { + using ostream_type = typename print_container_helper::ostream_type; + + static void print_body(const std::pair & c, ostream_type & stream) + { + stream << c.first; + if (print_container_helper::delimiters_type::values.delimiter != NULL) + stream << print_container_helper::delimiters_type::values.delimiter; + stream << c.second; + } + }; + + // Specialization for tuples + + template + template + struct print_container_helper::printer> + { + using ostream_type = typename print_container_helper::ostream_type; + using element_type = std::tuple; + + template struct Int { }; + + static void print_body(const element_type & c, ostream_type & stream) + { + tuple_print(c, stream, Int<0>()); + } + + static void tuple_print(const element_type &, ostream_type &, Int) + { + } + + static void tuple_print(const element_type & c, ostream_type & stream, + typename std::conditional, std::nullptr_t>::type) + { + stream << std::get<0>(c); + tuple_print(c, stream, Int<1>()); + } + + template + static void tuple_print(const element_type & c, ostream_type & stream, Int) + { + if (print_container_helper::delimiters_type::values.delimiter != NULL) + stream << print_container_helper::delimiters_type::values.delimiter; + + stream << std::get(c); + + tuple_print(c, stream, Int()); + } + }; + + // Prints a print_container_helper to the specified stream. + + template + inline std::basic_ostream & operator<<( + std::basic_ostream & stream, + const print_container_helper & helper) + { + helper(stream); + return stream; + } + + + // Basic is_container template; specialize to derive from std::true_type for all desired container types + + template + struct is_container : public std::integral_constant::value && + detail::has_begin_end::beg_value && + detail::has_begin_end::end_value> { }; + + template + struct is_container : std::true_type { }; + + template + struct is_container : std::false_type { }; + + template + struct is_container> : std::true_type { }; + + template + struct is_container> : std::true_type { }; + + template + struct is_container> : std::true_type { }; + + + // Default delimiters + + template struct delimiters { static const delimiters_values values; }; + template const delimiters_values delimiters::values = { "[", ", ", "]" }; + template struct delimiters { static const delimiters_values values; }; + template const delimiters_values delimiters::values = { L"[", L", ", L"]" }; + + + // Delimiters for (multi)set and unordered_(multi)set + + template + struct delimiters< ::std::set, char> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::set, char>::values = { "{", ", ", "}" }; + + template + struct delimiters< ::std::set, wchar_t> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::set, wchar_t>::values = { L"{", L", ", L"}" }; + + template + struct delimiters< ::std::multiset, char> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::multiset, char>::values = { "{", ", ", "}" }; + + template + struct delimiters< ::std::multiset, wchar_t> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::multiset, wchar_t>::values = { L"{", L", ", L"}" }; + + template + struct delimiters< ::std::unordered_set, char> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::unordered_set, char>::values = { "{", ", ", "}" }; + + template + struct delimiters< ::std::unordered_set, wchar_t> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::unordered_set, wchar_t>::values = { L"{", L", ", L"}" }; + + template + struct delimiters< ::std::unordered_multiset, char> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::unordered_multiset, char>::values = { "{", ", ", "}" }; + + template + struct delimiters< ::std::unordered_multiset, wchar_t> { static const delimiters_values values; }; + + template + const delimiters_values delimiters< ::std::unordered_multiset, wchar_t>::values = { L"{", L", ", L"}" }; + + + // Delimiters for pair and tuple + + template struct delimiters, char> { static const delimiters_values values; }; + template const delimiters_values delimiters, char>::values = { "(", ", ", ")" }; + template struct delimiters< ::std::pair, wchar_t> { static const delimiters_values values; }; + template const delimiters_values delimiters< ::std::pair, wchar_t>::values = { L"(", L", ", L")" }; + + template struct delimiters, char> { static const delimiters_values values; }; + template const delimiters_values delimiters, char>::values = { "(", ", ", ")" }; + template struct delimiters< ::std::tuple, wchar_t> { static const delimiters_values values; }; + template const delimiters_values delimiters< ::std::tuple, wchar_t>::values = { L"(", L", ", L")" }; + + + // Type-erasing helper class for easy use of custom delimiters. + // Requires TCharTraits = std::char_traits and TChar = char or wchar_t, and MyDelims needs to be defined for TChar. + // Usage: "cout << pretty_print::custom_delims(x)". + + struct custom_delims_base + { + virtual ~custom_delims_base() { } + virtual std::ostream & stream(::std::ostream &) = 0; + virtual std::wostream & stream(::std::wostream &) = 0; + }; + + template + struct custom_delims_wrapper : custom_delims_base + { + custom_delims_wrapper(const T & t_) : t(t_) { } + + std::ostream & stream(std::ostream & s) + { + return s << print_container_helper, Delims>(t); + } + + std::wostream & stream(std::wostream & s) + { + return s << print_container_helper, Delims>(t); + } + + private: + const T & t; + }; + + template + struct custom_delims + { + template + custom_delims(const Container & c) : base(new custom_delims_wrapper(c)) { } + + std::unique_ptr base; + }; + + template + inline std::basic_ostream & operator<<(std::basic_ostream & s, const custom_delims & p) + { + return p.base->stream(s); + } + + + // A wrapper for a C-style array given as pointer-plus-size. + // Usage: std::cout << pretty_print_array(arr, n) << std::endl; + + template + struct array_wrapper_n + { + typedef const T * const_iterator; + typedef T value_type; + + array_wrapper_n(const T * const a, size_t n) : _array(a), _n(n) { } + inline const_iterator begin() const { return _array; } + inline const_iterator end() const { return _array + _n; } + + private: + const T * const _array; + size_t _n; + }; + + + // A wrapper for hash-table based containers that offer local iterators to each bucket. + // Usage: std::cout << bucket_print(m, 4) << std::endl; (Prints bucket 5 of container m.) + + template + struct bucket_print_wrapper + { + typedef typename T::const_local_iterator const_iterator; + typedef typename T::size_type size_type; + + const_iterator begin() const + { + return m_map.cbegin(n); + } + + const_iterator end() const + { + return m_map.cend(n); + } + + bucket_print_wrapper(const T & m, size_type bucket) : m_map(m), n(bucket) { } + + private: + const T & m_map; + const size_type n; + }; + +} // namespace pretty_print + + +// Global accessor functions for the convenience wrappers + +template +inline pretty_print::array_wrapper_n pretty_print_array(const T * const a, size_t n) +{ + return pretty_print::array_wrapper_n(a, n); +} + +template pretty_print::bucket_print_wrapper +bucket_print(const T & m, typename T::size_type n) +{ + return pretty_print::bucket_print_wrapper(m, n); +} + + +// Main magic entry point: An overload snuck into namespace std. +// Can we do better? + +namespace std +{ + // Prints a container to the stream using default delimiters + + template + inline typename enable_if< ::pretty_print::is_container::value, + basic_ostream &>::type + operator<<(basic_ostream & stream, const T & container) + { + return stream << ::pretty_print::print_container_helper(container); + } +} + +#endif // H_PRETTY_PRINT diff --git a/spoj/topics to cover b/spoj/topics to cover new file mode 100644 index 0000000..5fed1b4 --- /dev/null +++ b/spoj/topics to cover @@ -0,0 +1,12 @@ + ADHOC/Implementation/Greedy + Math(Combinatorics, Euclidean GCD, Modular Exponentiation, Euler Totient Function etc). Codemonk material should be sufficient. + Binary Search + C++ STL & basic data structures(Stack, Queue etc) + Sliding Window/Two Pointers + DFS/BFS + DSU + Backtracking(Josephus Algorithm, N Queen Problem etc) + Dynamic Programming + Other Graph Algorithms(SCC, MST, Shortest Parths) + String Algorithms(Hashing, KMP, Rabin Karp) + Advanced Data Structures(Segment Trees, Binary Indexed Trees, Tries etc) diff --git a/spoj/try.py b/spoj/try.py new file mode 100644 index 0000000..738cf16 --- /dev/null +++ b/spoj/try.py @@ -0,0 +1,11 @@ +def matrix(): + #for 15 lists each with 10 elements i.e. 15 rows and 10 columns + w,h=10,15 + + matrix=[[0 for x in range(w)] for y in range(h)] + + #initalising + matrix[0][0]=1 + print matrix[0][0] + +matrix() \ No newline at end of file