Submission #378823

# Submission time Handle Problem Language Result Execution time Memory
378823 2021-03-17T05:18:54 Z eulerdesoja Examination (JOI19_examination) C++17
100 / 100
158 ms 12304 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;

#define ll long long
#define pb push_back
#define sz(x) int(x.size())

typedef pair<int,int>ii;
typedef vector<int> vi;

const int mxn=1e5+5;
struct t{
	int a,b,sum;
	bool operator <(const t& p ){return sum>p.sum;}
};
struct t1{
	int x,y,z,id;
	bool operator<(const t1& p){return z>p.z;}
};

vector<t>al;
vector<t1>op;
int n,q,bit[2][mxn],ans[mxn];
vector<ii> cmp[2];

void upd(int k,int pos){
	for(;pos<mxn;pos+=pos&-pos)bit[k][pos]++;
}
int query(int k,int pos){
	int sum=0;
	for(;pos>0;pos-=pos&-pos)sum+=bit[k][pos];
	return sum;
}
int32_t main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	//setIO("sort");

	cin>>n>>q;

	for(int i=0;i<n;i++){
		int a,b;cin>>a>>b;
		al.pb({a,b,a+b});
		cmp[0].pb({a,i});
		cmp[1].pb({b,i});
	}

	for(int i=0;i<2;i++)sort(cmp[i].begin(),cmp[i].end());

	for(int i=0;i<q;i++){
		int x,y,z;cin>>x>>y>>z;
		z=max(z,x+y);
		auto it=lower_bound(cmp[0].begin(),cmp[0].end(),ii(x,-1));
		x=(it-cmp[0].begin())+1;
		auto it1=lower_bound(cmp[1].begin(),cmp[1].end(),ii(y,-1));
		y=(it1-cmp[1].begin())+1;
		op.pb({x,y,z,i});
	}

	for(int i=0;i<n;i++){
		al[cmp[0][i].second].a=i+1;
		al[cmp[1][i].second].b=i+1;
	}

	sort(al.begin(),al.end());
	sort(op.begin(),op.end());

	//for(int i=0;i<n;i++)cout<<al[i].a<<" "<<al[i].b<<" "<<al[i].sum<<"\n";
	
	//for(int i=0;i<q;i++)cout<<op[i].x<<" "<<op[i].y<<" "<<op[i].z<<"\n";

	int i=0;
	for(int j=0;j<q;j++){
		while(i<n && al[i].sum>=op[j].z){
			upd(0,al[i].a);
			upd(1,al[i].b);
			i++;
		}
		int q1=query(0,op[j].x-1);
		int q2=query(1,op[j].y-1);
		ans[op[j].id]=i-q1-q2;
	}
	for(int i=0;i<q;i++)cout<<ans[i]<<"\n";


	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 5 ms 876 KB Output is correct
8 Correct 5 ms 876 KB Output is correct
9 Correct 4 ms 876 KB Output is correct
10 Correct 4 ms 748 KB Output is correct
11 Correct 4 ms 796 KB Output is correct
12 Correct 3 ms 748 KB Output is correct
13 Correct 5 ms 876 KB Output is correct
14 Correct 4 ms 768 KB Output is correct
15 Correct 4 ms 768 KB Output is correct
16 Correct 4 ms 748 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 10016 KB Output is correct
2 Correct 141 ms 10132 KB Output is correct
3 Correct 139 ms 10000 KB Output is correct
4 Correct 124 ms 9232 KB Output is correct
5 Correct 123 ms 9232 KB Output is correct
6 Correct 96 ms 8548 KB Output is correct
7 Correct 147 ms 9872 KB Output is correct
8 Correct 134 ms 10000 KB Output is correct
9 Correct 124 ms 9744 KB Output is correct
10 Correct 112 ms 9104 KB Output is correct
11 Correct 112 ms 8976 KB Output is correct
12 Correct 73 ms 8080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 10016 KB Output is correct
2 Correct 141 ms 10132 KB Output is correct
3 Correct 139 ms 10000 KB Output is correct
4 Correct 124 ms 9232 KB Output is correct
5 Correct 123 ms 9232 KB Output is correct
6 Correct 96 ms 8548 KB Output is correct
7 Correct 147 ms 9872 KB Output is correct
8 Correct 134 ms 10000 KB Output is correct
9 Correct 124 ms 9744 KB Output is correct
10 Correct 112 ms 9104 KB Output is correct
11 Correct 112 ms 8976 KB Output is correct
12 Correct 73 ms 8080 KB Output is correct
13 Correct 143 ms 10384 KB Output is correct
14 Correct 146 ms 10560 KB Output is correct
15 Correct 139 ms 10000 KB Output is correct
16 Correct 130 ms 9616 KB Output is correct
17 Correct 124 ms 9616 KB Output is correct
18 Correct 96 ms 8528 KB Output is correct
19 Correct 143 ms 10384 KB Output is correct
20 Correct 142 ms 10384 KB Output is correct
21 Correct 138 ms 10384 KB Output is correct
22 Correct 113 ms 8976 KB Output is correct
23 Correct 112 ms 8976 KB Output is correct
24 Correct 71 ms 8208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 5 ms 876 KB Output is correct
8 Correct 5 ms 876 KB Output is correct
9 Correct 4 ms 876 KB Output is correct
10 Correct 4 ms 748 KB Output is correct
11 Correct 4 ms 796 KB Output is correct
12 Correct 3 ms 748 KB Output is correct
13 Correct 5 ms 876 KB Output is correct
14 Correct 4 ms 768 KB Output is correct
15 Correct 4 ms 768 KB Output is correct
16 Correct 4 ms 748 KB Output is correct
17 Correct 4 ms 748 KB Output is correct
18 Correct 3 ms 768 KB Output is correct
19 Correct 141 ms 10016 KB Output is correct
20 Correct 141 ms 10132 KB Output is correct
21 Correct 139 ms 10000 KB Output is correct
22 Correct 124 ms 9232 KB Output is correct
23 Correct 123 ms 9232 KB Output is correct
24 Correct 96 ms 8548 KB Output is correct
25 Correct 147 ms 9872 KB Output is correct
26 Correct 134 ms 10000 KB Output is correct
27 Correct 124 ms 9744 KB Output is correct
28 Correct 112 ms 9104 KB Output is correct
29 Correct 112 ms 8976 KB Output is correct
30 Correct 73 ms 8080 KB Output is correct
31 Correct 143 ms 10384 KB Output is correct
32 Correct 146 ms 10560 KB Output is correct
33 Correct 139 ms 10000 KB Output is correct
34 Correct 130 ms 9616 KB Output is correct
35 Correct 124 ms 9616 KB Output is correct
36 Correct 96 ms 8528 KB Output is correct
37 Correct 143 ms 10384 KB Output is correct
38 Correct 142 ms 10384 KB Output is correct
39 Correct 138 ms 10384 KB Output is correct
40 Correct 113 ms 8976 KB Output is correct
41 Correct 112 ms 8976 KB Output is correct
42 Correct 71 ms 8208 KB Output is correct
43 Correct 156 ms 12304 KB Output is correct
44 Correct 152 ms 12304 KB Output is correct
45 Correct 158 ms 12304 KB Output is correct
46 Correct 131 ms 10816 KB Output is correct
47 Correct 131 ms 10768 KB Output is correct
48 Correct 96 ms 8336 KB Output is correct
49 Correct 150 ms 12176 KB Output is correct
50 Correct 151 ms 12176 KB Output is correct
51 Correct 141 ms 12176 KB Output is correct
52 Correct 121 ms 10512 KB Output is correct
53 Correct 117 ms 9872 KB Output is correct