Submission #106732

# Submission time Handle Problem Language Result Execution time Memory
106732 2019-04-19T22:08:52 Z eriksuenderhauf Examination (JOI19_examination) C++11
100 / 100
2133 ms 342112 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const ll INF = 1e16 + 7;
const int MAXN = 4e5 + 5;
const double eps = 1e-9;
pii a[MAXN];

struct nodeX {
	vector<vi> seg;
	vi arr, sm;
} seg[MAXN];

void build(int l, int r, int k, int k2, vi &sm) {
	if (l == r) {
		seg[k2].seg[k] = {sm[l]};
		return;
	}
	int m = (l + r) / 2;
	build(l, m, k*2, k2, sm);
	build(m+1, r, k*2+1, k2, sm);
	int i = 0, j = 0;
	while (i < (int)seg[k2].seg[k*2].size() && j < (int)seg[k2].seg[k*2+1].size())
		if (seg[k2].seg[k*2][i] < seg[k2].seg[k*2+1][j])
			seg[k2].seg[k].pb(seg[k2].seg[k*2][i++]);
		else
			seg[k2].seg[k].pb(seg[k2].seg[k*2+1][j++]);
	while (i < (int)seg[k2].seg[k*2].size())
		seg[k2].seg[k].pb(seg[k2].seg[k*2][i++]);
	while (j < (int)seg[k2].seg[k*2+1].size())
		seg[k2].seg[k].pb(seg[k2].seg[k*2+1][j++]);
}

void build(int l, int r, int k) {
	if (l == r) {
		seg[k].arr = {a[l].se};
		seg[k].sm = {a[l].fi + a[l].se};
		seg[k].seg.resize(2);
		build(0, 0, 1, k, seg[k].sm);
		return;
	}
	seg[k].seg.resize(3*(r-l+1)+1);
	int m = (l + r) / 2;
	build(l, m, k * 2);
	build(m + 1, r, k * 2 + 1);
	int i = 0, j = 0;
	while (i < (int)seg[k*2].arr.size() && j < (int)seg[k*2+1].arr.size()) {
		if (seg[k*2].arr[i] < seg[k*2+1].arr[j]) {
			seg[k].arr.pb(seg[k*2].arr[i]);
			seg[k].sm.pb(seg[k*2].sm[i++]);
		} else {
			seg[k].arr.pb(seg[k*2+1].arr[j]);
			seg[k].sm.pb(seg[k*2+1].sm[j++]);
		}
	}
	while (i < (int)seg[k*2].arr.size()) {
		seg[k].arr.pb(seg[k*2].arr[i]);
		seg[k].sm.pb(seg[k*2].sm[i++]);
	}
	while (j < (int)seg[k*2+1].arr.size()) {
		seg[k].arr.pb(seg[k*2+1].arr[j]);
		seg[k].sm.pb(seg[k*2+1].sm[j++]);
	}
	build(0, r - l, 1, k, seg[k].sm);
}

int qry1(int l, int r, int k, int k2, int a, int b, int z) {
	if (r < a || b < l) return 0;
	if (a <= l && r <= b) {
		int lo = lower_bound(seg[k2].seg[k].begin(), seg[k2].seg[k].end(), z) - seg[k2].seg[k].begin();
		return (int)seg[k2].seg[k].size() - lo;
	}
	int m = (l + r) / 2;
	return qry1(l, m, k*2, k2, a, b, z) + qry1(m+1, r, k*2+1, k2, a, b, z);
}

int qry(int l, int r, int k, int a, int b, int y, int z) {
	if (r < a || b < l) return 0;
	if (a <= l && r <= b) {
		int lo = lower_bound(seg[k].arr.begin(), seg[k].arr.end(), y) - seg[k].arr.begin();
		return qry1(0, r - l, 1, k, lo, r - l, z);
	}
	int m = (l + r) / 2;
	return qry(l, m, k*2, a, b, y, z) + qry(m + 1, r, k*2+1, a, b, y, z);
}

int main() {
	int n, q;
	scanf("%d %d", &n, &q);
	for (int i = 0; i < n; i++)
		scanf("%d %d", &a[i].fi, &a[i].se);
	sort(a, a + n);
	build(0, n - 1, 1);
	for (int i = 0; i < q; i++) {
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		int lo = lower_bound(a, a + n, mp(x, -1)) - a;
		pri(qry(0, n - 1, 1, lo, n - 1, y, z));
	}
    return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:118: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:120:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a[i].fi, &a[i].se);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:125:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &x, &y, &z);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 28544 KB Output is correct
