CSES - Datatähti 2019 alku - Results
Submission details
Task:Taulukko
Sender:borkbork
Submission time:2018-10-09 15:22:57 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:21:29: error: 'map' was not declared in this scope
     for(size_t i=0;i<k;i++){map[d[i]]++;}
                             ^~~
input/code.cpp:21:29: note: suggested alternative: 'main'
     for(size_t i=0;i<k;i++){map[d[i]]++;}
                             ^~~
                             main
input/code.cpp:23:9: error: 'map' was not declared in this scope
         map[d[i+size]]++;
         ^~~
input/code.cpp:23:9: note: suggested alternative: 'main'
         map[d[i+size]]++;
         ^~~
         main

Code

#include<iostream>
#include<unordered_set>
#include<unordered_map>
#include<vector>

int main(){
    std::ios_base::sync_with_stdio(0);std::cin.tie(NULL);
    unsigned int n,k;
    std::cin>>n>>k;
    unsigned int d[500100];
    for(size_t i=0;i<n;i++){std::cin>>d[i];}
    
    unsigned long long res=n*k;
    if(1<k) res-=((k)*(k-1))/2;

    if(n==k){std::cout<<res;return 0;}
    if(k<n/3)
    std::unordered_map<unsigned int,unsigned int> map;

    unsigned int size = k;
    for(size_t i=0;i<k;i++){map[d[i]]++;}
    for(size_t i=0;i<n-k;i++){
        map[d[i+size]]++;

        if(map[d[i]]<2){map.erase(d[i]);}
        else{map[d[i]]--;}

    }
    for(size_t i=0;i<n;i++){d[i]++;}

    std::cout<<res;
    
}