Cod sursa(job #2091920)

Utilizator MihaelaCismaruMihaela Cismaru MihaelaCismaru Data 20 decembrie 2017 16:28:46
Problema Hvrays Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.27 kb
#include<fstream>
#include<algorithm>
using namespace std;
class InParser {
private:
    FILE *fin;
    char *buff;
    int sp;

    char read_ch() {
        ++sp;
        if (sp == 4096) {
            sp = 0;
            fread(buff, 1, 4096, fin);
        }
        return buff[sp];
    }

public:
    InParser(const char* nume) {
        fin = fopen(nume, "r");
        buff = new char[4096]();
        sp = 4095;
    }

    InParser& operator >> (int &n) {
        char c;
        while (!isdigit(c = read_ch()) && c != '-');
        int sgn = 1;
        if (c == '-') {
            n = 0;
            sgn = -1;
        } else {
            n = c - '0';
        }
        while (isdigit(c = read_ch())) {
            n = 10 * n + c - '0';
        }
        n *= sgn;
        return *this;
    }

    InParser& operator >> (long long &n) {
        char c;
        n = 0;
        while (!isdigit(c = read_ch()) && c != '-');
        long long sgn = 1;
        if (c == '-') {
            n = 0;
            sgn = -1;
        } else {
            n = c - '0';
        }
        while (isdigit(c = read_ch())) {
            n = 10 * n + c - '0';
        }
        n *= sgn;
        return *this;
    }
} in( "hvrays.in" );
ofstream out ("hvrays.out");
int n,m,t,lp,ilp,sol;
struct punct {
    int a,b;
}o[100001],v[10001],last_point;
bool cmp (punct x, punct y) {
    if (x.a == y.a) {
        return x.b < y.b;
    }
    return x.a < y.a;
}
int main (void) {
    in >> t;
    for (int h = 1; h <= t; h ++) {
        in >> n >> m;
        for (int i = 1; i <= n; i ++) {
            in >> o[i].a >> o[i].b;
        }
        for (int i = 1; i <= m; i ++) {
            in >> v[i].a >> v[i].b;
        }
        sort (v + 1, v + m + 1,cmp);
        sort (o + 1, o + n + 1,cmp);
        sol = 0; lp = 1; ilp = 1; last_point = {0,0};
        for (int i = 1; i <= n; i ++) {
            if (o[i].a > v[ilp].a) {
                sol ++;
                lp = 1;
                while (lp <= m && o[i].a <= v[lp].a) {
                    if (o[i].b > v[lp].b) {
                        ilp = lp;
                    }
                    lp ++;
                }
            }
        }
        out << sol<<"\n";
    }
    return 0;
}