답안 #102202

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102202 2019-03-23T13:30:29 Z Pajaraja Examination (JOI19_examination) C++17
100 / 100
1035 ms 28840 KB
#include <bits/stdc++.h>
#define MAXN 1000007
using namespace std;
int n,q,bit[2*MAXN],qx[MAXN],qy[MAXN],qxy[MAXN],x[MAXN],y[MAXN],a[MAXN],b[MAXN],c[MAXN],d[MAXN],sol[MAXN],ans[MAXN];
bool t[MAXN];
pair<int,int> r[2*MAXN];
pair<pair<int,int>,int> l[2*MAXN];
void upd(int x) {while(x<2*MAXN) {bit[x]++; x+=(x&-x);} }
int val(int x)
{
	int s=0;
	while(x)
	{
		s+=bit[x];
		x-=(x&-x);
	}
	return s;
}
map<int,int> m;
void calc1()
{
	for(int i=0;i<n;i++) r[i]=make_pair(a[i],1);
	for(int i=0;i<q;i++) r[n+i]=make_pair(b[i],-i);
	sort(r,r+n+q);
	int cnt=0;
	for(int i=0;i<n+q;i++)
	{
		if(r[i].second==1) cnt++;
		else sol[-r[i].second]=cnt;
	}
}
void calc2()
{
	fill(bit,bit+2*MAXN,0);
	m.clear();
	vector<int> zk;
	for(int i=0;i<n;i++) zk.push_back(b[i]);
	for(int i=0;i<q;i++) zk.push_back(d[i]);
	sort(zk.begin(),zk.end());
	for(int i=0;i<zk.size();i++) m[zk[i]]=i+1;
	for(int i=0;i<n;i++) l[i]=make_pair(make_pair(a[i],m[b[i]]),-1);
	for(int i=0;i<q;i++) l[n+i]=make_pair(make_pair(c[i]-1,m[d[i]]-1),i);
	sort(l,l+n+q);
	for(int i=0;i<n+q;i++)
	{
		if(l[i].second==-1) upd(l[i].first.second);
		else sol[l[i].second]=val(l[i].first.second);
	}
}
int main()
{
	scanf("%d%d",&n,&q);
	for(int i=0;i<n;i++) scanf("%d%d",&x[i],&y[i]);
	for(int i=0;i<q;i++) scanf("%d%d%d",&qx[i],&qy[i],&qxy[i]);
	for(int i=0;i<q;i++) t[i]=(qx[i]+qy[i]<qxy[i]);
	for(int i=0;i<n;i++) a[i]=x[i];
	for(int i=0;i<q;i++) b[i]=qx[i];
	calc1();
	for(int i=0;i<q;i++) ans[i]+=sol[i];
	for(int i=0;i<n;i++) a[i]=y[i];
	for(int i=0;i<q;i++) b[i]=qy[i];
	calc1();
	for(int i=0;i<q;i++) ans[i]+=sol[i];
	for(int i=0;i<n;i++) a[i]=x[i]+y[i];
	for(int i=0;i<q;i++) b[i]=qxy[i];
	calc1();
	for(int i=0;i<q;i++) if(t[i]) ans[i]+=sol[i];
	for(int i=0;i<n;i++) a[i]=x[i];
	for(int i=0;i<n;i++) b[i]=y[i];
	for(int i=0;i<q;i++) c[i]=qx[i];
	for(int i=0;i<q;i++) d[i]=qy[i];
	calc2();
	for(int i=0;i<q;i++) if(!t[i]) ans[i]-=sol[i];
	for(int i=0;i<n;i++) a[i]=x[i];
	for(int i=0;i<n;i++) b[i]=x[i]+y[i];
	for(int i=0;i<q;i++) c[i]=qx[i];
	for(int i=0;i<q;i++) d[i]=qxy[i];
	calc2();
	for(int i=0;i<q;i++) if(t[i]) ans[i]-=sol[i];
	for(int i=0;i<n;i++) a[i]=x[i]+y[i];
	for(int i=0;i<n;i++) b[i]=y[i];
	for(int i=0;i<q;i++) c[i]=qxy[i];
	for(int i=0;i<q;i++) d[i]=qy[i];
	calc2();
	for(int i=0;i<q;i++) if(t[i]) ans[i]-=sol[i];
	for(int i=0;i<q;i++) printf("%d\n",n-ans[i]);
}

Compilation message

examination.cpp: In function 'void calc2()':
examination.cpp:40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<zk.size();i++) m[zk[i]]=i+1;
              ~^~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&q);
  ~~~~~^~~~~~~~~~~~~~
examination.cpp:53:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) scanf("%d%d",&x[i],&y[i]);
                       ~~~~~^~~~~~~~~~~~~~~~~~~~
examination.cpp:54:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<q;i++) scanf("%d%d%d",&qx[i],&qy[i],&qxy[i]);
                       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 8320 KB Output is correct
