Cod sursa(job #2450533)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 23 august 2019 16:47:06
Problema Secventa 5 Scor 0
Compilator cpp-64 Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I Marime 1.41 kb
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007

using namespace std;

typedef long long ll;


int add(int a, int b)
{
    ll x = a+b;
    if(x >= mod)
        x -= mod;
    if(x < 0)
        x += mod;
    return x;
}
ll mul(ll a, ll b)
{
    return (a*b) % mod;
}

ll pw(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

ifstream f("secv5.in");
ofstream g("secv5.out");

unsigned n, L, R, v[(1<<20) + 2];
unordered_map<unsigned, int>mp;
ll seq(int mx)
{
    memset(frq, 0, sizeof(frq));
    int st = 1;
    int dr = 1;
    int countt = 0;
    ll ans = 0;
    while(st <= n)
    {
        while(dr <= n && countt <= mx)
        {
            if(mp[v[dr]] == 0 && countt == mx)
                break;
            if(mp[v[dr]] == 0)
                ++countt;
            ++mp[v[dr]];
            ++dr;
        }
        ans += dr - st;
        --mp[v[st]];
        if(mp[v[st]] == 0)
            --countt;
        ++st;
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    f >> n >> L >> R;
    for(int i = 1; i <= n; ++i)
        f >> v[i];
    g << seq(R) - seq(L-1) << '\n';
    return 0;
}