Advertisement
konchin_shih

毒瘤題

Dec 2nd, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.82 KB | None | 0 0
  1. //Input Output
  2. #include<iostream>
  3. #include<fstream>
  4. #include<sstream>
  5. #include<streambuf>
  6. //C lib
  7. #include<cstdlib>
  8. #include<cstring>
  9. #include<cmath>
  10. #include<climits>
  11. #include<cctype>
  12. //Container
  13. #include<array>
  14. #include<vector>
  15. #include<stack>
  16. #include<queue>
  17. #include<deque>
  18. #include<list>
  19. #include<bitset>
  20. #include<set>
  21. #include<map>
  22. #include<unordered_set>
  23. #include<unordered_map>
  24. //Others
  25. #include<tuple>
  26. #include<algorithm>
  27. #include<functional>
  28. #include<numeric>
  29. #include<iterator>
  30. #include<limits>
  31. #include<utility>
  32. #include<complex>
  33. #include<type_traits>
  34. #include<initializer_list>
  35.  
  36. #if __cplusplus > 201703L
  37. #include<concepts>
  38. #endif
  39.  
  40. using namespace std;
  41.  
  42. #define debug(x) cout << #x << " : " << x << endl
  43.  
  44. namespace abb {
  45. using ll = long long;
  46. using ull = unsigned long long;
  47. template<typename T> using V = vector<T>;
  48. template<typename T> using Q = queue<T>;
  49. template<typename T> using DQ = deque<T>;
  50. template<typename T> using V2d = vector<vector<T>>;
  51. template<typename T> using US = unordered_set<T>;
  52. template<typename T, size_t s> using A = array<T, s>;
  53. template<typename T1, typename T2> using UM = unordered_map<T1, T2>;
  54. template<typename T1, typename T2 = T1> using P = pair<T1, T2>;
  55. template<typename T, typename Cmp = less<T>> using S = set<T, Cmp>;
  56. template<typename T, typename Cmp = less<T>> using PQ = priority_queue<T, Cmp>;
  57. template<typename T1, typename T2, typename Cmp = less<T1>> using M = map<T1, T2, Cmp>;
  58. }
  59.  
  60. namespace output {
  61. template<typename T>
  62. ostream& operator<<(ostream& os, const vector<T>& v) {
  63.     for (const auto& i : v) os << i << ' ';
  64.     return os;
  65. }
  66. template<typename T1, typename T2>
  67. ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  68.     return os << '(' << p.first << ", " << p.second << ')';
  69. }
  70. template<typename T>
  71. ostream& operator<<(ostream& os, const set<T>& s) {
  72.     for (const auto& i : s) os << i << ' ';
  73.     return os;
  74. }
  75. template<typename T1, typename T2>
  76. ostream& operator<<(ostream& os, const map<T1, T2>& m) {
  77.     for (const auto& i : m) os << i << ' ';
  78.     return os;
  79. }
  80. };
  81.  
  82. namespace rit {
  83. struct fast_istream {
  84.     operator bool() const {return bool(cin);}
  85.     fast_istream() {cin.tie(nullptr);}
  86. } fin;
  87. #if __cplusplus > 201703L
  88. template<typename T>
  89. fast_istream& operator>>(fast_istream& is, T& n) requires integral<T> {
  90. #else
  91. template<typename T, class = typename enable_if<is_integral<T>::value>::type>
  92. fast_istream & operator>>(fast_istream& is, T& n) {
  93. #endif
  94.     while (isspace(cin.rdbuf()->sgetc()))
  95.         cin.rdbuf()->snextc();
  96.     bool sign = false;
  97.     if (cin.rdbuf()->sgetc() == '-')
  98.         sign = true, cin.rdbuf()->snextc();
  99.     for (n = 0; isdigit(cin.rdbuf()->sgetc());)
  100.         n *= 10, n += cin.rdbuf()->sbumpc() - '0';
  101.     n = sign ? -n : n;
  102.     return is;
  103. }
  104. fast_istream& operator>>(fast_istream& is, char& n) {
  105.     while (isspace(cin.rdbuf()->sgetc()))
  106.         cin.rdbuf()->snextc();
  107.     n = cin.rdbuf()->sbumpc();
  108.     return is;
  109. }
  110. }
  111.  
  112. #define endl '\n'
  113. namespace wit {
  114. struct fast_ostream {
  115.     operator bool() const {return bool(cout);}
  116.     fast_ostream() {cout.tie(nullptr);}
  117. } fout;
  118. constexpr int buffer_size = 30;
  119. #if __cplusplus > 201703L
  120. template<typename T>
  121. fast_ostream& operator<<(fast_ostream& os, T n) requires integral<T> {
  122. #else
  123. template<typename T, class = typename enable_if<is_integral<T>::value>::type>
  124. fast_ostream & operator<<(fast_ostream& os, T n) {
  125. #endif
  126.     if (!n) {cout.rdbuf()->sputc('0'); return os;}
  127.     if (n < 0) cout.rdbuf()->sputc('-'), n = -n;
  128.     static char buffer[buffer_size];
  129.     int cnt = buffer_size;
  130.     for (; n; n /= 10)
  131.         buffer[--cnt] = n % 10 + '0';
  132.     cout.rdbuf()->sputn(buffer + cnt, buffer_size - cnt);
  133.     return os;
  134. }
  135. fast_ostream& operator<< (fast_ostream& os, const char& n) {
  136.     cout.rdbuf()->sputc(n); return os;
  137. }
  138. }
  139.  
  140. #define MULTI_TASKCASE
  141. using namespace abb;
  142. using namespace output;
  143. using namespace rit;
  144. using namespace wit;
  145.  
  146. inline void init() {
  147.  
  148. }
  149.  
  150.  
  151. inline void c1() {
  152.     ll n, k, maxn = -1e9, curn = -1e9; cin >> n;
  153.     while (n--)
  154.         cin >> k, curn = max(0LL, curn) - k, maxn = max(maxn, curn);
  155.     cout << maxn << endl;
  156. }
  157.  
  158. V<int> v; int n;
  159. int ans = 0, cura = 0, curb = 0;
  160. void dfs(int i) {
  161.     if (i == n) {ans = max(ans, cura * curb); return;}
  162.     cura += v[i], dfs(i + 1), cura -= v[i];
  163.     curb += v[i], dfs(i + 1), curb -= v[i];
  164. }
  165.  
  166. inline void c2() {
  167.     int curn = -1e9, maxn = -1e9; cin >> n;
  168.     v.resize(n);
  169.     for (auto& i : v)
  170.         fin >> i, curn = max(0, curn) - i, maxn = max(maxn, curn), i = maxn;
  171.     // debug(v);
  172.     dfs(0);
  173.     fout << ans << endl;
  174. }
  175.  
  176. function<void()> solve[] = {c1, c2};
  177. //#define FILEIO
  178. main() {
  179.     ios::sync_with_stdio(false);
  180. #ifdef FILEIO
  181.     fstream filein("in.txt", ios::in);
  182.     fstream fileout("out.txt", ios::out);
  183.     cin.rdbuf(filein.rdbuf());
  184.     cout.rdbuf(fileout.rdbuf());
  185. #endif
  186.     init();
  187.     int t = 1, c;
  188. #ifdef MULTI_TASKCASE
  189.     cin >> c >> t;
  190. #endif
  191.     while (t--) solve[c == 2]();
  192.     return 0;
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement