洛谷P8572

洛谷P8572

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
#define int long long
int c[705][705];
signed main()
{
    int n, k, q;
    cin >> n >> k >> q;
    //int a[n + 1][k + 1];
    vector<vector<int>> a(k + 1, vector<int>(n + 1));

    for (int i = 1; i <= k;i++)
        for (int j = 1; j <= n;j++)
        {
            int x;
            cin >> x;
            a[i][j] = a[i][j - 1] + x;
        }

    if(n<=700)
    {
        
        for (int i = 1; i <= k;i++)
            for (int j = 1; j <= n;j++)
                for (int p = 1; p <= n;p++)
                    c[j][p] = max(c[j][p], a[i][p] - a[i][j - 1]);

        while(q--)
        {
            int l, r;
            cin >> l >> r;
            cout << c[l][r] << endl;
        }

        return 0;
    }    

    while(q--)
    {
        int l, r, mx = 0;
        cin>>l>>r;
        for (int i = 1; i <= k;i++)
            mx = max(mx, a[i][r] - a[i][l - 1]);
        cout << mx << endl;
    }

}
相关推荐
lisw056 小时前
稀疏算法概述!
算法·机器人·无人机
思想觉悟7 小时前
Aosp实战之自定义开机启动进程
c++·面试
YLCHUP7 小时前
【括号匹配+dp优化】题解:双端括号(brackets)_动态规划_状态优化_数学建模_贪心_性质挖掘_STLmap_C++算法竞赛
数据结构·c++·笔记·算法·数学建模·贪心算法·动态规划
郝学胜-神的一滴8 小时前
Effective STL 条款09:慎重选择删除元素的方法
开发语言·网络·数据结构·c++·算法·stl
geovindu12 小时前
python:Logistic Regression
开发语言·后端·python·算法
geovindu13 小时前
python: Random Forest
开发语言·后端·python·算法·随机森林
derek199714 小时前
软考软件设计师:主键、传递依赖和冗余,三问其实是一件事
c语言·c++·计算机网络·软件工程·学习方法
凌冰_14 小时前
数据结构 - 线性结构(三)
java·数据结构·算法·软件工程
拂拉氏15 小时前
【知识讲解】 数据结构与算法-树状数组的认识
数据结构·算法·树状数组
艾莉丝努力练剑15 小时前
【AI大模型接入SDK】解决Unicode码转化以及界面变形问题
前端·c++·人工智能·学习·安全·架构