Advertisement
Tooster

Untitled

May 12th, 2016
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. #define __USE_SCANF
  2. //#define __PRE
  3. // __USE_CIN or __USE_SCANF
  4. // desynchronized <iostream> faster than <cstdio> ???
  5.  
  6. /*
  7. NOTES:
  8. constructor initializer list:
  9. point(int x, int y) : x{x}, y{y} {}
  10.  
  11. */
  12. using namespace std;
  13.  
  14. #include <vector>
  15. #include <set>
  16. #include <queue>
  17. #include <map>
  18. #include <bitset>
  19.  
  20. #include <cmath>
  21. #include <algorithm>
  22. #include <utility>
  23. #include <functional>
  24. #include <string>
  25.  
  26. #ifdef __USE_CIN
  27. #include <iostream>
  28. #define INT(x) int x; cin>>x
  29. #define LL(x) long long x; cin>>x
  30. #define ULL(x) unsigned long long x; cin>>x
  31. #define STR(s) string (s); cin>>(s)
  32. #define OUT(x) cout<<(x)
  33. #define IN(x) cin>>(x)
  34. #define nl cout << '\n';
  35.  
  36. #elif defined __USE_SCANF
  37. #include <cstdio>
  38. #define INT(x) int x; scanf("%d", &x)
  39. #define LL(x) long long x; scanf("%lld", &x)
  40. #define ULL(x) unsigned long long x; scanf("%llu", &x)
  41. #define STR(s, i) char *(s) = new char[(i)+1]; scanf("%s", (s));
  42. #define OUT(x) printf("%d", (x))
  43. #define IN(x) scanf("%d", &(x))
  44. #define nl printf("\n");
  45. #elif !defined __USE_CIN && !defined __USE_SCANF
  46. #error Standard input flag not set.
  47. #endif
  48.  
  49. #define ll long long
  50. #define ull unsigned long long
  51. #define ui unsigned int
  52.  
  53. typedef pair<int, int> pi;
  54. typedef pair<bool, int> pbi;
  55. typedef pair<ll, ll> pll;
  56. typedef pair< pair<int, int>, pair<int, int> > ppi;
  57. typedef vector< int > vi;
  58. typedef vector<bool > vb;
  59. typedef vector< long long > vll;
  60. typedef vector< pi > vpi;
  61. typedef vector<vector<int> > vvi;
  62. typedef vector< vector<long long> > vvll;
  63. typedef vector<vector< pi > > vvpi;
  64.  
  65. const int oo = 2147483647;
  66. const ll LLoo = 9223372036854775807;
  67. const ll HASH = 999999937;
  68.  
  69. #define fr(x,y) for(int x=0; x<(y); x++)
  70. #define frr(x,y, z) for(int x=(y); x<(z); x++)
  71. #define fr1(x,y) for(int x=1; x<(y); x++)
  72. #define rf(x,y) for(int x=(y); x>0; x--)
  73. #define rf0(x,y) for(int x=(y); x>=0; x--)
  74. #define r(NAME, SIZE) NAME.resize((SIZE))
  75. #define rv(NAME, SIZE, VAL) NAME.resize((SIZE), (VAL))
  76. #define zajmodulo(x,y) ((x)%(y)+(y))%(y)
  77. #define all(x) x.begin(), x.end()
  78. #define MATRIX_INT(NAME,ROW,COL,VAR) vvi NAME((ROW), vi((COL), (VAR)))
  79. #define MATRIX_LL(NAME,ROW,COL,VAR) vvll NAME((ROW), vl((COL), (VAR)))
  80. #define FILLIN(NAME,VAR) fr(i,NAME.size()) fr(j, NAME[i].size()) NAME[i][j] = (VAR);
  81.  
  82. pll EGCD(ll a, ll b) { if (b == 0) return pll(1, 0); pll xy = EGCD(b, a%b); return pll(xy.second, xy.first - (a / b)*xy.second); }
  83. //returni a(mod p) ale trzeba użyć zajmodulo(ECGD.f, ECGD.s)
  84. struct point {
  85. int x, y;
  86. point() : x{ 0 }, y{ 0 } {}
  87. point(int x, int y) :x{ x }, y{ y } {}
  88. point operator- (const point &p) const { return point(x - p.x, y - p.y); }
  89. int operator* (const point &p) const { return (x*p.y - y*p.x); } //if >0 vector 0->p on the left of 0->this
  90. int dist(const point &p) { int a = x - p.x, b = y - p.y; return a*a + b*b; }
  91. bool smallerY(const point &p) const { return (y < p.y || (y == p.y && x < p.x)); }
  92. bool smallerX(const point &p) const { return (x < p.x || (x == p.x && y < p.y)); }
  93. };
  94.  
  95. /*
  96. ###########
  97. Tooster
  98. ###########
  99.  
  100. --------
  101. range-min-querry
  102. --------
  103. */
  104. vpi tab;
  105.  
  106. pi find(int a, int b) {
  107. pi m1(oo, 0), m2(oo, o);
  108. while (a / 2 != b / 2) {
  109. if (b & 1) m1 = (m1.first < tab[b - 1].first ? m1 : tab[b - 1]);
  110. if (!a & 1) m2 = (m2.first < tab[a + 1].first ? m2 : tab[a + 1]);
  111. a /= 2; b /= 2;
  112. }
  113. return m1.first < m2.first ? m1 : m2;
  114. }
  115.  
  116. void pie() {
  117. INT(n);
  118. int size = 1; while (size <= n) size <<= 1;
  119. rv(tab, size, pi(oo, 0));
  120. fr(i, n) { INT(a); tab[size + i] = pi(a, i); }
  121. rf(i, size - 1) tab[i] = (tab[2 * i].first < tab[2 * i + 1].first ? tab[2 * i] : tab[2 * i + 1]);
  122. INT(q);
  123. while (q--) {
  124. INT(a); INT(b); find(a + size - 1, b + size - 1);
  125. }
  126. return;
  127. }
  128.  
  129. int main() {
  130. #ifdef __USE_CIN
  131. ios_base::sync_with_stdio(false);
  132. #endif
  133. INT(t);
  134. while (t) pie();
  135. return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement