답안 #123680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123680 2019-07-02T03:52:22 Z 박상수(#3035) Examination (JOI19_examination) C++14
100 / 100
395 ms 20700 KB
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb push_back
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;

int N, Q;
pll p[100010];
ll ans[100010];
ll In[100010][3];
vector <int> ID[200020];
vector <ll> xx, yy;
int T[2][200020];

int main() {
	scanf("%d%d", &N, &Q);
	for(int i=1;i<=N;i++) {
		ll x, y;
		scanf("%lld%lld", &x, &y);
		p[i] = pll(x, y);
		xx.pb(x); yy.pb(y);
	}
	vector <ll> xy;
	for(int i=1;i<=N;i++) xy.pb(p[i].Fi + p[i].Se);
	sort(all(xy));
	for(int i=1;i<=Q;i++) {
		ll A, B, C;
		scanf("%lld%lld%lld", &A, &B, &C);
		if(C < A + B) C = A + B;
		ans[i] = N - (int)(lower_bound(all(xy), C) - xy.begin());
		In[i][0] = A, In[i][1] = B, In[i][2] = C;
	}
	for(int i=1;i<=Q;i++) xy.pb(In[i][2]);
	sort(all(xy)); xy.resize(unique(all(xy)) - xy.begin());
	sort(all(xx)); xx.resize(unique(all(xx)) - xx.begin());
	sort(all(yy)); yy.resize(unique(all(yy)) - yy.begin());
	for(int i=1;i<=N;i++) {
		ll v = p[i].Fi + p[i].Se;
		int pi = (int)(lower_bound(all(xy), v) - xy.begin());
		ID[pi].pb(i);
	}
	for(int i=1;i<=Q;i++) {
		int pi = (int)(lower_bound(all(xy), In[i][2]) - xy.begin());
		ID[pi].pb(-i);
	}
	auto update = [&](int T[200020], int x, int v) { for(int i=x;i<200020;i+=(i&-i)) T[i] += v; };
	auto read = [&](int T[200020], int x) { int res = 0; for(int i=x;i;i-=(i&-i)) res += T[i]; return res; };
	for(int i=szz(xy)-1;i>=0;i--) {
		for(int e : ID[i]) if(e > 0) {
			int xi = (int)(lower_bound(all(xx), p[e].Fi) - xx.begin() + 1);
			int yi = (int)(lower_bound(all(yy), p[e].Se) - yy.begin() + 1);
			update(T[0], xi, 1);
			update(T[1], yi, 1);
		}
		for(int e : ID[i]) if(e < 0) {
			e = -e;
			ll x = In[e][0], y = In[e][1];
			int xi = (int)(lower_bound(all(xx), x) - xx.begin());
			int yi = (int)(lower_bound(all(yy), y) - yy.begin());
			ans[e] -= read(T[0], xi);
			ans[e] -= read(T[1], yi);
		}
	}
	
	for(int i=1;i<=Q;i++) printf("%lld\n", ans[i]);
	return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &Q);
  ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
