Submission #377153

# Submission time Handle Problem Language Result Execution time Memory
377153 2021-03-13T04:50:09 Z eulerdesoja Examination (JOI19_examination) C++14
0 / 100
3000 ms 12328 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;
int n,q,a[mxn],b[mxn],ans[mxn],arr[mxn];
map<int,int>mp;
int bit[2][5*mxn];

struct t{
	int x,y,z,id;
};
vector<t>aux;

void upd(int k,int pos,int val){
	for(;pos<mxn;pos+=pos&-pos)bit[k][pos]+=val;
}

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++){
		cin>>a[i]>>b[i];
		mp[a[i]];
		mp[b[i]];
	}
	for(int i=0;i<q;i++){
		int x,y,z;cin>>x>>y>>z;
		aux.pb({x,y,z,i});
		mp[x];mp[y];
	}

	int T=0;
	for(auto it=mp.begin();it!=mp.end();it++){
		T++;
		it->second=T;
	}
	for(int i=0;i<n;i++)arr[i]=i;
	sort(arr,arr+n,[](int x,int y){return a[x]+b[x]<a[y]+b[y];});
	
	sort(aux.begin(),aux.end(),[](t a,t b){return max(a.x+a.y,a.z)<max(b.x+b.y,b.z);});

	for(int tmp=0;tmp<n;tmp++){
		int i=arr[tmp];
		upd(0,mp[a[i]],1);
		upd(1,mp[b[i]],1);

	}
	for(int i=0;i<n;i++)cout<<a[arr[i]]<<" "<<b[arr[i]]<<"\n";
	cout<<"\n";
	for(int i=0;i<q;i++)cout<<aux[i].x<<" "<<aux[i].y<<" "<<aux[i].z<<"\n";
	int i=0;
	for(int j=0;j<q;j++){
		while(a[arr[i]]+b[arr[i]]<max(aux[j].x+aux[j].y,aux[j].z)){
			upd(0,mp[a[arr[i]]],-1);
			upd(1,mp[b[arr[i]]],-1);
			i++;
		}
		int sub=0;
		sub+=query(0,mp[aux[j].x]-1);
		sub+=query(1,mp[aux[j].y]-1);
		ans[aux[j].id]=n-i-sub;
	}
	for(int i=0;i<q;i++)cout<<ans[i]<<"\n";



	return 0;
}
/*
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100

10 10
41304 98327
91921 28251
85635 59191
30361 72671
28949 96958
99041 37826
10245 2726
19387 20282
60366 87723
95388 49726
52302 69501 66009
43754 45346 3158
25224 58881 18727
7298 24412 63782
24107 10583 61508
65025 29140 7278
36104 56758 2775
23126 67608 122051
56910 17272 62933
39675 15874 117117
*/
# Verdict Execution time Memory Grader output
1 Execution timed out 3066 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 542 ms 12328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 542 ms 12328 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3066 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -