CSES - Datatähti 2019 alku - Results
Submission details
Task:Taulukko
Sender:valtteriilola
Submission time:2018-10-10 09:38:58 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:35:16: error: 'end' was not declared in this scope
         sum += end - begin;
                ^~~
input/code.cpp:35:16: note: suggested alternative:
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from input/code.cpp:1:
/usr/include/c++/7/bits/range_access.h:97:5: note:   'std::end'
     end(_Tp (&__arr)[_Nm])
     ^~~
input/code.cpp:35:22: error: 'begin' was not declared in this scope
         sum += end - begin;
                      ^~~~~
input/code.cpp:35:22: note: suggested alternative:
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,...

Code

#include <iostream>
#include <vector>
#include <map>

using ul = unsigned long;


int main() {
    ul max_size, window_size;
    std::cin >> max_size >> window_size;

    auto grid = std::vector<int>(max_size);

    for (auto &num : grid) {
        std::cin >> num;
    }

    ul sum = 0;

    std::map<int, int> seen;

    auto left  = grid.begin() - 1;
    auto right = grid.begin() - 1;

    while (right != grid.end()) {
        right++;
        seen[*right]++;

        while (seen.size() > window_size) {
            left++;
            if (--seen[*left] == 0) {
                seen.erase(*left);
            }
        }
        sum += end - begin;
    }


    std::cout << sum << std::endl;
}