Pagini recente » Cod sursa (job #2619498) | Cod sursa (job #1505818) | Cod sursa (job #149805) | Cod sursa (job #2092757) | Cod sursa (job #2408343)
#include <fstream>
#include <algorithm>
// sort separat + id de segment ( inchis / deschis )
// de inversat x cu y, y = linia, x = coloana defapt
#define NMAX 50000
#define MMAX 100000
#define CMAX 1000000
using namespace std;
ifstream fin ( "ograzi.in" );
ofstream fout ( "ograzi.out" );
struct Points {
int x, y;
};
Points segment[1 + 2 * NMAX];
int N, M, W, H;
Points oaie[1 + MMAX];
int aib[1 + CMAX];
bool cmp ( Points a, Points b ) {
if ( a.y == b.y )
return a.x < b.x;
return a.y < b.y;
}
void update ( int poz ) {
for ( ; poz <= CMAX; poz += ( poz & ( -poz ) ) )
++aib[poz];
}
int query ( int poz ) {
int ans = 0;
for ( ; poz > 0; poz -= ( poz & ( -poz ) ) )
ans += aib[poz];
return ans;
}
int main () {
fin >> N >> M >> W >> H;
//fout << N << ' ' << M << ' ' << W << ' ' << H << '\n';
for ( int i = 1; i <= N; ++i ) {
fin >> segment[i].x >> segment[i].y;
++segment[i].x;
++segment[i].y;
segment[N + i] = ( Points ) { segment[i].x + H - 1, segment[i].y };
}
for ( int i = 1; i <= M; ++i ) {
fin >> oaie[i].x >> oaie[i].y;
++oaie[i].x;
++oaie[i].y;
}
sort ( oaie + 1, oaie + M + 1, cmp );
sort ( segment + 1, segment + N + 1, cmp );
sort ( segment + N + 1, segment + 2 * N + 1, cmp );
/*fout << "OAIE:\n";
for ( int i = 1; i <= M; ++i )
fout << oaie[i].x << ' ' << oaie[i].y << '\n';
fout << "SEGMENT:\n";
for ( int i = 1; i <= N; ++i )
fout << segment[i].x << ' ' << segment[i].y << ' ' << segment[i + N].x << ' ' << segment[i + N].y << '\n';
*/
int poz = 1;
int ans = 0;
for ( int i = 1; i <= N; ++i ) {
int x = segment[i].x;
int y = segment[i].y + W - 1;
while ( poz <= M && oaie[poz].y < y ) {
update ( oaie[poz].x );
++poz;
}
ans = ans - query ( x ) ;
fout << ans << '\n';
x = segment[i + N].x;
y = segment[i + N].y + W - 1;
while ( poz <= M && oaie[poz].y <= y ) {
update ( oaie[poz].x );
++poz;
}
ans = ans + query ( x );
fout << ans << '\n';
}
fout << M - ans;
return 0;
}