Submission #118856

# Submission time Handle Problem Language Result Execution time Memory
118856 2019-06-19T23:55:15 Z tmwilliamlin168 Examination (JOI19_examination) C++14
100 / 100
528 ms 26868 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN=1e5;
int n, q, s[mxN], t[mxN], x, a[mxN], b[mxN], c[mxN], ans[mxN];
vector<int> vs, vt[mxN+1], ft[mxN+1];
array<int, 2> d[mxN], e[mxN];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> q;
	for(int i=0; i<n; ++i) {
		cin >> s[i] >> t[i], s[i]=-s[i], t[i]=-t[i];
		vs.push_back(s[i]);
		d[i]={s[i]+t[i], i};
	}
	sort(vs.begin(), vs.end());
	vs.resize(x=unique(vs.begin(), vs.end())-vs.begin());
	for(int i=0; i<n; ++i) {
		s[i]=lower_bound(vs.begin(), vs.end(), s[i])-vs.begin();
		for(int j=s[i]+1; j<=x; j+=j&-j)
			vt[j].push_back(t[i]);
	}
	for(int i=1; i<=x; ++i) {
		sort(vt[i].begin(), vt[i].end());
		vt[i].resize(unique(vt[i].begin(), vt[i].end())-vt[i].begin());
		ft[i].resize(vt[i].size()+1);
	}
	sort(d, d+n);
	for(int i=0; i<q; ++i) {
		cin >> a[i] >> b[i] >> c[i], a[i]=-a[i], b[i]=-b[i], c[i]=-c[i];
		e[i]={c[i], i};
	}
	sort(e, e+q);
	for(int i1=0, i2=0; i1<q; ++i1) {
		while(i2<n&&d[i2][0]<=e[i1][0]) {
			for(int i=s[d[i2][1]]+1; i<=x; i+=i&-i)
				for(int j=lower_bound(vt[i].begin(), vt[i].end(), t[d[i2][1]])-vt[i].begin()+1; j<=vt[i].size(); j+=j&-j)
					ft[i][j]++;
			++i2;
		}
		for(int i=upper_bound(vs.begin(), vs.end(), a[e[i1][1]])-vs.begin(); i; i-=i&-i)
			for(int j=upper_bound(vt[i].begin(), vt[i].end(), b[e[i1][1]])-vt[i].begin(); j; j-=j&-j)
				ans[e[i1][1]]+=ft[i][j];
	}
	for(int i=0; i<q; ++i)
		cout << ans[i] << "\n";
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:40:86: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=lower_bound(vt[i].begin(), vt[i].end(), t[d[i2][1]])-vt[i].begin()+1; j<=vt[i].size(); j+=j&-j)
                                                                                     ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 5 ms 5092 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 6 ms 4992 KB Output is correct
6 Correct 6 ms 5092 KB Output is correct
7 Correct 12 ms 5628 KB Output is correct
8 Correct 14 ms 5604 KB Output is correct
9 Correct 14 ms 5632 KB Output is correct
10 Correct 11 ms 5632 KB Output is correct
11 Correct 10 ms 5376 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
13 Correct 12 ms 5632 KB Output is correct
14 Correct 12 ms 5632 KB Output is correct
15 Correct 13 ms 5632 KB Output is correct
16 Correct 8 ms 5376 KB Output is correct
17 Correct 10 ms 5504 KB Output is correct
18 Correct 7 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 409 ms 22080 KB Output is correct
2 Correct 414 ms 22132 KB Output is correct
3 Correct 413 ms 22116 KB Output is correct
4 Correct 209 ms 19060 KB Output is correct
5 Correct 136 ms 13644 KB Output is correct
6 Correct 81 ms 12280 KB Output is correct
7 Correct 387 ms 22052 KB Output is correct
8 Correct 392 ms 22120 KB Output is correct
9 Correct 337 ms 21876 KB Output is correct
10 Correct 90 ms 12144 KB Output is correct
11 Correct 191 ms 18744 KB Output is correct
12 Correct 56 ms 11112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 409 ms 22080 KB Output is correct
2 Correct 414 ms 22132 KB Output is correct
3 Correct 413 ms 22116 KB Output is correct
4 Correct 209 ms 19060 KB Output is correct
5 Correct 136 ms 13644 KB Output is correct
6 Correct 81 ms 12280 KB Output is correct
7 Correct 387 ms 22052 KB Output is correct
8 Correct 392 ms 22120 KB Output is correct
9 Correct 337 ms 21876 KB Output is correct
10 Correct 90 ms 12144 KB Output is correct
11 Correct 191 ms 18744 KB Output is correct
12 Correct 56 ms 11112 KB Output is correct
13 Correct 429 ms 22384 KB Output is correct
14 Correct 424 ms 22516 KB Output is correct
15 Correct 417 ms 22072 KB Output is correct
16 Correct 258 ms 19416 KB Output is correct
17 Correct 150 ms 14068 KB Output is correct
18 Correct 91 ms 12432 KB Output is correct
19 Correct 432 ms 22516 KB Output is correct
20 Correct 442 ms 22516 KB Output is correct
21 Correct 416 ms 22516 KB Output is correct
22 Correct 90 ms 12148 KB Output is correct
23 Correct 218 ms 18676 KB Output is correct
24 Correct 56 ms 11124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5120 KB Output is correct
2 Correct 5 ms 5092 KB Output is correct
3 Correct 6 ms 5120 KB Output is correct
4 Correct 6 ms 5120 KB Output is correct
5 Correct 6 ms 4992 KB Output is correct
6 Correct 6 ms 5092 KB Output is correct
7 Correct 12 ms 5628 KB Output is correct
8 Correct 14 ms 5604 KB Output is correct
9 Correct 14 ms 5632 KB Output is correct
10 Correct 11 ms 5632 KB Output is correct
11 Correct 10 ms 5376 KB Output is correct
12 Correct 8 ms 5248 KB Output is correct
13 Correct 12 ms 5632 KB Output is correct
14 Correct 12 ms 5632 KB Output is correct
15 Correct 13 ms 5632 KB Output is correct
16 Correct 8 ms 5376 KB Output is correct
17 Correct 10 ms 5504 KB Output is correct
18 Correct 7 ms 5248 KB Output is correct
19 Correct 409 ms 22080 KB Output is correct
20 Correct 414 ms 22132 KB Output is correct
21 Correct 413 ms 22116 KB Output is correct
22 Correct 209 ms 19060 KB Output is correct
23 Correct 136 ms 13644 KB Output is correct
24 Correct 81 ms 12280 KB Output is correct
25 Correct 387 ms 22052 KB Output is correct
26 Correct 392 ms 22120 KB Output is correct
27 Correct 337 ms 21876 KB Output is correct
28 Correct 90 ms 12144 KB Output is correct
29 Correct 191 ms 18744 KB Output is correct
30 Correct 56 ms 11112 KB Output is correct
31 Correct 429 ms 22384 KB Output is correct
32 Correct 424 ms 22516 KB Output is correct
33 Correct 417 ms 22072 KB Output is correct
34 Correct 258 ms 19416 KB Output is correct
35 Correct 150 ms 14068 KB Output is correct
36 Correct 91 ms 12432 KB Output is correct
37 Correct 432 ms 22516 KB Output is correct
38 Correct 442 ms 22516 KB Output is correct
39 Correct 416 ms 22516 KB Output is correct
40 Correct 90 ms 12148 KB Output is correct
41 Correct 218 ms 18676 KB Output is correct
42 Correct 56 ms 11124 KB Output is correct
43 Correct 522 ms 26868 KB Output is correct
44 Correct 528 ms 26740 KB Output is correct
45 Correct 477 ms 26584 KB Output is correct
46 Correct 305 ms 22516 KB Output is correct
47 Correct 163 ms 15348 KB Output is correct
48 Correct 96 ms 12276 KB Output is correct
49 Correct 470 ms 26484 KB Output is correct
50 Correct 504 ms 26336 KB Output is correct
51 Correct 419 ms 26356 KB Output is correct
52 Correct 108 ms 13940 KB Output is correct
53 Correct 202 ms 21488 KB Output is correct