2 Correct 12 ms 8320 KB Output is correct
3 Correct 12 ms 8292 KB Output is correct
4 Correct 11 ms 8192 KB Output is correct
5 Correct 11 ms 8320 KB Output is correct
6 Correct 11 ms 8320 KB Output is correct
7 Correct 25 ms 8968 KB Output is correct
8 Correct 25 ms 8992 KB Output is correct
9 Correct 30 ms 8992 KB Output is correct
10 Correct 20 ms 8960 KB Output is correct
11 Correct 28 ms 8952 KB Output is correct
12 Correct 18 ms 8576 KB Output is correct
13 Correct 22 ms 8960 KB Output is correct
14 Correct 24 ms 8980 KB Output is correct
15 Correct 23 ms 8988 KB Output is correct
16 Correct 25 ms 8860 KB Output is correct
17 Correct 21 ms 8932 KB Output is correct
18 Correct 19 ms 8576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 663 ms 23396 KB Output is correct
2 Correct 648 ms 23476 KB Output is correct
3 Correct 637 ms 23560 KB Output is correct
4 Correct 278 ms 21708 KB Output is correct
5 Correct 634 ms 23508 KB Output is correct
6 Correct 248 ms 19532 KB Output is correct
7 Correct 644 ms 23512 KB Output is correct
8 Correct 537 ms 22656 KB Output is correct
9 Correct 508 ms 22680 KB Output is correct
10 Correct 701 ms 23384 KB Output is correct
11 Correct 274 ms 21836 KB Output is correct
12 Correct 209 ms 19388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 663 ms 23396 KB Output is correct
2 Correct 648 ms 23476 KB Output is correct
3 Correct 637 ms 23560 KB Output is correct
4 Correct 278 ms 21708 KB Output is correct
5 Correct 634 ms 23508 KB Output is correct
6 Correct 248 ms 19532 KB Output is correct
7 Correct 644 ms 23512 KB Output is correct
8 Correct 537 ms 22656 KB Output is correct
9 Correct 508 ms 22680 KB Output is correct
10 Correct 701 ms 23384 KB Output is correct
11 Correct 274 ms 21836 KB Output is correct
12 Correct 209 ms 19388 KB Output is correct
13 Correct 812 ms 24716 KB Output is correct
14 Correct 699 ms 24172 KB Output is correct
15 Correct 645 ms 23600 KB Output is correct
16 Correct 370 ms 22732 KB Output is correct
17 Correct 741 ms 23468 KB Output is correct
18 Correct 245 ms 19616 KB Output is correct
19 Correct 840 ms 24500 KB Output is correct
20 Correct 780 ms 24264 KB Output is correct
21 Correct 753 ms 24824 KB Output is correct
22 Correct 641 ms 23252 KB Output is correct
23 Correct 308 ms 21784 KB Output is correct
24 Correct 185 ms 19532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 8320 KB Output is correct
2 Correct 12 ms 8320 KB Output is correct
3 Correct 12 ms 8292 KB Output is correct
4 Correct 11 ms 8192 KB Output is correct
5 Correct 11 ms 8320 KB Output is correct
6 Correct 11 ms 8320 KB Output is correct
7 Correct 25 ms 8968 KB Output is correct
8 Correct 25 ms 8992 KB Output is correct
9 Correct 30 ms 8992 KB Output is correct
10 Correct 20 ms 8960 KB Output is correct
11 Correct 28 ms 8952 KB Output is correct
12 Correct 18 ms 8576 KB Output is correct
13 Correct 22 ms 8960 KB Output is correct
14 Correct 24 ms 8980 KB Output is correct
15 Correct 23 ms 8988 KB Output is correct
16 Correct 25 ms 8860 KB Output is correct
17 Correct 21 ms 8932 KB Output is correct
18 Correct 19 ms 8576 KB Output is correct
19 Correct 663 ms 23396 KB Output is correct
20 Correct 648 ms 23476 KB Output is correct
21 Correct 637 ms 23560 KB Output is correct
22 Correct 278 ms 21708 KB Output is correct
23 Correct 634 ms 23508 KB Output is correct
24 Correct 248 ms 19532 KB Output is correct
25 Correct 644 ms 23512 KB Output is correct
26 Correct 537 ms 22656 KB Output is correct
27 Correct 508 ms 22680 KB Output is correct
28 Correct 701 ms 23384 KB Output is correct
29 Correct 274 ms 21836 KB Output is correct
30 Correct 209 ms 19388 KB Output is correct
31 Correct 812 ms 24716 KB Output is correct
32 Correct 699 ms 24172 KB Output is correct
33 Correct 645 ms 23600 KB Output is correct
34 Correct 370 ms 22732 KB Output is correct
35 Correct 741 ms 23468 KB Output is correct
36 Correct 245 ms 19616 KB Output is correct
37 Correct 840 ms 24500 KB Output is correct
38 Correct 780 ms 24264 KB Output is correct
39 Correct 753 ms 24824 KB Output is correct
40 Correct 641 ms 23252 KB Output is correct
41 Correct 308 ms 21784 KB Output is correct
42 Correct 185 ms 19532 KB Output is correct
43 Correct 1016 ms 28620 KB Output is correct
44 Correct 972 ms 28408 KB Output is correct
45 Correct 958 ms 28644 KB Output is correct
46 Correct 460 ms 28236 KB Output is correct
47 Correct 1022 ms 28772 KB Output is correct
48 Correct 222 ms 19548 KB Output is correct
49 Correct 1004 ms 28636 KB Output is correct
50 Correct 953 ms 28840 KB Output is correct
51 Correct 955 ms 28632 KB Output is correct
52 Correct 1035 ms 28540 KB Output is correct
53 Correct 300 ms 23612 KB Output is correct