Submission #123685

# Submission time Handle Problem Language Result Execution time Memory
123685 2019-07-02T03:59:17 Z 이온조(#3029) Examination (JOI19_examination) C++14
100 / 100
276 ms 12108 KB
#include <bits/stdc++.h>
using namespace std;

const int MXN = 200000;
struct query { int X, Y, Z, id; };
int S[100009], T[100009], ans[100009], F1[200009], F2[200009], F3[200009];

int getx(vector<int> &S, int x) { return lower_bound(S.begin(), S.end(), x) - S.begin() + 1; }

void upd(int F[], int x, int y) { for(int i=x; i<=MXN; i+=(i&-i)) F[i] += y; }
int get(int F[], int x) { int ret = 0; for(int i=x; i>=1; i-=(i&-i)) ret += F[i]; return ret; }

int main() {
	vector<int> XS, YS;
	vector<query> A, B;
	int N, Q; scanf("%d%d",&N,&Q);
	for(int i=1; i<=N; i++) {
		scanf("%d%d", &S[i], &T[i]);
		A.push_back({S[i], T[i], -1, -1});
		B.push_back({S[i], T[i], -1, -1});
		XS.push_back(S[i]);
		YS.push_back(T[i]);
	}
	
	for(int i=0; i<Q; i++) {
		int X, Y, Z; scanf("%d%d%d",&X,&Y,&Z);
		if(X+Y >= Z) A.push_back({X, Y, Z, i});
		else B.push_back({X, Y, Z, i});
		XS.push_back(X);
		YS.push_back(Y);
	}

	sort(XS.begin(), XS.end()); XS.resize(unique(XS.begin(), XS.end()) - XS.begin());
	sort(YS.begin(), YS.end()); YS.resize(unique(YS.begin(), YS.end()) - YS.begin());

	sort(A.begin(), A.end(), [&](query PP, query QQ) {
		if(PP.X == QQ.X) return PP.id < QQ.id;
		return PP.X > QQ.X;
	});
	for(auto& it: A) {
		if(it.id == -1) upd(F1, getx(YS, it.Y), +1);
		else ans[it.id] = get(F1, MXN) - get(F1, getx(YS, it.Y) - 1);
	}
	sort(B.begin(), B.end(), [&](query PP, query QQ) {
		int PZ, QZ;
		if(PP.id == -1) PZ = PP.X + PP.Y;
		else PZ = PP.Z;
		if(QQ.id == -1) QZ = QQ.X + QQ.Y;
		else QZ = QQ.Z;
		if(PZ == QZ) return PP.id < QQ.id;
		return PZ > QZ;
	});
	int cnt = 0;
	for(auto& it: B) {
		if(it.id == -1) {
			upd(F2, getx(XS, it.X), +1);
			upd(F3, getx(YS, it.Y), +1);
			++cnt;
		}
		else ans[it.id] = cnt - get(F2, getx(XS, it.X) - 1) - get(F3, getx(YS, it.Y) - 1);
	}
	for(int i=0; i<Q; i++) printf("%d\n", ans[i]);
	return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:16:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int N, Q; scanf("%d%d",&N,&Q);
            ~~~~~^~~~~~~~~~~~~~
examination.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &S[i], &T[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:26:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int X, Y, Z; scanf("%d%d%d",&X,&Y,&Z);
                ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 8 ms 888 KB Output is correct
8 Correct 8 ms 888 KB Output is correct
9 Correct 8 ms 888 KB Output is correct
10 Correct 7 ms 888 KB Output is correct
11 Correct 7 ms 760 KB Output is correct
12 Correct 6 ms 828 KB Output is correct
13 Correct 8 ms 760 KB Output is correct
14 Correct 8 ms 760 KB Output is correct
15 Correct 8 ms 888 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 7 ms 888 KB Output is correct
18 Correct 5 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 10784 KB Output is correct
2 Correct 225 ms 10804 KB Output is correct
3 Correct 219 ms 10804 KB Output is correct
4 Correct 151 ms 10164 KB Output is correct
5 Correct 171 ms 10444 KB Output is correct
6 Correct 116 ms 9776 KB Output is correct
7 Correct 222 ms 10672 KB Output is correct
8 Correct 210 ms 10672 KB Output is correct
9 Correct 209 ms 10620 KB Output is correct
10 Correct 157 ms 10420 KB Output is correct
11 Correct 143 ms 10036 KB Output is correct
12 Correct 102 ms 9388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 10784 KB Output is correct
2 Correct 225 ms 10804 KB Output is correct
3 Correct 219 ms 10804 KB Output is correct
4 Correct 151 ms 10164 KB Output is correct
5 Correct 171 ms 10444 KB Output is correct
6 Correct 116 ms 9776 KB Output is correct
7 Correct 222 ms 10672 KB Output is correct
8 Correct 210 ms 10672 KB Output is correct
9 Correct 209 ms 10620 KB Output is correct
10 Correct 157 ms 10420 KB Output is correct
11 Correct 143 ms 10036 KB Output is correct
12 Correct 102 ms 9388 KB Output is correct
13 Correct 238 ms 10836 KB Output is correct
14 Correct 229 ms 10804 KB Output is correct
15 Correct 224 ms 10708 KB Output is correct
16 Correct 168 ms 10104 KB Output is correct
17 Correct 182 ms 10404 KB Output is correct
18 Correct 120 ms 9952 KB Output is correct
19 Correct 241 ms 10784 KB Output is correct
20 Correct 237 ms 10732 KB Output is correct
21 Correct 239 ms 10672 KB Output is correct
22 Correct 161 ms 10288 KB Output is correct
23 Correct 143 ms 9908 KB Output is correct
24 Correct 98 ms 9524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 2 ms 508 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 8 ms 888 KB Output is correct
8 Correct 8 ms 888 KB Output is correct
9 Correct 8 ms 888 KB Output is correct
10 Correct 7 ms 888 KB Output is correct
11 Correct 7 ms 760 KB Output is correct
12 Correct 6 ms 828 KB Output is correct
13 Correct 8 ms 760 KB Output is correct
14 Correct 8 ms 760 KB Output is correct
15 Correct 8 ms 888 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 7 ms 888 KB Output is correct
18 Correct 5 ms 760 KB Output is correct
19 Correct 222 ms 10784 KB Output is correct
20 Correct 225 ms 10804 KB Output is correct
21 Correct 219 ms 10804 KB Output is correct
22 Correct 151 ms 10164 KB Output is correct
23 Correct 171 ms 10444 KB Output is correct
24 Correct 116 ms 9776 KB Output is correct
25 Correct 222 ms 10672 KB Output is correct
26 Correct 210 ms 10672 KB Output is correct
27 Correct 209 ms 10620 KB Output is correct
28 Correct 157 ms 10420 KB Output is correct
29 Correct 143 ms 10036 KB Output is correct
30 Correct 102 ms 9388 KB Output is correct
31 Correct 238 ms 10836 KB Output is correct
32 Correct 229 ms 10804 KB Output is correct
33 Correct 224 ms 10708 KB Output is correct
34 Correct 168 ms 10104 KB Output is correct
35 Correct 182 ms 10404 KB Output is correct
36 Correct 120 ms 9952 KB Output is correct
37 Correct 241 ms 10784 KB Output is correct
38 Correct 237 ms 10732 KB Output is correct
39 Correct 239 ms 10672 KB Output is correct
40 Correct 161 ms 10288 KB Output is correct
41 Correct 143 ms 9908 KB Output is correct
42 Correct 98 ms 9524 KB Output is correct
43 Correct 276 ms 11968 KB Output is correct
44 Correct 271 ms 11996 KB Output is correct
45 Correct 260 ms 12076 KB Output is correct
46 Correct 182 ms 10540 KB Output is correct
47 Correct 203 ms 11236 KB Output is correct
48 Correct 121 ms 9572 KB Output is correct
49 Correct 272 ms 12036 KB Output is correct
50 Correct 274 ms 12060 KB Output is correct
51 Correct 270 ms 12108 KB Output is correct
52 Correct 195 ms 11148 KB Output is correct
53 Correct 152 ms 10444 KB Output is correct