Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <stack>
- #include <cmath>
- #include <set>
- #include <iomanip>
- #include <map>
- #include <queue>
- #include <cstdio>
- #include <deque>
- using namespace std;
- ifstream cin("input.txt");
- ofstream cout("output.txt");
- typedef long long ll;
- typedef unsigned long long ull;
- typedef long double ld;
- #define all(a) a.begin(), a.end()
- #define sqr(a) a * a
- int INF = 2 * 1e9;
- vector <int> arr, lg;
- vector <vector <int> > sparce;
- void build(int n) {
- arr.resize(n);
- lg.resize(n + 1);
- for (int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- for (int i = 2; i <= n; i++) {
- lg[i] = lg[i / 2] + 1;
- }
- sparce.resize(lg[n] + 1, vector <int>(n));
- for (int i = 0; i < n; i++) {
- sparce[0][i] = arr[i];
- }
- for (int i = 1; i <= lg[n]; i++) {
- for (int j = 0; j + (1 << i) - 1 < n; j++) {
- sparce[i][j] = min(sparce[i - 1][j], sparce[i - 1][j + (1 << (i - 1))]);
- }
- }
- }
- int find_min(int l, int r) {
- int len = lg[r - l + 1];
- return min(sparce[len][l], sparce[len][r - (1 << len) + 1]);
- }
- int main() {
- int n, k;
- cin >> n >> k;
- build(n);
- }
Add Comment
Please, Sign In to add comment