- #include <bits/stdc++.h>
- using namespace std;
- #define mx 100001
- int arr[mx];
- int tree[mx * 3];
- void init(int node, int b, int e)
- {
- if (b == e) {
- tree[node] = arr[b];
- return;
- }
- int Left = node * 2;
- int Right = node * 2 + 1;
- int mid = (b + e) / 2;
- init(Left, b, mid);
- init(Right, mid + 1, e);
- tree[node] = min(tree[Left], tree[Right]);
- }
- int query(int node, int b, int e, int i, int j)
- {
- if (i > e || j < b)
- return INT_MAX; //বাইরে চলে গিয়েছে
- if (b >= i && e <= j)
- return tree[node]; //রিলেভেন্ট সেগমেন্ট
- int Left = node * 2; //আরো ভাঙতে হবে
- int Right = node * 2 + 1;
- int mid = (b + e) / 2;
- int p1 = query(Left, b, mid, i, j);
- int p2 = query(Right, mid + 1, e, i, j);
- return min(p1,p2); //বাম এবং ডান পাশের যোগফল
- }
- int main()
- {
- int ts;
- scanf("%d", &ts);
- for(int p = 1; p <=ts; p++){
- printf("Case %d:\n", p);
- int n, q;
- scanf("%d%d", &n, &q);
- for(int i = 1; i <= n; i++) scanf("%d", &arr[i]);
- init(1, 1, n);
- for(int i = 0;i <q; i++){
- int a, b;
- scanf("%d%d", &a, &b);
- printf("%d\n",query(1, 1, n, a, b));
- }
- }
- return 0;
- }
Saturday, 29 July 2017
Lightoj 1082 - Array Queries
Subscribe to:
Post Comments (Atom)
Most Featured Post
Lightoj 1159 - Batman
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
-
http://lightoj.com/volume_showproblem.php?problem=1382 Problem analysis: This is a rare problem i wrote about so far. After much strugg...
-
http://lightoj.com/volume_showproblem.php?problem=1159 problem analysis: First i thought of this as if s1, s2 and s3 are those three str...
No comments:
Post a Comment