Submission #144672

# Submission time Handle Problem Language Result Execution time Memory
144672 2019-08-17T11:44:50 Z TadijaSebez Examination (JOI19_examination) C++11
100 / 100
748 ms 12604 KB
#include <bits/stdc++.h>
using namespace std;
const int N=200050;
int a[N],b[N],c[N],t[N],p[N];
int cdq1[N],cdq2[N],tmp[N],ans[N];
void CDQ2D(int id[], int l, int r)
{
	if(l>=r) return;
	int mid=l+r>>1;
	CDQ2D(id,l,mid);CDQ2D(id,mid+1,r);
	int i=l,j=mid+1,k=l;
	int sum=0;
	while(k<=r)
	{
		if(j>r || (i<=mid && c[id[i]]>=c[id[j]]))
		{
			if(t[id[i]]==0 && p[id[i]]==0) sum++;
			tmp[k++]=id[i++];
		}
		else
		{
			if(t[id[j]]==1 && p[id[j]]==1) ans[id[j]]+=sum;
            tmp[k++]=id[j++];
		}
	}
	for(int z=l;z<=r;z++) id[z]=tmp[z];
}
void CDQ1D(int id[], int l, int r)
{
    if(l>=r) return;
    int mid=l+r>>1;
    CDQ1D(id,l,mid);CDQ1D(id,mid+1,r);
    int i=l,j=mid+1,k=l;
    while(k<=r)
	{
		if(j>r || (i<=mid && b[id[i]]>=b[id[j]])) p[tmp[k++]=id[i++]]=0;
		else p[tmp[k++]=id[j++]]=1;
	}
	for(int z=l;z<=r;z++) cdq2[z]=id[z]=tmp[z];
	CDQ2D(cdq2,l,r);
}
int main()
{
	int n,q;
	scanf("%i %i",&n,&q);
	for(int i=1;i<=n;i++) scanf("%i %i",&a[i],&b[i]),c[i]=a[i]+b[i],t[i]=0;
	for(int i=n+1;i<=n+q;i++) scanf("%i %i %i",&a[i],&b[i],&c[i]),t[i]=1;
	for(int i=1;i<=n+q;i++) cdq1[i]=i;
	sort(cdq1+1,cdq1+1+q+n,[&](int i, int j){ return make_pair(a[i],-t[i])>make_pair(a[j],-t[j]);});
	CDQ1D(cdq1,1,n+q);
	for(int i=n+1;i<=n+q;i++) printf("%i\n",ans[i]);
	return 0;
}

Compilation message

examination.cpp: In function 'void CDQ2D(int*, int, int)':
examination.cpp:9:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=l+r>>1;
          ~^~
examination.cpp: In function 'void CDQ1D(int*, int, int)':
examination.cpp:31:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int mid=l+r>>1;
             ~^~
examination.cpp: In function 'int main()':
examination.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&q);
  ~~~~~^~~~~~~~~~~~~~~
examination.cpp:46:65: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%i %i",&a[i],&b[i]),c[i]=a[i]+b[i],t[i]=0;
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
examination.cpp:47:63: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=n+1;i<=n+q;i++) scanf("%i %i %i",&a[i],&b[i],&c[i]),t[i]=1;
                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 14 ms 760 KB Output is correct
8 Correct 14 ms 760 KB Output is correct
9 Correct 14 ms 760 KB Output is correct
10 Correct 13 ms 760 KB Output is correct
11 Correct 11 ms 760 KB Output is correct
12 Correct 9 ms 632 KB Output is correct
13 Correct 11 ms 888 KB Output is correct
14 Correct 11 ms 632 KB Output is correct
15 Correct 11 ms 760 KB Output is correct
16 Correct 9 ms 632 KB Output is correct
17 Correct 11 ms 632 KB Output is correct
18 Correct 8 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 560 ms 10080 KB Output is correct
2 Correct 575 ms 10024 KB Output is correct
3 Correct 551 ms 10120 KB Output is correct
4 Correct 488 ms 9376 KB Output is correct
5 Correct 411 ms 9336 KB Output is correct
6 Correct 364 ms 8568 KB Output is correct
7 Correct 483 ms 9976 KB Output is correct
8 Correct 511 ms 10144 KB Output is correct
9 Correct 473 ms 9952 KB Output is correct
10 Correct 355 ms 9076 KB Output is correct
11 Correct 413 ms 9180 KB Output is correct
12 Correct 240 ms 8064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 560 ms 10080 KB Output is correct
2 Correct 575 ms 10024 KB Output is correct
3 Correct 551 ms 10120 KB Output is correct
4 Correct 488 ms 9376 KB Output is correct
5 Correct 411 ms 9336 KB Output is correct
6 Correct 364 ms 8568 KB Output is correct
7 Correct 483 ms 9976 KB Output is correct
8 Correct 511 ms 10144 KB Output is correct
9 Correct 473 ms 9952 KB Output is correct
10 Correct 355 ms 9076 KB Output is correct
11 Correct 413 ms 9180 KB Output is correct
12 Correct 240 ms 8064 KB Output is correct
13 Correct 724 ms 10492 KB Output is correct
14 Correct 695 ms 10484 KB Output is correct
15 Correct 547 ms 10128 KB Output is correct
16 Correct 636 ms 9744 KB Output is correct
17 Correct 545 ms 9724 KB Output is correct
18 Correct 408 ms 8716 KB Output is correct
19 Correct 734 ms 10528 KB Output is correct
20 Correct 719 ms 10620 KB Output is correct
21 Correct 671 ms 10560 KB Output is correct
22 Correct 354 ms 9208 KB Output is correct
23 Correct 404 ms 9208 KB Output is correct
24 Correct 243 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 14 ms 760 KB Output is correct
8 Correct 14 ms 760 KB Output is correct
9 Correct 14 ms 760 KB Output is correct
10 Correct 13 ms 760 KB Output is correct
11 Correct 11 ms 760 KB Output is correct
12 Correct 9 ms 632 KB Output is correct
13 Correct 11 ms 888 KB Output is correct
14 Correct 11 ms 632 KB Output is correct
15 Correct 11 ms 760 KB Output is correct
16 Correct 9 ms 632 KB Output is correct
17 Correct 11 ms 632 KB Output is correct
18 Correct 8 ms 632 KB Output is correct
19 Correct 560 ms 10080 KB Output is correct
20 Correct 575 ms 10024 KB Output is correct
21 Correct 551 ms 10120 KB Output is correct
22 Correct 488 ms 9376 KB Output is correct
23 Correct 411 ms 9336 KB Output is correct
24 Correct 364 ms 8568 KB Output is correct
25 Correct 483 ms 9976 KB Output is correct
26 Correct 511 ms 10144 KB Output is correct
27 Correct 473 ms 9952 KB Output is correct
28 Correct 355 ms 9076 KB Output is correct
29 Correct 413 ms 9180 KB Output is correct
30 Correct 240 ms 8064 KB Output is correct
31 Correct 724 ms 10492 KB Output is correct
32 Correct 695 ms 10484 KB Output is correct
33 Correct 547 ms 10128 KB Output is correct
34 Correct 636 ms 9744 KB Output is correct
35 Correct 545 ms 9724 KB Output is correct
36 Correct 408 ms 8716 KB Output is correct
37 Correct 734 ms 10528 KB Output is correct
38 Correct 719 ms 10620 KB Output is correct
39 Correct 671 ms 10560 KB Output is correct
40 Correct 354 ms 9208 KB Output is correct
41 Correct 404 ms 9208 KB Output is correct
42 Correct 243 ms 8184 KB Output is correct
43 Correct 748 ms 12484 KB Output is correct
44 Correct 742 ms 12604 KB Output is correct
45 Correct 722 ms 12408 KB Output is correct
46 Correct 652 ms 11160 KB Output is correct
47 Correct 543 ms 10872 KB Output is correct
48 Correct 428 ms 8544 KB Output is correct
49 Correct 647 ms 12456 KB Output is correct
50 Correct 673 ms 12476 KB Output is correct
51 Correct 639 ms 12224 KB Output is correct
52 Correct 467 ms 10744 KB Output is correct
53 Correct 416 ms 10036 KB Output is correct