Submission #127544

#TimeUsernameProblemLanguageResultExecution timeMemory
127544fefeExamination (JOI19_examination)C++17
100 / 100
407 ms18924 KiB
#include<bits/stdc++.h>
#define MAX_N 100005
#define MAX_M 55
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(V) (V).begin(),(V).end()
#define reset(V) (V).clear();(V).resize(0);
#define sq(x) ((x)*(x))
#define abs(x) ((x)>0?(x):(-(x)))
#define fi first
#define se second
#define LL_inf (1LL<<60)
#define full_inf 0x7fffffff
#define half_inf 0x3fffffff
#define inf 0x3fffffff
#define MOD 1000000007
#define cpx_mod(x) (((LD)(((LL)x.real())%MOD)),((LD)(((LL)x.imag())%MOD)))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pil;
typedef pair<LL,string> pls;
typedef complex<LD> Complex;
typedef long double LD;
struct node{
	int x,y,ye,i;
};
int n,m,ans[MAX_N];
int t[4*MAX_N];
vector<node> A,B;
vector<int> X,Y,Z;
void update(int i){
	int e=max({X.size(),Y.size(),Z.size()});
	for(;i<=e;i+=(i&-i))	t[i]++;
	return;
}
int read(int i){
	int sum=0;
	for(;i>0;i-=(i&-i))	sum+=t[i];
	return sum;
}
int main(){
	int i,x,y,z;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d %d",&x,&y);
		A.pb({x,y,-1,-1});X.eb(x);Y.eb(y);
		B.pb({x+y,y,-1,-1});Z.eb(x+y);
	}
	for(i=0;i<m;i++){
		scanf("%d %d %d",&x,&y,&z);
		if(x+y>z){
			A.pb({x,y,-1,i});X.eb(x);Y.eb(y);
		}else{
			A.pb({x,z-x+1,-1,i});X.eb(x);Y.eb(z-x+1);
			B.pb({z,z-x,y,i});Z.eb(z);Y.eb(y);Y.eb(z-x);
		}
	}
	
	sort(all(X));X.erase(unique(all(X)),X.end());
	sort(all(Y));Y.erase(unique(all(Y)),Y.end());
	sort(all(Z));Z.erase(unique(all(Z)),Z.end());
	
	for(node &p:A){
		p.x=X.size()-(lower_bound(all(X),p.x)-X.begin());
		p.y=Y.size()-(lower_bound(all(Y),p.y)-Y.begin());
	}
	
	for(node &p:B){
		p.x=Z.size()-(lower_bound(all(Z),p.x)-Z.begin());
		p.y=Y.size()-(lower_bound(all(Y),p.y)-Y.begin());
		p.ye=Y.size()-(lower_bound(all(Y),p.ye)-Y.begin());
	}
	
	sort(all(A),[&](const node x,const node y){return (x.x==y.x)?(x.i<y.i):(x.x<y.x);});
	sort(all(B),[&](const node x,const node y){return (x.x==y.x)?(x.i<y.i):(x.x<y.x);});
	
	
	for(node &p:A){
		if(p.i==-1)	update(p.y);
		else	ans[p.i]+=read(p.y);
	}
	for(i=max({X.size(),Y.size(),Z.size()});i>=0;i--)	t[i]=0;
	for(node &p:B){
		if(p.i==-1)	update(p.y);
		else	ans[p.i]+=read(p.ye)-read(p.y-1);
	}
	for(i=0;i<m;i++)	printf("%d\n",ans[i]);
	return 0;
}

Compilation message (stderr)

examination.cpp: In function 'int main()':
examination.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
examination.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&x,&y);
   ~~~~~^~~~~~~~~~~~~~~
examination.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&x,&y,&z);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...