Code Submission Evaluation System Login

Datatähti 2019 alku

Start:2018-10-01 00:00:00
End:2018-10-15 00:00:00
 

Tasks | Messages | Scoreboard | Statistics


CSES - Datatähti 2019 alku - Results
History
2018-10-10 09:43:30100
2018-10-10 09:40:580
2018-10-10 09:38:58
2018-10-08 17:48:1847
2018-10-07 11:51:3847
2018-10-06 22:36:430
2018-10-06 21:06:0512
2018-10-06 20:43:5412
2018-10-06 17:48:0612
2018-10-06 17:38:3412
2018-10-06 15:08:410
2018-10-06 13:19:4312
Task:Taulukko
Sender:valtteriilola
Submission time:2018-10-10 09:38:58
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,
                 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:87:5: note:   'std::begin'
     begin(_Tp (&__arr)[_Nm])
     ^~~~~

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;
}