Submission #313772

# Submission time Handle Problem Language Result Execution time Memory
313772 2020-10-17T04:16:15 Z limabeans Examination (JOI19_examination) C++17
100 / 100
2504 ms 157808 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//*find_by_order: iterator to kth elem (0-indexed)
//order_of_key: # of items < k (stictly less)


using ll = long long;


const int maxn = 1e5 + 10;

int n, q;
ordered_set<pair<int,int>> t[4*maxn];
vector<pair<int,int>> vx, vy;
vector<array<int, 4>> Q;

int cc = 0;

void upd(int v, int tl, int tr, int i, int sum) {
    t[v].insert({sum,cc++});
    if (tl==tr) {
	return;
    }
    int tm = (tl+tr)/2;
    if (i<=tm) {
	upd(2*v,tl,tm,i,sum);
    } else {
	upd(2*v+1,tm+1,tr,i,sum);
    }
}

int qry(int v, int tl, int tr, int l, int r, int sum) {
    if (l>tr || r<tl) {
	return 0;
    }
    if (l<=tl && tr<=r) {
	return (int)t[v].size() - t[v].order_of_key(make_pair(sum,-1)) ;
    } else {
	int tm = (tl+tr)/2;
	return qry(2*v,tl,tm,l,r,sum) + qry(2*v+1,tm+1,tr,l,r,sum);
    }
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n>>q;
    for (int i=0; i<n; i++) {
	int x,y;
	cin>>x>>y;
	vx.emplace_back(x,y);
	vy.emplace_back(x,y);
    }

    sort(vx.begin(),vx.end(),[&](pair<int,int> a, pair<int,int> b) {
	    return a<b;
	});

    sort(vy.begin(),vy.end(),[&](pair<int,int> a, pair<int,int> b) {
	    return make_pair(a.second,a.first) < make_pair(b.second,b.first);
	});


    Q.resize(q);
    for (int i=0; i<q; i++) {
	for (int j=0; j<3; j++) {
	    cin>>Q[i][j];
	}
	Q[i][3] = i;
    }

    sort(Q.begin(),Q.end(),[&](array<int,4> a, array<int,4> b) {
	    return a[1] > b[1];
	});



    vector<int> ans(q);
    
    for (auto qu: Q) {
	int x=qu[0];
	int y=qu[1];
	int z=qu[2];
	int i=qu[3];


	while (!vy.empty() && vy.back().second >= y) {
	    pair<int,int> cur = vy.back();
	    vy.pop_back();
	    int idx = lower_bound(vx.begin(),vx.end(),cur) - vx.begin() + 1;
	    upd(1,1,n,idx,cur.first+cur.second);
	}

	int idx = lower_bound(vx.begin(),vx.end(),make_pair(x,-1)) - vx.begin() + 1;
	int res = qry(1,1,n,idx,n,z);
	ans[i] = res;
    }


    for (int x: ans) {
	cout<<x<<"\n";
    }
    
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 37 ms 37880 KB Output is correct
2 Correct 37 ms 37888 KB Output is correct
3 Correct 37 ms 37880 KB Output is correct
4 Correct 37 ms 37880 KB Output is correct
5 Correct 37 ms 37888 KB Output is correct
6 Correct 37 ms 38008 KB Output is correct
7 Correct 55 ms 40440 KB Output is correct
8 Correct 53 ms 40440 KB Output is correct
9 Correct 54 ms 40444 KB Output is correct
10 Correct 52 ms 40448 KB Output is correct
11 Correct 52 ms 40568 KB Output is correct
12 Correct 50 ms 40440 KB Output is correct
13 Correct 54 ms 40440 KB Output is correct
14 Correct 53 ms 40412 KB Output is correct
15 Correct 54 ms 40440 KB Output is correct
16 Correct 50 ms 40444 KB Output is correct
17 Correct 52 ms 40440 KB Output is correct
18 Correct 55 ms 40444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2128 ms 154016 KB Output is correct
2 Correct 2137 ms 155408 KB Output is correct
3 Correct 2136 ms 155536 KB Output is correct
4 Correct 1097 ms 154608 KB Output is correct
5 Correct 1041 ms 154616 KB Output is correct
6 Correct 834 ms 153976 KB Output is correct
7 Correct 2032 ms 155420 KB Output is correct
8 Correct 2181 ms 155324 KB Output is correct
9 Correct 2003 ms 155124 KB Output is correct
10 Correct 731 ms 154516 KB Output is correct
11 Correct 976 ms 154324 KB Output is correct
12 Correct 1461 ms 155580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2128 ms 154016 KB Output is correct
2 Correct 2137 ms 155408 KB Output is correct
3 Correct 2136 ms 155536 KB Output is correct
4 Correct 1097 ms 154608 KB Output is correct
5 Correct 1041 ms 154616 KB Output is correct
6 Correct 834 ms 153976 KB Output is correct
7 Correct 2032 ms 155420 KB Output is correct
8 Correct 2181 ms 155324 KB Output is correct
9 Correct 2003 ms 155124 KB Output is correct
10 Correct 731 ms 154516 KB Output is correct
11 Correct 976 ms 154324 KB Output is correct
12 Correct 1461 ms 155580 KB Output is correct
13 Correct 2285 ms 156052 KB Output is correct
14 Correct 2186 ms 155900 KB Output is correct
15 Correct 2124 ms 155412 KB Output is correct
16 Correct 1140 ms 155152 KB Output is correct
17 Correct 1162 ms 154948 KB Output is correct
18 Correct 840 ms 153872 KB Output is correct
19 Correct 2258 ms 155704 KB Output is correct
20 Correct 2257 ms 155860 KB Output is correct
21 Correct 2444 ms 155768 KB Output is correct
22 Correct 737 ms 154512 KB Output is correct
23 Correct 992 ms 154512 KB Output is correct
24 Correct 1497 ms 155412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 37880 KB Output is correct
2 Correct 37 ms 37888 KB Output is correct
3 Correct 37 ms 37880 KB Output is correct
4 Correct 37 ms 37880 KB Output is correct
5 Correct 37 ms 37888 KB Output is correct
6 Correct 37 ms 38008 KB Output is correct
7 Correct 55 ms 40440 KB Output is correct
8 Correct 53 ms 40440 KB Output is correct
9 Correct 54 ms 40444 KB Output is correct
10 Correct 52 ms 40448 KB Output is correct
11 Correct 52 ms 40568 KB Output is correct
12 Correct 50 ms 40440 KB Output is correct
13 Correct 54 ms 40440 KB Output is correct
14 Correct 53 ms 40412 KB Output is correct
15 Correct 54 ms 40440 KB Output is correct
16 Correct 50 ms 40444 KB Output is correct
17 Correct 52 ms 40440 KB Output is correct
18 Correct 55 ms 40444 KB Output is correct
19 Correct 2128 ms 154016 KB Output is correct
20 Correct 2137 ms 155408 KB Output is correct
21 Correct 2136 ms 155536 KB Output is correct
22 Correct 1097 ms 154608 KB Output is correct
23 Correct 1041 ms 154616 KB Output is correct
24 Correct 834 ms 153976 KB Output is correct
25 Correct 2032 ms 155420 KB Output is correct
26 Correct 2181 ms 155324 KB Output is correct
27 Correct 2003 ms 155124 KB Output is correct
28 Correct 731 ms 154516 KB Output is correct
29 Correct 976 ms 154324 KB Output is correct
30 Correct 1461 ms 155580 KB Output is correct
31 Correct 2285 ms 156052 KB Output is correct
32 Correct 2186 ms 155900 KB Output is correct
33 Correct 2124 ms 155412 KB Output is correct
34 Correct 1140 ms 155152 KB Output is correct
35 Correct 1162 ms 154948 KB Output is correct
36 Correct 840 ms 153872 KB Output is correct
37 Correct 2258 ms 155704 KB Output is correct
38 Correct 2257 ms 155860 KB Output is correct
39 Correct 2444 ms 155768 KB Output is correct
40 Correct 737 ms 154512 KB Output is correct
41 Correct 992 ms 154512 KB Output is correct
42 Correct 1497 ms 155412 KB Output is correct
43 Correct 2295 ms 157696 KB Output is correct
44 Correct 2284 ms 157724 KB Output is correct
45 Correct 2198 ms 157640 KB Output is correct
46 Correct 1182 ms 156304 KB Output is correct
47 Correct 1214 ms 156164 KB Output is correct
48 Correct 895 ms 153872 KB Output is correct
49 Correct 2308 ms 157636 KB Output is correct
50 Correct 2504 ms 157808 KB Output is correct
51 Correct 2364 ms 157720 KB Output is correct
52 Correct 779 ms 156172 KB Output is correct
53 Correct 1018 ms 155268 KB Output is correct