Submission #117476

# Submission time Handle Problem Language Result Execution time Memory
117476 2019-06-16T05:23:32 Z faustaadp Examination (JOI19_examination) C++17
100 / 100
2538 ms 270236 KB
#include<bits/stdc++.h>
typedef long long ll;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
int n,q,a[101010],b[101010],ta,tb,tc,i,jaw[101010],j,te,KA,KB;
vector<pair<pair<int,int>,int> > isi[101010];
pair<int,int> A[101010];
int ki[29404040];
int ka[29404040];
int ST[29404040];
int RU[804040];
int tam[3][101010];
vector<int> za,zb;
unordered_map<int,int> mea,meb;
void upd2(int aa,int bb,int cc,int ee)
{
	if(aa==bb)
		ST[ee]++;
	else
	{
		int ce=(aa+bb)/2;
		if(cc<=ce)
		{
			if(!ki[ee])ki[ee]=++te;
			upd2(aa,ce,cc,ki[ee]);
		}
		else
		{
			if(!ka[ee])ka[ee]=++te;
			upd2(ce+1,bb,cc,ka[ee]);
		}
		ST[ee]=ST[ki[ee]]+ST[ka[ee]];
	}
}
void upd(int aa,int bb,int cc,int dd,int ee)
{
	if(RU[ee]==0)
		RU[ee]=++te;
	upd2(1,KB,KB-dd,RU[ee]);
	if(aa<bb)
	{
		int ce=(aa+bb)/2;
		if(cc<=ce)
			upd(aa,ce,cc,dd,ee*2);
		else
			upd(ce+1,bb,cc,dd,ee*2+1);
	}
}
int que2(int aa,int bb,int cc,int dd,int ee)
{
	if(bb<cc||dd<aa||ee==0)
		return 0;
	else
	if(cc<=aa&&bb<=dd)
		return ST[ee];
	else
	{
		int ce=(aa+bb)/2;
		return que2(aa,ce,cc,dd,ki[ee])+que2(ce+1,bb,cc,dd,ka[ee]);
	}
}
int que(int aa,int bb,int cc,int dd,int ee,int ff)
{
//	cout<<aa<<" "<<bb<<" "<<cc<<" "<<dd<<" "<<ee<<" "<<ff<<"\n";
	if(bb<cc||dd<aa)
		return 0;
	else
	if(cc<=aa&&bb<=dd)
	{
		//cout<<aa<<" "<<bb<<"_\n";
		return que2(1,KB,1,KB-ff,RU[ee]);
	}
	else
	{
		int ce=(aa+bb)/2;
		return que(aa,ce,cc,dd,ee*2,ff)+que(ce+1,bb,cc,dd,ee*2+1,ff);
	}
}
int main()
{
//	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>q;
	for(i=1;i<=n;i++)
	{
		cin>>a[i]>>b[i];
		za.pb(a[i]);
		zb.pb(b[i]);
		A[i]=mp(a[i]+b[i],i);
	}
	sort(A+1,A+1+n);
	for(i=1;i<=q;i++)
	{
		cin>>tam[0][i]>>tam[1][i]>>tam[2][i];
		za.pb(tam[0][i]);
		zb.pb(tam[1][i]);
	}
	sort(za.begin(),za.end());
	sort(zb.begin(),zb.end());
	KA=1;
	KB=1;
	for(i=0;i<za.size();i++)
	{
		if(i==0||za[i]!=za[i-1])
		{
			mea[za[i]]=KA;
			KA++;
		}
	}
	for(i=0;i<zb.size();i++)
	{
		if(i==0||zb[i]!=zb[i-1])
		{
			meb[zb[i]]=KB;
			KB++;
		}
	}
	for(i=1;i<=q;i++)
	{
		ta=tam[0][i];
		tb=tam[1][i];
		tc=tam[2][i];
		int L=1,R=n,C,hz=0,ki=n+1;
		while(L<=R)
		{	
			C=(L+R)/2;
			if(A[C].fi>=tc)
			{
				ki=C;
				R=C-1;
			}
			else
				L=C+1;
		}
		isi[ki].pb(mp(mp(ta,tb),i));
		//cout<<ki<<"\n";
		// if((n<=3000&&q<=3000))
		// {		
		// 	for(j=1;j<=n;j++)
		// 		if(a[j]>=ta&&b[j]>=tb&&(a[j]+b[j])>=tc)
		//  			hz++;
		// 	cout<<hz<<"\n";
		// }
	}
	// if((n<=3000&&q<=3000))return 0;
	//K=za.size()+3;
	KA++;
	KB++;
	KA=max(KA,KB);
	KB=max(KA,KB);
	for(i=n;i>=1;i--)
	{
	//	cout<<i<<" "<<a[A[i].se]<<" "<<b[A[i].se]<<"\n";
	//	cout<<mea[a[A[i].se]]<<" "<<meb[b[A[i].se]]<<"\n";
		upd(1,KA,mea[a[A[i].se]],meb[b[A[i].se]],1);
		//continue;
		for(j=0;j<isi[i].size();j++)
		{
	//		cout<<mea[isi[i][j].fi.fi]<<" "<<meb[isi[i][j].fi.se]<<"\n";
		//	cout<<i<<"\n";
			jaw[isi[i][j].se]=que(1,KA,mea[isi[i][j].fi.fi],KA,1,meb[isi[i][j].fi.se]);
		}
	}
	for(i=1;i<=q;i++)
		cout<<jaw[i]<<"\n";
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:104:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<za.size();i++)
          ~^~~~~~~~~~
