zoukankan      html  css  js  c++  java
  • [线段树][ZZNUOJ]易水寒

    没必要用线段树

    只是想练习一下

    #pragma GCC optimize(2)
    #include <cstdio>
    #include <iostream>
    #include <cstdlib>
    #include <cmath>
    #include <cctype>
    #include <string>
    #include <cstring>
    #include <algorithm>
    #include <stack>
    #include <queue>
    #include <set>
    #include <map>
    #include <ctime>
    #include <vector>
    #include <fstream>
    #include <list>
    #include <iomanip>
    #include <numeric>
    using namespace std;
    typedef long long ll;
    
    const int MAXN = 1e6 + 100;
    
    ll arr[MAXN] = {0};
    
    ll tree[MAXN * 4 + 10] = {0};
    
    void buildtree(int now, int l, int r)
    {
    	if(l == r)
    	{
    		tree[now] = arr[l];
    		return ;
    	}
    
    	int mid = l + (r - l) / 2;
    
    	buildtree(now * 2, l, mid);
    
    	buildtree(now * 2 + 1, mid + 1, r);
    
    	tree[now] = max(tree[now * 2], tree[now * 2 + 1] );
    
    }
    
    ll find(int now, int l, int r, int x, int y)
    {
    	if(r < x || l > y)
    		return -1;
    	if(x <= l && y >= r)
    		return tree[now];
    
    	int mid = l + (r - l) / 2;
    
    	ll ans = 0;
    
    	ans = max(ans, find(now * 2, l, mid, x, y) );
    
    	ans = max(ans, find(now * 2 + 1, mid + 1, r, x, y) );
    
    	return ans;
    
    }
     
    ll findt(int now, int l, int r, int x, int y)
    {
    	if(r < x || l > y)
    		return -1;
    	if(x <= l && y >= r)
    		return tree[now];
     
    	int mid = l + (r - l) / 2;
     
    	ll ans = 0;
     
    	ans = max(ans, find(now * 2, l, mid, x, y) );
     
    	ans = max(ans, find(now * 2 + 1, mid + 1, r, x, y) );
     
    	return ans;
     
    }
    
    
    int main()
    {
    	ios::sync_with_stdio(false);
    
    	cin.tie(0);
    
    	cout.tie(0);
    
    	int T;
    
    	cin>>T;
    	
    	for(int m = 1; m <= T; m++)
    	{
    		memset(arr, 0, sizeof(arr));
    
    		memset(tree, 0, sizeof(arr));
    
    		int len;
    
    		cin>>len;
    
    		for(int i = 1; i <= len; i++)
    		{
    			cin>>arr[i];
    		}
    
    		ll ans = 0;
    		
    		buildtree(1, 1, len);
    
    		for(int i = 1; i <= len; i++)
    		{
    			ans = max(ans,  findt(1, 1, len, i + 1, len) - arr[i]);
    		}
    		
    		cout<<"Case #"<<m<<": "<<ans<<endl;
    	}
        
    
        return 0;
    }
  • 相关阅读:
    使用VideoView开发视频总结
    后台接口向数据库录入汉字时乱码以及自动过滤文字经验总结
    8 Crash Reporting Tools For iOS And Android Apps
    Best Mobile Crash Reporting Software
    How do I obtain crash-data from my Android application?
    ACRA (Automated Crash Reporting for Android)
    Debugging Neural Networks with PyTorch and W&B
    OpenPose MobileNet V1
    Real-time-human-pose-estimation-by-pytorch
    openpose-pytorch
  • 原文地址:https://www.cnblogs.com/zeolim/p/12270496.html
Copyright © 2011-2022 走看看