examination.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld", &A, &B, &C);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 7 ms 5112 KB Output is correct
5 Correct 7 ms 5112 KB Output is correct
6 Correct 7 ms 5112 KB Output is correct
7 Correct 13 ms 5624 KB Output is correct
8 Correct 13 ms 5496 KB Output is correct
9 Correct 13 ms 5496 KB Output is correct
10 Correct 12 ms 5624 KB Output is correct
11 Correct 12 ms 5496 KB Output is correct
12 Correct 9 ms 5368 KB Output is correct
13 Correct 13 ms 5496 KB Output is correct
14 Correct 12 ms 5496 KB Output is correct
15 Correct 12 ms 5496 KB Output is correct
16 Correct 11 ms 5624 KB Output is correct
17 Correct 11 ms 5500 KB Output is correct
18 Correct 8 ms 5496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 332 ms 17628 KB Output is correct
2 Correct 330 ms 17580 KB Output is correct
3 Correct 314 ms 17632 KB Output is correct
4 Correct 234 ms 16480 KB Output is correct
5 Correct 231 ms 16624 KB Output is correct
6 Correct 115 ms 14680 KB Output is correct
7 Correct 298 ms 17548 KB Output is correct
8 Correct 303 ms 17500 KB Output is correct
9 Correct 275 ms 17140 KB Output is correct
10 Correct 221 ms 16348 KB Output is correct
11 Correct 220 ms 16428 KB Output is correct
12 Correct 84 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 332 ms 17628 KB Output is correct
2 Correct 330 ms 17580 KB Output is correct
3 Correct 314 ms 17632 KB Output is correct
4 Correct 234 ms 16480 KB Output is correct
5 Correct 231 ms 16624 KB Output is correct
6 Correct 115 ms 14680 KB Output is correct
7 Correct 298 ms 17548 KB Output is correct
8 Correct 303 ms 17500 KB Output is correct
9 Correct 275 ms 17140 KB Output is correct
10 Correct 221 ms 16348 KB Output is correct
11 Correct 220 ms 16428 KB Output is correct
12 Correct 84 ms 14428 KB Output is correct
13 Correct 317 ms 17596 KB Output is correct
14 Correct 319 ms 17568 KB Output is correct
15 Correct 362 ms 17652 KB Output is correct
16 Correct 241 ms 16572 KB Output is correct
17 Correct 268 ms 16472 KB Output is correct
18 Correct 109 ms 14688 KB Output is correct
19 Correct 325 ms 17628 KB Output is correct
20 Correct 328 ms 17536 KB Output is correct
21 Correct 325 ms 17712 KB Output is correct
22 Correct 225 ms 16384 KB Output is correct
23 Correct 222 ms 16480 KB Output is correct
24 Correct 85 ms 14168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 7 ms 5112 KB Output is correct
5 Correct 7 ms 5112 KB Output is correct
6 Correct 7 ms 5112 KB Output is correct
7 Correct 13 ms 5624 KB Output is correct
8 Correct 13 ms 5496 KB Output is correct
9 Correct 13 ms 5496 KB Output is correct
10 Correct 12 ms 5624 KB Output is correct
11 Correct 12 ms 5496 KB Output is correct
12 Correct 9 ms 5368 KB Output is correct
13 Correct 13 ms 5496 KB Output is correct
14 Correct 12 ms 5496 KB Output is correct
15 Correct 12 ms 5496 KB Output is correct
16 Correct 11 ms 5624 KB Output is correct
17 Correct 11 ms 5500 KB Output is correct
18 Correct 8 ms 5496 KB Output is correct
19 Correct 332 ms 17628 KB Output is correct
20 Correct 330 ms 17580 KB Output is correct
21 Correct 314 ms 17632 KB Output is correct
22 Correct 234 ms 16480 KB Output is correct
23 Correct 231 ms 16624 KB Output is correct
24 Correct 115 ms 14680 KB Output is correct
25 Correct 298 ms 17548 KB Output is correct
26 Correct 303 ms 17500 KB Output is correct
27 Correct 275 ms 17140 KB Output is correct
28 Correct 221 ms 16348 KB Output is correct
29 Correct 220 ms 16428 KB Output is correct
30 Correct 84 ms 14428 KB Output is correct
31 Correct 317 ms 17596 KB Output is correct
32 Correct 319 ms 17568 KB Output is correct
33 Correct 362 ms 17652 KB Output is correct
34 Correct 241 ms 16572 KB Output is correct
35 Correct 268 ms 16472 KB Output is correct
36 Correct 109 ms 14688 KB Output is correct
37 Correct 325 ms 17628 KB Output is correct
38 Correct 328 ms 17536 KB Output is correct
39 Correct 325 ms 17712 KB Output is correct
40 Correct 225 ms 16384 KB Output is correct
41 Correct 222 ms 16480 KB Output is correct
42 Correct 85 ms 14168 KB Output is correct
43 Correct 375 ms 20572 KB Output is correct
44 Correct 383 ms 20700 KB Output is correct
45 Correct 378 ms 20464 KB Output is correct
46 Correct 311 ms 20216 KB Output is correct
47 Correct 308 ms 20056 KB Output is correct
48 Correct 112 ms 14300 KB Output is correct
49 Correct 395 ms 20628 KB Output is correct
50 Correct 394 ms 20536 KB Output is correct
51 Correct 355 ms 20656 KB Output is correct
52 Correct 281 ms 19928 KB Output is correct
53 Correct 250 ms 19932 KB Output is correct