World Robot Contest2025-2026Algorithm Application ThemeJunior Highwrc.hao.work
WRC
Contest Archive / Structured Dossiers青少年算法应用训练档案馆

把训练题、知识点、执行证据和最终解题档案统一归档成可直接浏览的竞赛资料库。

Archive30 Cases

四大文化赛道完整展开

AccessHTTPS

完整题面 / 题解 / 运行证据

No Rounded CornersTailwind FirstDossier Ready
02-solution/src/cpp/main.cpp

main.cpp

站内文件视图直接读取仓库内容,Markdown 使用文档排版渲染,其余文本文件保持原始排版,方便校对训练证据链。

文件类型.cpp

10-cases/s4-jh-06-dye-batch-query/02-solution/src/cpp/main.cpp

#include <iostream>
#include <vector>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q;
    if (!(cin >> n >> q)) {
        return 0;
    }
    vector<long long> prefix(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
        long long value;
        cin >> value;
        prefix[i] = prefix[i - 1] + value;
    }
    int best_query = 1;
    long long best_sum = -1;
    for (int query_id = 1; query_id <= q; ++query_id) {
        int left, right;
        cin >> left >> right;
        long long total = prefix[right] - prefix[left - 1];
        cout << "query_" << query_id << "=" << total << "\n";
        if (total > best_sum) {
            best_sum = total;
            best_query = query_id;
        }
    }
    cout << "max_query=" << best_query << "\n";
    return 0;
}