Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- #include <deque>
- #include <algorithm>
- #define ll long long
- using namespace std;
- const ll inf = 1e9;
- vector<int> A;
- int n = 1e9;
- vector<int> t(2 * n, inf);
- void build() {
- n = 1; // размер массива в дереве отрезков
- while (n < A.size()) n *= 2;
- for (int i = n; i < (n + A.size()); ++i) {
- t[i] = A[i - n];
- }
- for (int i = (n - 1); i <= 1; --i) {
- t[i] = min(t[i * 2], t[i * 2 + 1]);
- }
- }
- void set(int ind, int value) {
- ind += n;
- t[ind] = value;
- ind /= 2;
- while (ind >= 1) {
- t[ind] = min(t[ind * 2], t[ind * 2 + 1]);
- ind /= 2;
- }
- }
- int getsum(int l, int r) {
- ll mins = inf;
- l += n;
- r += n;
- int sum = 0;
- for (; l <= r; l /= 2, r /= 2) {
- if (l % 2 == 1) {
- mins = min(mins, t[l]);
- sum += t[l];
- l++;
- }
- if (r % 2 == 0) {
- mins = min(mins, t[r]);
- sum += t[r];
- r--;
- }
- }
- return sum;
- }
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment