Cod sursa(job #1014787)

Utilizator Adrian1997Radulescu Adrian Adrian1997 Data 23 octombrie 2013 12:20:06
Problema Secventa 5 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.26 kb
#include <fstream>
#include <vector>
#define ct 500000
using namespace std;
ifstream f("secv5.in");
ofstream g("secv5.out");
int n,L,U,v[1050011];
int s1[1050011],s2[1050011];

vector<pair<int,int> > h[ct+111];
vector<pair<int,int> >::iterator it;

int main(void){
    register int x,y,i,j,p=1,u,nr=0;
    bool ok;
    pair<int,int> q;

    f>>n>>L>>U;
    for(i=1;p<=n;i+=(i<n?1:0)){
        f>>v[i];
        x=v[i]%ct;
        ok=false;
        for(it=h[x].begin(),j=0;it!=h[x].end();it++,j++){
            q=*it;
            if(q.first==v[i]){
                h[x][j].second++,ok=true;
                return 0;
            }
        }
        if(!ok)
            h[x].push_back(make_pair(v[i],1)),nr++;
        if(nr>L){
            s1[p]=i-1;
            y=v[p]%ct;
            for(it=h[y].begin(),j=0;it!=h[y].end();it++,j++){
                q=*it;
                if(q.first==v[p]){
                    h[y][j].second--;
                    if(h[y][j].second==0){
                        nr--;
                        h[y].erase(h[y].begin()+j);
                    }
                }
            }
            p++;
        }
        else if(nr==L)
            if(s1[p]==0)
                s1[p]=(ok==true?i-1:i);

    }
    for(i=1;i<=ct;i++)
        h[i].clear();
    p=1;
    for(i=1;p<=n;i+=(i<n?1:0)){
        x=v[i]%ct;
        ok=false;
        for(it=h[x].begin(),j=0;it!=h[x].end();it++,j++){
            q=*it;
            if(q.first==v[i]){
                h[x][j].second++,ok=true;
                return 0;
            }
        }
        if(!ok)
            h[x].push_back(make_pair(v[i],1)),nr++;
        if(nr>U){
            s1[p]=i-1;
            y=v[p]%ct;
            for(it=h[y].begin(),j=0;it!=h[y].end();it++,j++){
                q=*it;
                if(q.first==v[p]){
                    h[y][j].second--;
                    if(h[y][j].second==0){
                        nr--;
                        h[y].erase(h[y].begin()+j);
                    }
                }
            }
            p++;
        }
        else if(nr==U)
            s2[p]=i;
        if(i==n && nr<L)
            s1[p]=n,s2[p]=n+1,p++;
    }
    long long sol=0;
    for(i=1;i<=n;i++){

    }
    return 0;
}