CSES - Datatähti 2019 alku - Results
Submission details
Task:Taulukko
Sender:Kameli
Submission time:2018-10-03 12:12:29 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:48:32: error: 'rumbers' was not declared in this scope
         if(k==diff_numbers && !rumbers[t[e+1]]!=0){
                                ^~~~~~~
input/code.cpp:48:32: note: suggested alternative: 'numbers'
         if(k==diff_numbers && !rumbers[t[e+1]]!=0){
                                ^~~~~~~
                                numbers

Code

#include <iostream>
#include <unordered_map>

using namespace std;
long n, k;

bool check(unordered_map<long,long> map, long index){

    return map[index]!=0;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>k;
    long t[n];
    for(long i=0;i<n;i++){
        cin>>t[i];
    }
    long b=0;
    long e=0;
    long last_e=-1;
    long c=0;

    unordered_map<long, long> numbers;
    numbers[t[0]]=1;
    
    long diff_numbers=1;

    while(true){
        if(e==n-1){
            c+=((e-b+1)*(e-b+1)+(e-b+1))/2;
            if (last_e>=b){
                c-=((last_e-b+1)*(last_e-b+1)+(last_e-b+1))/2;
            }
            break;
        }
        if(k<diff_numbers){
            e+=1;
            if(numbers[t[e]]!=0){
                diff_numbers+=1;
                numbers[t[e]]=1;
            }else{
                numbers[t[e]]+=1;
            }
            continue;
        }
        if(k==diff_numbers && !rumbers[t[e+1]]!=0){
            c+=((e-b+1)*(e-b+1)+(e-b+1))/2;
            if(last_e>=b){
                c-=((last_e-b+1)*(last_e-b+1)+(last_e-b+1))/2;
            }
            last_e=e;
            if(check(numbers,t[b])){
                if(numbers[t[b]]==1){
                    numbers.erase(t[b]);
                    diff_numbers-=1;
                }
                else{
                    numbers[t[b]]-=1;
                }
            }
            b+=1;
        }
        else{
            e+=1;
            if(check(numbers,t[e])){
                numbers[t[e]]+=1; 
            }
            else{
                numbers[t[e]]=1;
                diff_numbers+=1;
            }
        }
    }
    cout<<c<<"\n";
}