• ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题目9 : Minimum


    时间限制:1000ms
    单点时限:1000ms
    内存限制:256MB

    描述

    You are given a list of integers a0, a1, …, a2^k-1.

    You need to support two types of queries:

    1. Output Minx,y∈[l,r] {ax∙ay}.

    2. Let ax=y.

    输入

    The first line is an integer T, indicating the number of test cases. (1≤T≤10).

    For each test case:

    The first line contains an integer k (0 ≤ k ≤ 17).

    The following line contains 2k integers, a0, a1, …, a2^k-1 (-2k ≤ ai < 2k).

    The next line contains a integer  (1 ≤ Q < 2k), indicating the number of queries. Then next Q lines, each line is one of:

    1. 1 l r: Output Minx,y∈[l,r]{ax∙ay}. (0 ≤ l ≤ r < 2k)

    2. 2 x y: Let ax=y. (0 ≤ x < 2k, -2k ≤ y < 2k)

    输出

    For each query 1, output a line contains an integer, indicating the answer.

    样例输入
    1
    3
    1 1 2 2 1 1 2 2
    5
    1 0 7
    1 1 2
    2 1 2
    2 2 2
    1 1 2
    样例输出
    1
    1
    4

    线段树模板题,贴个模板代码。

    // Asimple
    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstdlib>
    #include <queue>
    #include <vector>
    #include <string>
    #include <cstring>
    #include <stack>
    #include <set>
    #include <map>
    #include <cmath>
    #define INF 0x3f3f3f3f
    #define debug(a) cout<<#a<<" = "<<a<<endl
    #define test() cout<<"============"<<endl
    #define CLS(a,v) memset(a, v, sizeof(a))
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    int dx[] = {-1,1,0,0,-1,-1,1,1}, dy[]={0,0,-1,1,-1,1,1,-1};
    const int maxn = 140000;
    const ll mod = 233;
    int n, m, T, len, cnt, num, ans, Max, k;
    int x, y;
    pair<int, int> dat[4*maxn];
    
    void init() {
        for (int i = 0; i < 2 * n - 1; ++i) {
            dat[i].first = INF;
            dat[i].second = -INF;
        }
    }
    void update(int k, int x) {
        k += n - 1;
        dat[k] = pair<int, int>(x, x);
        while (k > 0) {
            k = (k - 1) / 2;
            dat[k].first = min(dat[2 * k + 1].first, dat[2 * k + 2].first);
            dat[k].second = max(dat[2 * k + 1].second, dat[2 * k + 2].second);
        }
    }
    
    pair<int, int> query(int a, int b, int k, int l, int r) {
        if (a <= l && r <= b) return dat[k];
        if (a > r || b < l) return pair<int, int>(INF, -INF);
        pair<int, int> vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        pair<int, int> vr = query(a, b, 2 * k + 2, (l + r) / 2 + 1, r);
        return pair<int, int>(min(vl.first, vr.first), max(vl.second, vr.second));
    }
    
    void input(){
        for(scanf("%d", &T); T--; ) {
            scanf("%d", &k);
            n = (int)pow(2, k);
            init();
            for(int i=0; i<n; i++) {
                scanf("%d", &num);
                update(i, num);
            }
            for(scanf("%d", &m); m--; ) {
                scanf("%d%d%d",&k, &x, &y);
                if( k == 2 ) update(x, y);
                else {
                    pair<int, int> p = query(x, y, 0, 0, n-1);
                    ll ans = min((ll)p.first*p.first, min((ll)p.second*p.second, (ll)p.first*p.second));
                    printf("%lld
    ", ans);
                }
            }
        }
    }
    
    int main() {
        input();
        return 0;
    } 
  • 相关阅读:
    expect 函数体 花括号
    bash 连接字符串
    Ubuntu下搭建Python开发环境
    expect
    >&2
    expect语法基础: while、for 循环、if 语句的用法示例
    bash exit
    python开发工具
    eclipse中安装adt出现了duplicate location错误怎样解决
    shell source
  • 原文地址:https://www.cnblogs.com/Asimple/p/7581913.html
Copyright © 2020-2023  润新知