Pagini recente » Cod sursa (job #429242) | Cod sursa (job #63202) | Cod sursa (job #1031194) | Cod sursa (job #318811) | Cod sursa (job #3291793)
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
struct elem{
int x, y;
};
struct fast_elem{
int poz1, poz2, x;
};
struct fast_map{
const int MOD = 983875;
vector <fast_elem> v[983875];
void add_elem(int poz1, int poz2, int x){
poz1++;
poz2++;
v[1ll * poz1 * poz2 % MOD].push_back( { poz1, poz2, x } );
}
int get_elem(int poz1, int poz2){
int x, i;
//return -1;
poz1++;
poz2++;
x = 1ll * poz1 * poz2 % MOD;
//cout << poz1 << ' ' << poz2 << ' ' << x << '\n';
i = 0;
while( i < v[x].size() && ( v[x][i].poz1 != poz1 || v[x][i].poz2 != poz2 ) ){
i++;
}
//cout << i << '\n';
if( i < v[x].size() ){
return v[x][i].x;
}
return -1;
}
};
vector <elem> v;
fast_map f;
int w, h;
int check(int x, int y, int poz){
if( poz == -1 ){
return 0;
}
//cout << x << ' ' << y << ' ' << v[poz].x << ' ' << v[poz].y << '\n';
if( v[poz].x <= x && v[poz].y <= y && v[poz].x + w >= x && v[poz].y + h >= y ){
return 1;
}
return 0;
}
FILE *FIN = fopen( "ograzi.in", "r" );
static inline elem read(){
int x, y, i;
char s[100];
fgets( s, 100, FIN );
//cout << s << '\n';
i = x = 0;
while( s[i] != ' ' ){
x = x * 10 + s[i] - '0';
i++;
}
i++;
y = 0;
while( '0' <= s[i] && s[i] <= '9' ){
//cout << s[i] << ' ';
y = y * 10 + s[i] - '0';
i++;
}
//cout << '\n';
return { x, y };
}
int main(){
int n, m, i, x, y, r, ad;
elem a;
ifstream fin( "ograzi.in" );
ofstream fout( "ograzi.out" );
fin >> n >> m >> w >> h;
read();
for( i = 0; i < n; i++ ){
a = read();
//fin >> x >> y;
x = a.x;
y = a.y;
//cout << x << ' ' << y << '\n';
v.push_back( { x, y } );
f.add_elem( x / w, y / h, i );
}
r = 0;
for( i = 0; i < m; i++ ){
a = read();
x = a.x;
y = a.y;
//cout << x << ' ' << y << '\n';
ad = max( check( x, y, f.get_elem( x / w, y / h ) ), check( x, y, f.get_elem( x / w - 1, y / h ) ) );
ad = max( check( x, y, f.get_elem( x / w, y / h - 1 ) ), ad );
ad = max( check( x, y, f.get_elem( x / w - 1, y / h - 1 ) ), ad );
r += ad;
}
fout << r;
return 0;
}