Cod sursa(job #3333520)

Utilizator Mateixx1Trandafir Matei Mateixx1 Data 13 ianuarie 2026 20:17:29
Problema Secventa 5 Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <iostream>
#include <unordered_map>
#include <fstream>
using namespace std;
ifstream f("secv5.in");
ofstream g("secv5.out");
const int NMAX=(1<<20)+1;
int n,l,u,st;
unsigned int v[NMAX];
unordered_map<unsigned int,unsigned int> q;

unsigned int ra(int x) {
    q.clear();
    st=1;
    unsigned int cate=0;
    for(int i=1; i<=n; ++i) {
        ++q[v[i]];
        while(x<q.size()) {
            q[v[st]]--;
            if(!q[v[st]]) {
                q.erase(v[st]);
            }
            st++;
        }
        cate+=i-st+1;
    }
    return cate;
}

int main() {
    f>>n>>l>>u;
    for(int i=1; i<=n; ++i) {
        f>>v[i];
    }
    g<<ra(u)-ra(l-1);
    f.close();
    g.close();
    return 0;
}