examination.cpp:112:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0;i<zb.size();i++)
          ~^~~~~~~~~~
examination.cpp:125:17: warning: unused variable 'hz' [-Wunused-variable]
   int L=1,R=n,C,hz=0,ki=n+1;
                 ^~
examination.cpp:159:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(j=0;j<isi[i].size();j++)
           ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2816 KB Output is correct
2 Correct 5 ms 2816 KB Output is correct
3 Correct 4 ms 2816 KB Output is correct
4 Correct 4 ms 2816 KB Output is correct
5 Correct 4 ms 2816 KB Output is correct
6 Correct 5 ms 2816 KB Output is correct
7 Correct 25 ms 7680 KB Output is correct
8 Correct 21 ms 7672 KB Output is correct
9 Correct 25 ms 7680 KB Output is correct
10 Correct 17 ms 4992 KB Output is correct
11 Correct 17 ms 4992 KB Output is correct
12 Correct 9 ms 3072 KB Output is correct
13 Correct 26 ms 7680 KB Output is correct
14 Correct 25 ms 7672 KB Output is correct
15 Correct 27 ms 7800 KB Output is correct
16 Correct 14 ms 4736 KB Output is correct
17 Correct 16 ms 4608 KB Output is correct
18 Correct 8 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2137 ms 209304 KB Output is correct
2 Correct 2258 ms 207852 KB Output is correct
3 Correct 2273 ms 208028 KB Output is correct
4 Correct 686 ms 54368 KB Output is correct
5 Correct 588 ms 52572 KB Output is correct
6 Correct 154 ms 11056 KB Output is correct
7 Correct 2199 ms 201248 KB Output is correct
8 Correct 2131 ms 201588 KB Output is correct
9 Correct 1587 ms 190084 KB Output is correct
10 Correct 429 ms 45536 KB Output is correct
11 Correct 544 ms 44892 KB Output is correct
12 Correct 121 ms 10716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2137 ms 209304 KB Output is correct
2 Correct 2258 ms 207852 KB Output is correct
3 Correct 2273 ms 208028 KB Output is correct
4 Correct 686 ms 54368 KB Output is correct
5 Correct 588 ms 52572 KB Output is correct
6 Correct 154 ms 11056 KB Output is correct
7 Correct 2199 ms 201248 KB Output is correct
8 Correct 2131 ms 201588 KB Output is correct
9 Correct 1587 ms 190084 KB Output is correct
10 Correct 429 ms 45536 KB Output is correct
11 Correct 544 ms 44892 KB Output is correct
12 Correct 121 ms 10716 KB Output is correct
13 Correct 1996 ms 208036 KB Output is correct
14 Correct 2194 ms 207796 KB Output is correct
15 Correct 2096 ms 207924 KB Output is correct
16 Correct 590 ms 54444 KB Output is correct
17 Correct 568 ms 52996 KB Output is correct
18 Correct 143 ms 11104 KB Output is correct
19 Correct 2089 ms 208260 KB Output is correct
20 Correct 2067 ms 208216 KB Output is correct
21 Correct 1705 ms 201504 KB Output is correct
22 Correct 416 ms 45532 KB Output is correct
23 Correct 552 ms 44772 KB Output is correct
24 Correct 119 ms 10592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2816 KB Output is correct
2 Correct 5 ms 2816 KB Output is correct
3 Correct 4 ms 2816 KB Output is correct
4 Correct 4 ms 2816 KB Output is correct
5 Correct 4 ms 2816 KB Output is correct
6 Correct 5 ms 2816 KB Output is correct
7 Correct 25 ms 7680 KB Output is correct
8 Correct 21 ms 7672 KB Output is correct
9 Correct 25 ms 7680 KB Output is correct
10 Correct 17 ms 4992 KB Output is correct
11 Correct 17 ms 4992 KB Output is correct
12 Correct 9 ms 3072 KB Output is correct
13 Correct 26 ms 7680 KB Output is correct
14 Correct 25 ms 7672 KB Output is correct
15 Correct 27 ms 7800 KB Output is correct
16 Correct 14 ms 4736 KB Output is correct
17 Correct 16 ms 4608 KB Output is correct
18 Correct 8 ms 3072 KB Output is correct
19 Correct 2137 ms 209304 KB Output is correct
20 Correct 2258 ms 207852 KB Output is correct
21 Correct 2273 ms 208028 KB Output is correct
22 Correct 686 ms 54368 KB Output is correct
23 Correct 588 ms 52572 KB Output is correct
24 Correct 154 ms 11056 KB Output is correct
25 Correct 2199 ms 201248 KB Output is correct
26 Correct 2131 ms 201588 KB Output is correct
27 Correct 1587 ms 190084 KB Output is correct
28 Correct 429 ms 45536 KB Output is correct
29 Correct 544 ms 44892 KB Output is correct
30 Correct 121 ms 10716 KB Output is correct
31 Correct 1996 ms 208036 KB Output is correct
32 Correct 2194 ms 207796 KB Output is correct
33 Correct 2096 ms 207924 KB Output is correct
34 Correct 590 ms 54444 KB Output is correct
35 Correct 568 ms 52996 KB Output is correct
36 Correct 143 ms 11104 KB Output is correct
37 Correct 2089 ms 208260 KB Output is correct
38 Correct 2067 ms 208216 KB Output is correct
39 Correct 1705 ms 201504 KB Output is correct
40 Correct 416 ms 45532 KB Output is correct
41 Correct 552 ms 44772 KB Output is correct
42 Correct 119 ms 10592 KB Output is correct
43 Correct 2434 ms 270036 KB Output is correct
44 Correct 2448 ms 270236 KB Output is correct
45 Correct 2538 ms 270128 KB Output is correct
46 Correct 860 ms 90040 KB Output is correct
47 Correct 801 ms 88392 KB Output is correct
48 Correct 145 ms 10592 KB Output is correct
49 Correct 2330 ms 258664 KB Output is correct
50 Correct 2163 ms 258816 KB Output is correct
51 Correct 1993 ms 246524 KB Output is correct
52 Correct 666 ms 80544 KB Output is correct
53 Correct 824 ms 83136 KB Output is correct