Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define __USE_SCANF
- //#define __PRE
- // __USE_CIN or __USE_SCANF
- // desynchronized <iostream> faster than <cstdio> ???
- /*
- NOTES:
- constructor initializer list:
- point(int x, int y) : x{x}, y{y} {}
- */
- using namespace std;
- #include <vector>
- #include <set>
- #include <queue>
- #include <map>
- #include <bitset>
- #include <cmath>
- #include <algorithm>
- #include <utility>
- #include <functional>
- #include <string>
- #ifdef __USE_CIN
- #include <iostream>
- #define INT(x) int x; cin>>x
- #define LL(x) long long x; cin>>x
- #define ULL(x) unsigned long long x; cin>>x
- #define STR(s) string (s); cin>>(s)
- #define OUT(x) cout<<(x)
- #define IN(x) cin>>(x)
- #define nl cout << '\n';
- #elif defined __USE_SCANF
- #include <cstdio>
- #define INT(x) int x; scanf("%d", &x)
- #define LL(x) long long x; scanf("%lld", &x)
- #define ULL(x) unsigned long long x; scanf("%llu", &x)
- #define STR(s, i) char *(s) = new char[(i)+1]; scanf("%s", (s));
- #define OUT(x) printf("%d", (x))
- #define IN(x) scanf("%d", &(x))
- #define nl printf("\n");
- #elif !defined __USE_CIN && !defined __USE_SCANF
- #error Standard input flag not set.
- #endif
- #define ll long long
- #define ull unsigned long long
- #define ui unsigned int
- typedef pair<int, int> pi;
- typedef pair<bool, int> pbi;
- typedef pair<ll, ll> pll;
- typedef pair< pair<int, int>, pair<int, int> > ppi;
- typedef vector< int > vi;
- typedef vector<bool > vb;
- typedef vector< long long > vll;
- typedef vector< pi > vpi;
- typedef vector<vector<int> > vvi;
- typedef vector< vector<long long> > vvll;
- typedef vector<vector< pi > > vvpi;
- const int oo = 2147483647;
- const ll LLoo = 9223372036854775807;
- const ll HASH = 999999937;
- #define fr(x,y) for(int x=0; x<(y); x++)
- #define frr(x,y, z) for(int x=(y); x<(z); x++)
- #define fr1(x,y) for(int x=1; x<(y); x++)
- #define rf(x,y) for(int x=(y); x>0; x--)
- #define rf0(x,y) for(int x=(y); x>=0; x--)
- #define r(NAME, SIZE) NAME.resize((SIZE))
- #define rv(NAME, SIZE, VAL) NAME.resize((SIZE), (VAL))
- #define zajmodulo(x,y) ((x)%(y)+(y))%(y)
- #define all(x) x.begin(), x.end()
- #define MATRIX_INT(NAME,ROW,COL,VAR) vvi NAME((ROW), vi((COL), (VAR)))
- #define MATRIX_LL(NAME,ROW,COL,VAR) vvll NAME((ROW), vl((COL), (VAR)))
- #define FILLIN(NAME,VAR) fr(i,NAME.size()) fr(j, NAME[i].size()) NAME[i][j] = (VAR);
- 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); }
- //returni a(mod p) ale trzeba użyć zajmodulo(ECGD.f, ECGD.s)
- struct point {
- int x, y;
- point() : x{ 0 }, y{ 0 } {}
- point(int x, int y) :x{ x }, y{ y } {}
- point operator- (const point &p) const { return point(x - p.x, y - p.y); }
- int operator* (const point &p) const { return (x*p.y - y*p.x); } //if >0 vector 0->p on the left of 0->this
- int dist(const point &p) { int a = x - p.x, b = y - p.y; return a*a + b*b; }
- bool smallerY(const point &p) const { return (y < p.y || (y == p.y && x < p.x)); }
- bool smallerX(const point &p) const { return (x < p.x || (x == p.x && y < p.y)); }
- };
- /*
- ###########
- Tooster
- ###########
- --------
- range-min-querry
- --------
- */
- vpi tab;
- pi find(int a, int b) {
- pi m1(oo, 0), m2(oo, o);
- while (a / 2 != b / 2) {
- if (b & 1) m1 = (m1.first < tab[b - 1].first ? m1 : tab[b - 1]);
- if (!a & 1) m2 = (m2.first < tab[a + 1].first ? m2 : tab[a + 1]);
- a /= 2; b /= 2;
- }
- return m1.first < m2.first ? m1 : m2;
- }
- void pie() {
- INT(n);
- int size = 1; while (size <= n) size <<= 1;
- rv(tab, size, pi(oo, 0));
- fr(i, n) { INT(a); tab[size + i] = pi(a, i); }
- rf(i, size - 1) tab[i] = (tab[2 * i].first < tab[2 * i + 1].first ? tab[2 * i] : tab[2 * i + 1]);
- INT(q);
- while (q--) {
- INT(a); INT(b); find(a + size - 1, b + size - 1);
- }
- return;
- }
- int main() {
- #ifdef __USE_CIN
- ios_base::sync_with_stdio(false);
- #endif
- INT(t);
- while (t) pie();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement