답안 #202001

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
202001 2020-02-13T02:55:14 Z _7_7_ Examination (JOI19_examination) C++14
2 / 100
3000 ms 191524 KB
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 333;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e5 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

inline int R () {
	char c;
	bool is_negative = 0, started = 0;
	int ans = 0;
	while (1) {
		c = getchar();
		if ((c > '9' || c < '0') && c != '-' && !started)
			continue;
		if ((c > '9' || c < '0') && c != '-' && started)
			break;
		started = 1;
		if (c == '-')
			is_negative = 1;
		else
			ans = ans * 10 + c - '0';
	}

	return ans;
}

int n, q, X[N], Y[N], res[N];
unordered_map < int, int > t[N];


struct node {
	int x, y;
	bool operator < (const node &a) const {	
		return X[x] + Y[y] > X[a.x] + Y[a.y];
	}	
} d[N];

struct query {
	int a, b, c, id;
	bool operator < (const query &x) const {
		return c > x.c;
	}
} e[N];


void inc (int x, int y) {
	x = N - 1 - x;
	y = N - 1 - y;
	while (x < N) {
		int yy = y;
		while (yy < N)  {
			++t[x][yy];
			yy += (yy & -yy);
		}
		x += (x & -x);
	}
}

int get (int x, int y) {
	x = N - 1 - x;
	y = N - 1 - y;
	int res = 0;
	while (x > 0) {
		int yy = y;
		while (yy > 0) {
			if (t[x].count(yy))
				res += t[x][yy];
			yy -= (yy & -yy);
		}
		x -= (x & -x);
	}
	return res;
}


main () {
//	file("");
	n = R(), q = R();
	forn (i, 1, n) {
		d[i].x = R();
		d[i].y = R();
		X[i] = d[i].x;
		Y[i] = d[i].y;
	}

	sort(X + 1, X + 1 + n);
	sort(Y + 1, Y + 1 + n);

	forn (i, 1, n) {
		d[i].x = lower_bound(X + 1, X + 1 + n, d[i].x) - X;
		d[i].y = lower_bound(Y + 1, Y + 1 + n, d[i].y) - Y;
	}



	forn (i, 1, q) {
		e[i].a = R(); 
		e[i].b = R();	
		e[i].c = R();
		e[i].id = i;
		e[i].a = lower_bound(X + 1, X + 1 + n, e[i].a) - X;
		e[i].b = lower_bound(Y + 1, Y + 1 + n, e[i].b) - Y;
	}

	sort(d + 1, d + 1 + n);
	sort(e + 1, e + 1 + q);

	int j = 1;
	forn (i, 1, q) {
		while (j <= n && X[d[j].x] + Y[d[j].y] >= e[i].c) {
			inc(d[j].x, d[j].y);
//			cerr << " + " << d[j].x << ' ' << d[j].y << endl;
			++j;
		}
//		cerr << e[i].a << ' ' << e[i].b << " = " << get(e[i].a, e[i].b) << endl;
		res[e[i].id] = get(e[i].a, e[i].b);
	}

	forn (i, 1, q)
		printf("%d\n", res[i]);
}


Compilation message

examination.cpp: In function 'int R()':
examination.cpp:42:7: warning: variable 'is_negative' set but not used [-Wunused-but-set-variable]
  bool is_negative = 0, started = 0;
       ^~~~~~~~~~~
examination.cpp: At global scope:
examination.cpp:109:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5880 KB Output is correct
2 Correct 9 ms 5752 KB Output is correct
3 Correct 8 ms 5752 KB Output is correct
4 Correct 8 ms 5752 KB Output is correct
5 Correct 9 ms 5752 KB Output is correct
6 Correct 9 ms 5880 KB Output is correct
7 Correct 27 ms 8696 KB Output is correct
8 Correct 27 ms 8824 KB Output is correct
9 Correct 27 ms 8696 KB Output is correct
10 Correct 21 ms 7672 KB Output is correct
11 Correct 22 ms 7544 KB Output is correct
12 Correct 15 ms 6008 KB Output is correct
13 Correct 32 ms 8824 KB Output is correct
14 Correct 28 ms 8824 KB Output is correct
15 Correct 28 ms 8824 KB Output is correct
16 Correct 14 ms 6136 KB Output is correct
17 Correct 15 ms 6264 KB Output is correct
18 Correct 12 ms 5880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3015 ms 191524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3015 ms 191524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 5880 KB Output is correct
2 Correct 9 ms 5752 KB Output is correct
3 Correct 8 ms 5752 KB Output is correct
4 Correct 8 ms 5752 KB Output is correct
5 Correct 9 ms 5752 KB Output is correct
6 Correct 9 ms 5880 KB Output is correct
7 Correct 27 ms 8696 KB Output is correct
8 Correct 27 ms 8824 KB Output is correct
9 Correct 27 ms 8696 KB Output is correct
10 Correct 21 ms 7672 KB Output is correct
11 Correct 22 ms 7544 KB Output is correct
12 Correct 15 ms 6008 KB Output is correct
13 Correct 32 ms 8824 KB Output is correct
14 Correct 28 ms 8824 KB Output is correct
15 Correct 28 ms 8824 KB Output is correct
16 Correct 14 ms 6136 KB Output is correct
17 Correct 15 ms 6264 KB Output is correct
18 Correct 12 ms 5880 KB Output is correct
19 Execution timed out 3015 ms 191524 KB Time limit exceeded
20 Halted 0 ms 0 KB -