답안 #103352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
103352 2019-03-29T23:17:24 Z tincamatei Examination (JOI19_examination) C++14
2 / 100
3000 ms 222892 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 100000;
const int MAX_Q = 100000;
const int MAX_AIB = MAX_N + MAX_Q;
const int INF = 1000000001;

struct Student {
	int t, s;
} v[MAX_N];

struct Query {
	int a, b, c;
	int *rez;
} query[MAX_Q];

int rez[MAX_Q];

bool cmp1(Student a, Student b) {
	return a.t + a.s > b.t + b.s;
}

bool cmp2(Query a, Query b) {
	return a.c > b.c;
}

unordered_map<int, unordered_map<int, int> > aib;

static inline int lsb(int x) {
	return x & (-x);
}

void updateAib(int i, int j) {
	while(i <= INF) {
		int jc = j;
		while(jc <= INF) {
			aib[i][jc]++;
			jc += lsb(jc);
		}
		i += lsb(i);
	}
}

int queryAib(int i, int j) {
	int rez = 0;
	while(i > 0) {
		int jc = j;
		while(jc > 0) {
			rez += aib[i][jc];
			jc -= lsb(jc);
		}
		i -= lsb(i);
	}
	return rez;
}

void updatePoint(int a, int b) {
	updateAib(INF - a, INF - b);
}

int queryRectangle(int a, int b) {
	return queryAib(INF - a, INF - b);
}

int main() {
#ifdef HOME
	FILE *fin = fopen("input.in", "r");
	FILE *fout = fopen("output.out", "w");
#else
	FILE *fin = stdin;
	FILE *fout = stdout;
#endif

	int n, q;
	fscanf(fin, "%d%d", &n, &q);
	for(int i = 0; i < n; ++i)
		fscanf(fin, "%d%d", &v[i].t, &v[i].s);
	for(int i = 0; i < q; ++i) {
		fscanf(fin, "%d%d%d", &query[i].a, &query[i].b, &query[i].c);
		query[i].rez = &rez[i];
	}

	sort(v, v + n, cmp1);
	sort(query, query + q, cmp2);
	
	int lastup = 0;
	for(int i = 0; i < q; ++i) {
		while(lastup < n && v[lastup].t + v[lastup].s >= query[i].c) {
			updatePoint(v[lastup].t, v[lastup].s);
			++lastup;
		}

		*query[i].rez = queryRectangle(query[i].a, query[i].b);
	}
	
	for(int i = 0; i < q; ++i)
		fprintf(fout, "%d\n", rez[i]);

	fclose(fin);
	fclose(fout);
	return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:77:8: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fscanf(fin, "%d%d", &n, &q);
  ~~~~~~^~~~~~~~~~~~~~~~~~~~~
examination.cpp:79:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(fin, "%d%d", &v[i].t, &v[i].s);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:81:9: warning: ignoring return value of 'int fscanf(FILE*, const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   fscanf(fin, "%d%d%d", &query[i].a, &query[i].b, &query[i].c);
   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 511 ms 60340 KB Output is correct
8 Correct 481 ms 60088 KB Output is correct
9 Correct 488 ms 60344 KB Output is correct
10 Correct 186 ms 34312 KB Output is correct
11 Correct 378 ms 27656 KB Output is correct
12 Correct 39 ms 512 KB Output is correct
13 Correct 488 ms 60088 KB Output is correct
14 Correct 496 ms 60196 KB Output is correct
15 Correct 498 ms 60348 KB Output is correct
16 Correct 251 ms 19488 KB Output is correct
17 Correct 126 ms 23816 KB Output is correct
18 Correct 31 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3047 ms 222892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3047 ms 222892 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 511 ms 60340 KB Output is correct
8 Correct 481 ms 60088 KB Output is correct
9 Correct 488 ms 60344 KB Output is correct
10 Correct 186 ms 34312 KB Output is correct
11 Correct 378 ms 27656 KB Output is correct
12 Correct 39 ms 512 KB Output is correct
13 Correct 488 ms 60088 KB Output is correct
14 Correct 496 ms 60196 KB Output is correct
15 Correct 498 ms 60348 KB Output is correct
16 Correct 251 ms 19488 KB Output is correct
17 Correct 126 ms 23816 KB Output is correct
18 Correct 31 ms 512 KB Output is correct
19 Execution timed out 3047 ms 222892 KB Time limit exceeded
20 Halted 0 ms 0 KB -