Cod sursa(job #1031644)

Utilizator ioalexno1Alexandru Bunget ioalexno1 Data 15 noiembrie 2013 18:13:27
Problema Dtcsu Scor 0
Compilator cpp Status done
Runda FMI No Stress 4 Marime 2.04 kb
#include <cstdio>
#include <cstdlib>
#include<iostream>
#include<algorithm>

using namespace std;

FILE *f = fopen("dtcsu.in","r");
FILE *g = fopen("dtcsu.out","w");

#define ll long long
#define PAS1 93000
#define PAS2 185000
#define PAS3 276997
#define mid ((li+ls)>>1)

int lungime;
long long x;
char S[1000];
ll A[100000];
int Sol;

inline ll getInt(void)
{
    ll a = 0;

    for(int i=0;isdigit(S[i]);a = a * 10 + S[i++]-'0');

    return a;
}

inline void preprocesare(void)
{
    sort(A+1,A+lungime+1);
}

inline int cautBin(int li,int ls,ll val)
{
    if(li > ls)
        return 0;

    if(A[mid] == val)
        return 1;

    if(A[mid] > val)
        return cautBin(li,mid-1,val);
    else
        return cautBin(mid+1,ls,val);
}

int main(){
    
    //Prima treime
    for(lungime=1;lungime<=PAS1;lungime++)
    {
        fgets(S,sizeof(S),f);
        A[lungime] = getInt();
    }
    -- lungime;
    for(int i=PAS2;i<=PAS3;i++)
        fgets(S,sizeof(S),f);

    preprocesare();

    int q;
    fscanf(f, "%d\n", &q );
    for(; q >= 1; --q ){
        
        fgets(S,sizeof(S),f);
        x = getInt();
        Sol += cautBin(1,lungime,x);
    }

    rewind(f);

    //A doua treime
    for(int i=1;i<=PAS1;i++)
        fgets(S,sizeof(S),f);
    for(lungime=1;PAS1+lungime <= PAS2;lungime++)
    {
        fgets(S,sizeof(S),f);
        A[lungime] = getInt();
    }
    -- lungime;
    for(int i=PAS2+1;i<=PAS3;i++)
        fgets(S,sizeof(S),f);

    preprocesare();

    fscanf(f,"%d\n",&q);
    for(int i=1;i<=q;i++)
    {
        fgets(S,sizeof(S),f);
        x = getInt();
        Sol += cautBin(1,lungime,x);
    }

    rewind(f);

    //A treia treime
    for(int i=1;i<=PAS2;i++)
        fgets(S,sizeof(S),f);
    for(lungime=1;PAS2+lungime <= PAS3;lungime++)
    {
        fgets(S,sizeof(S),f);
        A[lungime] = getInt();
    }
    -- lungime;

    preprocesare();

    fscanf(f,"%d\n",&q);
    for(int i=1;i<=q;i++)
    {
        fgets(S,sizeof(S),f);
        x = getInt();
        Sol += cautBin(1,lungime,x);
    }

    fprintf(g, "%d", Sol);
    return 0;
}