2 Correct 28 ms 28544 KB Output is correct
3 Correct 27 ms 28536 KB Output is correct
4 Correct 33 ms 28664 KB Output is correct
5 Correct 29 ms 28544 KB Output is correct
6 Correct 28 ms 28544 KB Output is correct
7 Correct 57 ms 34936 KB Output is correct
8 Correct 54 ms 35028 KB Output is correct
9 Correct 63 ms 35064 KB Output is correct
10 Correct 54 ms 34936 KB Output is correct
11 Correct 52 ms 34936 KB Output is correct
12 Correct 53 ms 34936 KB Output is correct
13 Correct 56 ms 35064 KB Output is correct
14 Correct 55 ms 34936 KB Output is correct
15 Correct 56 ms 35064 KB Output is correct
16 Correct 49 ms 34936 KB Output is correct
17 Correct 54 ms 35064 KB Output is correct
18 Correct 53 ms 34936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1878 ms 342112 KB Output is correct
2 Correct 2133 ms 341932 KB Output is correct
3 Correct 1990 ms 342016 KB Output is correct
4 Correct 1717 ms 341952 KB Output is correct
5 Correct 1216 ms 342020 KB Output is correct
6 Correct 1226 ms 341804 KB Output is correct
7 Correct 1781 ms 342060 KB Output is correct
8 Correct 1705 ms 341928 KB Output is correct
9 Correct 1510 ms 341908 KB Output is correct
10 Correct 1169 ms 341764 KB Output is correct
11 Correct 1280 ms 341676 KB Output is correct
12 Correct 969 ms 341468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1878 ms 342112 KB Output is correct
2 Correct 2133 ms 341932 KB Output is correct
3 Correct 1990 ms 342016 KB Output is correct
4 Correct 1717 ms 341952 KB Output is correct
5 Correct 1216 ms 342020 KB Output is correct
6 Correct 1226 ms 341804 KB Output is correct
7 Correct 1781 ms 342060 KB Output is correct
8 Correct 1705 ms 341928 KB Output is correct
9 Correct 1510 ms 341908 KB Output is correct
10 Correct 1169 ms 341764 KB Output is correct
11 Correct 1280 ms 341676 KB Output is correct
12 Correct 969 ms 341468 KB Output is correct
13 Correct 2007 ms 341804 KB Output is correct
14 Correct 1849 ms 341904 KB Output is correct
15 Correct 1971 ms 341956 KB Output is correct
16 Correct 1774 ms 341804 KB Output is correct
17 Correct 1403 ms 341804 KB Output is correct
18 Correct 1469 ms 341904 KB Output is correct
19 Correct 2001 ms 341812 KB Output is correct
20 Correct 1808 ms 341804 KB Output is correct
21 Correct 1911 ms 341876 KB Output is correct
22 Correct 1107 ms 341720 KB Output is correct
23 Correct 1224 ms 341544 KB Output is correct
24 Correct 1092 ms 341420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 28544 KB Output is correct
2 Correct 28 ms 28544 KB Output is correct
3 Correct 27 ms 28536 KB Output is correct
4 Correct 33 ms 28664 KB Output is correct
5 Correct 29 ms 28544 KB Output is correct
6 Correct 28 ms 28544 KB Output is correct
7 Correct 57 ms 34936 KB Output is correct
8 Correct 54 ms 35028 KB Output is correct
9 Correct 63 ms 35064 KB Output is correct
10 Correct 54 ms 34936 KB Output is correct
11 Correct 52 ms 34936 KB Output is correct
12 Correct 53 ms 34936 KB Output is correct
13 Correct 56 ms 35064 KB Output is correct
14 Correct 55 ms 34936 KB Output is correct
15 Correct 56 ms 35064 KB Output is correct
16 Correct 49 ms 34936 KB Output is correct
17 Correct 54 ms 35064 KB Output is correct
18 Correct 53 ms 34936 KB Output is correct
19 Correct 1878 ms 342112 KB Output is correct
20 Correct 2133 ms 341932 KB Output is correct
21 Correct 1990 ms 342016 KB Output is correct
22 Correct 1717 ms 341952 KB Output is correct
23 Correct 1216 ms 342020 KB Output is correct
24 Correct 1226 ms 341804 KB Output is correct
25 Correct 1781 ms 342060 KB Output is correct
26 Correct 1705 ms 341928 KB Output is correct
27 Correct 1510 ms 341908 KB Output is correct
28 Correct 1169 ms 341764 KB Output is correct
29 Correct 1280 ms 341676 KB Output is correct
30 Correct 969 ms 341468 KB Output is correct
31 Correct 2007 ms 341804 KB Output is correct
32 Correct 1849 ms 341904 KB Output is correct
33 Correct 1971 ms 341956 KB Output is correct
34 Correct 1774 ms 341804 KB Output is correct
35 Correct 1403 ms 341804 KB Output is correct
36 Correct 1469 ms 341904 KB Output is correct
37 Correct 2001 ms 341812 KB Output is correct
38 Correct 1808 ms 341804 KB Output is correct
39 Correct 1911 ms 341876 KB Output is correct
40 Correct 1107 ms 341720 KB Output is correct
41 Correct 1224 ms 341544 KB Output is correct
42 Correct 1092 ms 341420 KB Output is correct
43 Correct 1976 ms 341804 KB Output is correct
44 Correct 1893 ms 341676 KB Output is correct
45 Correct 1791 ms 341804 KB Output is correct
46 Correct 1828 ms 341732 KB Output is correct
47 Correct 1288 ms 341800 KB Output is correct
48 Correct 1210 ms 341396 KB Output is correct
49 Correct 1941 ms 341796 KB Output is correct
50 Correct 1833 ms 341908 KB Output is correct
51 Correct 1671 ms 341744 KB Output is correct
52 Correct 1227 ms 341612 KB Output is correct
53 Correct 1208 ms 341444 KB Output is correct