Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <string>
- #include <math.h>
- #include <climits>
- //#pragma GCC optimize("O3, unroll-loops");
- #include <list>
- #include <map>
- #include <set>
- #include <queue>
- #include <unordered_map>
- #include <unordered_set>
- //#include <chrono>
- //#include <fstream>
- //#include <bits/stdc++.h>
- #define mp make_pair
- #define pb push_back
- #define eb emplace_back
- #define x first
- #define y second
- #define sz(x) (int)x.size()
- #define all(x) begin(x), end(x)
- #define rall(x) rbegin(x), rend(x)
- #define FOR(i,a,b) for (int i = (a); i < (b); i++)
- #define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- typedef pair<int, int> pi;
- typedef pair<ll, ll> pl;
- typedef vector<int> veci;
- typedef vector<bool> vecb;
- typedef vector<vector<int>> vvi;
- typedef vector<vector<bool>> vvb;
- const int INF_I = 1e9;
- const ll INF_LL = 1e18;
- veci a;
- vector<pi> st;
- int n;
- pi com(pi a, pi b) {
- if (a.x > b.x)
- return a;
- if (b.x > a.x)
- return b;
- return mp(a.x, a.y + b.y);
- }
- void build(int c = 1, int tl = 0, int tr = n - 1) {
- if (tl == tr) {
- st[c] = mp(a[tl], 1);
- return;
- }
- int tm = (tl + tr) >> 1;
- build(c << 1, tl, tm);
- build((c << 1) + 1, tm + 1, tr);
- st[c] = com(st[c << 1], st[(c << 1) + 1]);
- }
- pi get(int l, int r, int c = 1, int tl = 0, int tr = n - 1) {
- if (l > r)
- return pi();
- if (tl == l && tr == r)
- return st[c];
- int tm = (tl + tr) >> 1;
- return com(
- get(l, min(r, tm), c << 1, tl, tm),
- get(max(l, tm + 1), r, (c << 1) + 1, tm + 1, tr)
- );
- }
- int main() {
- /*ifstream cin("in.txt");
- ofstream cout("out.txt");
- auto start_time = chrono::high_resolution_clock::now();*/
- ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin >> n;
- a.assign(n, 0);
- st.assign(n << 2, pi());
- FOR(i, 0, n)
- cin >> a[i];
- build();
- int q;
- cin >> q;
- while (q--) {
- int l, r;
- cin >> l >> r;
- pi res = get(--l, --r);
- cout << res.x << " " << res.y << "\n";
- }
- /*auto end_time = chrono::high_resolution_clock::now();
- chrono::duration<double> duration = end_time - start_time;
- cout << duration.count() << "\n";
- cin.close();
- cout.close();*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment