Submission #208607

# Submission time Handle Problem Language Result Execution time Memory
208607 2020-03-11T19:30:37 Z erd1 Examination (JOI19_examination) C++14
100 / 100
682 ms 19220 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ost = tree<T, null_type, greater_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef int64_t lld;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define endl '\n'
#define jizz cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
template<typename Iter>
ostream& _out(ostream &s, Iter b, Iter e) {
	s<<"[";
	for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
	s<<"]";
	return s;
}
template<class T1,class T2>
ostream& operator<<(ostream& out, pair<T1,T2> p) {
	return out << '(' << p.first << ", " << p.second << ')';
}
template< class T, std::size_t N >
ostream& operator<<(ostream& out, array<T,N> c) {
	return _out(out, c.begin(), c.end());
}
template<class T1,class T2>
istream& operator>>(istream& in, pair<T1,T2>& p) {
	return in >> p.ff >> p.ss;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) {
	return _out(s,c.begin(),c.end());
}

typedef pair<array<int, 3>, pii> P;
vector<P> v;
vector<int> bit, ans, as, bs, cs;
int totalbits = 0;
void update(int i, int x){
	do bit[i] += x;
	while((i+=i&-i) < bit.size());
	totalbits += x;
}
int query(int i){
	int ans = 0;
	for(;i;i-=i&-i)
		ans += bit[i];
	return ans;
}
void CDQ(int l, int r){
	int mid = l+r>>1;
	if(l == r)return;
	CDQ(l, mid); CDQ(mid+1, r);
	//cout << (pii){l, r};// << endl;
	auto midP = v[mid];
	inplace_merge(v.begin()+l, v.begin()+mid+1, v.begin()+r+1, [](P a, P b){ return a.ff[1] == b.ff[1]?a<b:a.ff[1]<b.ff[1]; });
	//_out(cout, v.begin()+l, v.begin()+r+1);
	for(int i = l; i <= r; i++)
		if(v[i].ss.ss <= mid && !v[i].ss.ff)
			update(v[i].ff[2], 1);
		else if(v[i].ss.ss > mid && v[i].ss.ff)
			ans[v[i].ss.ff]+= query(v[i].ff[2]);
	//cout << bit << endl;
	for(int i = l; i <= r; i++)
		if(v[i].ss.ss <= mid && !v[i].ss.ff)update(v[i].ff[2], -1);
}
int main(){//jizz;
	int n, q;
	cin >> n >> q;
	for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		v.pb({{-a, -b, -a-b}, {0, 0}});
		as.pb(-a); bs.pb(-b); cs.pb(-a-b);
	}
	for(int i = 1; i <= q; i++){
		int a, b, c;
		cin >> a >> b >>c;
		v.pb({{-a, -b, -c}, {i, 0}});
		as.pb(-a); bs.pb(-b); cs.pb(-c);
	}
	sort(all(as)); sort(all(bs)); sort(all(cs)); sort(all(v));
	as.erase(unique(all(as)), as.end());
	bs.erase(unique(all(bs)), bs.end());
	cs.erase(unique(all(cs)), cs.end());
	for(int i = 0; i < n+q; i++){
		v[i].ff[0] = lower_bound(all(as), v[i].ff[0])-as.begin()+1;
		v[i].ff[1] = lower_bound(all(bs), v[i].ff[1])-bs.begin()+1;
		v[i].ff[2] = lower_bound(all(cs), v[i].ff[2])-cs.begin()+1;
		v[i].ss.ss = i;
	}
	//cout << v << endl;
	ans.resize(q+1); bit.resize(n+q+2);
	//cout << ans << endl;
	CDQ(0, n+q-1);
	for(int i = 1; i <= q; i++)
		cout << ans[i] << " ";
	cout << endl;
	
} 
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100

*/

Compilation message

examination.cpp: In function 'void update(int, int)':
examination.cpp:46:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while((i+=i&-i) < bit.size());
        ~~~~~~~~~~^~~~~~~~~~~~
examination.cpp: In function 'void CDQ(int, int)':
examination.cpp:56:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l+r>>1;
            ~^~
examination.cpp:60:7: warning: variable 'midP' set but not used [-Wunused-but-set-variable]
  auto midP = v[mid];
       ^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 21 ms 760 KB Output is correct
8 Correct 21 ms 760 KB Output is correct
9 Correct 22 ms 760 KB Output is correct
10 Correct 19 ms 760 KB Output is correct
11 Correct 18 ms 632 KB Output is correct
12 Correct 12 ms 760 KB Output is correct
13 Correct 20 ms 760 KB Output is correct
14 Correct 20 ms 764 KB Output is correct
15 Correct 20 ms 764 KB Output is correct
16 Correct 15 ms 760 KB Output is correct
17 Correct 16 ms 760 KB Output is correct
18 Correct 11 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 523 ms 14584 KB Output is correct
2 Correct 532 ms 17144 KB Output is correct
3 Correct 526 ms 17120 KB Output is correct
4 Correct 442 ms 16248 KB Output is correct
5 Correct 445 ms 16504 KB Output is correct
6 Correct 323 ms 15480 KB Output is correct
7 Correct 496 ms 16892 KB Output is correct
8 Correct 499 ms 17148 KB Output is correct
9 Correct 473 ms 16760 KB Output is correct
10 Correct 394 ms 16376 KB Output is correct
11 Correct 376 ms 16252 KB Output is correct
12 Correct 320 ms 15612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 523 ms 14584 KB Output is correct
2 Correct 532 ms 17144 KB Output is correct
3 Correct 526 ms 17120 KB Output is correct
4 Correct 442 ms 16248 KB Output is correct
5 Correct 445 ms 16504 KB Output is correct
6 Correct 323 ms 15480 KB Output is correct
7 Correct 496 ms 16892 KB Output is correct
8 Correct 499 ms 17148 KB Output is correct
9 Correct 473 ms 16760 KB Output is correct
10 Correct 394 ms 16376 KB Output is correct
11 Correct 376 ms 16252 KB Output is correct
12 Correct 320 ms 15612 KB Output is correct
13 Correct 606 ms 17508 KB Output is correct
14 Correct 587 ms 17404 KB Output is correct
15 Correct 518 ms 17152 KB Output is correct
16 Correct 456 ms 16784 KB Output is correct
17 Correct 446 ms 16632 KB Output is correct
18 Correct 326 ms 15608 KB Output is correct
19 Correct 572 ms 17532 KB Output is correct
20 Correct 566 ms 17404 KB Output is correct
21 Correct 566 ms 17404 KB Output is correct
22 Correct 376 ms 16376 KB Output is correct
23 Correct 373 ms 16248 KB Output is correct
24 Correct 313 ms 15536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 21 ms 760 KB Output is correct
8 Correct 21 ms 760 KB Output is correct
9 Correct 22 ms 760 KB Output is correct
10 Correct 19 ms 760 KB Output is correct
11 Correct 18 ms 632 KB Output is correct
12 Correct 12 ms 760 KB Output is correct
13 Correct 20 ms 760 KB Output is correct
14 Correct 20 ms 764 KB Output is correct
15 Correct 20 ms 764 KB Output is correct
16 Correct 15 ms 760 KB Output is correct
17 Correct 16 ms 760 KB Output is correct
18 Correct 11 ms 760 KB Output is correct
19 Correct 523 ms 14584 KB Output is correct
20 Correct 532 ms 17144 KB Output is correct
21 Correct 526 ms 17120 KB Output is correct
22 Correct 442 ms 16248 KB Output is correct
23 Correct 445 ms 16504 KB Output is correct
24 Correct 323 ms 15480 KB Output is correct
25 Correct 496 ms 16892 KB Output is correct
26 Correct 499 ms 17148 KB Output is correct
27 Correct 473 ms 16760 KB Output is correct
28 Correct 394 ms 16376 KB Output is correct
29 Correct 376 ms 16252 KB Output is correct
30 Correct 320 ms 15612 KB Output is correct
31 Correct 606 ms 17508 KB Output is correct
32 Correct 587 ms 17404 KB Output is correct
33 Correct 518 ms 17152 KB Output is correct
34 Correct 456 ms 16784 KB Output is correct
35 Correct 446 ms 16632 KB Output is correct
36 Correct 326 ms 15608 KB Output is correct
37 Correct 572 ms 17532 KB Output is correct
38 Correct 566 ms 17404 KB Output is correct
39 Correct 566 ms 17404 KB Output is correct
40 Correct 376 ms 16376 KB Output is correct
41 Correct 373 ms 16248 KB Output is correct
42 Correct 313 ms 15536 KB Output is correct
43 Correct 675 ms 19204 KB Output is correct
44 Correct 682 ms 19076 KB Output is correct
45 Correct 673 ms 19220 KB Output is correct
46 Correct 503 ms 17784 KB Output is correct
47 Correct 515 ms 18008 KB Output is correct
48 Correct 321 ms 15740 KB Output is correct
49 Correct 642 ms 19196 KB Output is correct
50 Correct 681 ms 19068 KB Output is correct
51 Correct 651 ms 19068 KB Output is correct
52 Correct 478 ms 17896 KB Output is correct
53 Correct 418 ms 17144 KB Output is correct