Submission #802963

# Submission time Handle Problem Language Result Execution time Memory
802963 2023-08-02T16:39:04 Z kshitij_sodani Radio Towers (IOI22_towers) C++17
56 / 100
4000 ms 17624 KB
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long llo;
#include "towers.h"

#include <vector>
int st=0;
int n;
vector<int> it;
int tree[4*200001][2];
void build(int no,int l,int r){
	if(l==r){
		tree[no][0]=it[l];
		tree[no][1]=it[l];
	}
	else{
		int mid=(l+r)/2;
		build(no*2+1,l,mid);
		build(no*2+2,mid+1,r);
		tree[no][0]=min(tree[no*2+1][0],tree[no*2+2][0]);
		tree[no][1]=max(tree[no*2+1][1],tree[no*2+2][1]);
	}
}
int query(int no,int l,int r,int aa,int bb){
	if(r<aa or l>bb or aa>bb){
		return 1e9+1;
	}
	if(aa<=l and r<=bb){
		return tree[no][0];
	}
	int mid=(l+r)/2;
	return min(query(no*2+1,l,mid,aa,bb),query(no*2+2,mid+1,r,aa,bb));
}
int query2(int no,int l,int r,int aa,int bb){
	if(r<aa or l>bb or aa>bb){
		return -1;
	}
	if(aa<=l and r<=bb){
		return tree[no][1];
	}
	int mid=(l+r)/2;
	return max(query2(no*2+1,l,mid,aa,bb),query2(no*2+2,mid+1,r,aa,bb));
}
void init(int nn, vector<int> ita) {
	n=nn;
	it=ita;
	st=0;
	build(0,0,n-1);
}
int re[100001][2];
int par[200001][20];
set<pair<int,int>> xx[2];
vector<pair<pair<int,int>,int>> yy;
map<int,int> kk;
int max_towers(int l, int r, int d) {
	if(kk.find(d)==kk.end()){
		llo ind=n;
		kk[d]++;

		yy.clear();
		xx[0].clear();
		xx[1].clear();

		for(int i=n-1;i>=0;i--){
			llo cur=query(0,0,n-1,i+1,ind-1);
			if(cur<=it[i]-d){
				llo zz=ind-1;
				while(zz>i){
					zz--;
					if(query(0,0,n-1,i+1,zz)<=it[i]-d){
						continue;
					}
					else{
						zz++;
						break;
					}
				}
				xx[0].insert({i,yy.size()});
				yy.pb({{i,zz},0});
				re[i][0]=zz;
				ind=zz;
			}
			else{
				re[i][0]=-1;
			}
		}
		ind=n;
		for(int i=n-1;i>=0;i--){
			llo cur=query2(0,0,n-1,i+1,ind-1);
			if(cur>=it[i]+d){
				llo zz=ind-1;
				while(zz>i){
					zz--;
					if(query2(0,0,n-1,i+1,zz)>=it[i]+d){
						continue;
					}
					else{
						zz++;
						break;
					}
				}
				re[i][1]=zz;
				xx[1].insert({i,yy.size()});
				yy.pb({{i,zz},1});
				ind=zz;
			}
			else{
				re[i][1]=-1;
			}
		}
		for(int i=0;i<yy.size();i++){
			par[i][0]=-1;
			auto j=xx[1-yy[i].b].lower_bound({yy[i].a.b,-1});
			if(j!=xx[1-yy[i].b].end()){
				par[i][0]=(*j).b;
			//	cout<<i<<":"<<(*j).b<<endl;
			}
		}
		for(int j=1;j<20;j++){
			for(int i=0;i<yy.size();i++){
				if(par[i][j-1]==-1){
					par[i][j]=-1;
				}
				else{
					par[i][j]=par[par[i][j-1]][j-1];
				}
			}
		}
	/*	for(auto j:yy){
			cout<<j.a.a<<","<<j.a.b<<","<<j.b<<endl;
		}
*/
		st=1;
	}
//	cout<<l<<",,,,"<<-1<<endl;
/*	for(auto j:xx[1]){
		cout<<j.a<<"//"<<j.b<<endl;
	}*/
	auto j=xx[1].lower_bound({l,-1});
	if(j==xx[1].end()){
		return 1;
	}
	int cot=(*j).b;
	//cout<<cot<<":::::"<<yy[cot].a.b<<endl;
//	cout<<((*j).a)<<"<<"<<endl;
	if(yy[cot].a.b>r){
		return 1;
	}
	//cout<<22<<endl;
	int su=1;
//cout<<cot<<";;"<<endl;
	//cout<<par[cot][0]<<":"<<par[cot][1]<<":"<<par[cot][2]<<endl;
	//cout<<par[cot][0]<<";;"<<yy[par[cot][0]].a.b<<";;"<<endl;
	for(int j=19;j>=0;j--){
		if(par[cot][j]>=0){
		//	cout<<yy[par[cot][j]].a.b<<";"<<j<<endl;
			if(yy[par[cot][j]].a.b<=r){
				cot=par[cot][j];
				su+=(1<<j);
			}
		}
	}
	//cout<<su<<",,,,"<<endl;
    return ((su)/2)+1;
}

Compilation message

towers.cpp: In function 'int max_towers(int, int, int)':
towers.cpp:114:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |   for(int i=0;i<yy.size();i++){
      |               ~^~~~~~~~~~
towers.cpp:123:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |    for(int i=0;i<yy.size();i++){
      |                ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 4035 ms 6196 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 640 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 2 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 640 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 2 ms 464 KB Output is correct
36 Correct 45 ms 10168 KB Output is correct
37 Correct 66 ms 6584 KB Output is correct
38 Correct 68 ms 11028 KB Output is correct
39 Correct 69 ms 4552 KB Output is correct
40 Correct 72 ms 16024 KB Output is correct
41 Correct 66 ms 11192 KB Output is correct
42 Correct 74 ms 17580 KB Output is correct
43 Correct 69 ms 9448 KB Output is correct
44 Correct 60 ms 9248 KB Output is correct
45 Correct 45 ms 5160 KB Output is correct
46 Correct 69 ms 5980 KB Output is correct
47 Correct 74 ms 17564 KB Output is correct
48 Correct 74 ms 17612 KB Output is correct
49 Correct 75 ms 17572 KB Output is correct
50 Correct 54 ms 17580 KB Output is correct
51 Correct 74 ms 17560 KB Output is correct
52 Correct 76 ms 17624 KB Output is correct
53 Correct 75 ms 17544 KB Output is correct
54 Correct 80 ms 17564 KB Output is correct
55 Correct 53 ms 17608 KB Output is correct
56 Correct 78 ms 17564 KB Output is correct
57 Correct 71 ms 7616 KB Output is correct
58 Correct 67 ms 9752 KB Output is correct
59 Correct 68 ms 12332 KB Output is correct
60 Correct 77 ms 17568 KB Output is correct
61 Correct 78 ms 16060 KB Output is correct
62 Correct 68 ms 13052 KB Output is correct
63 Correct 71 ms 16348 KB Output is correct
64 Correct 51 ms 7204 KB Output is correct
65 Correct 48 ms 6884 KB Output is correct
66 Correct 95 ms 5296 KB Output is correct
67 Correct 50 ms 6968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 590 ms 17412 KB Output is correct
2 Correct 791 ms 17508 KB Output is correct
3 Correct 792 ms 17532 KB Output is correct
4 Correct 906 ms 17596 KB Output is correct
5 Correct 816 ms 17580 KB Output is correct
6 Correct 866 ms 17600 KB Output is correct
7 Correct 747 ms 17596 KB Output is correct
8 Correct 771 ms 17568 KB Output is correct
9 Correct 842 ms 17608 KB Output is correct
10 Correct 697 ms 17596 KB Output is correct
11 Correct 784 ms 17560 KB Output is correct
12 Correct 886 ms 17568 KB Output is correct
13 Correct 804 ms 17560 KB Output is correct
14 Correct 0 ms 208 KB Output is correct
15 Correct 1 ms 592 KB Output is correct
16 Correct 1 ms 592 KB Output is correct
17 Correct 74 ms 17616 KB Output is correct
18 Correct 74 ms 17604 KB Output is correct
19 Correct 90 ms 17620 KB Output is correct
20 Correct 54 ms 17560 KB Output is correct
21 Correct 74 ms 17564 KB Output is correct
22 Correct 74 ms 17560 KB Output is correct
23 Correct 73 ms 17580 KB Output is correct
24 Correct 74 ms 17596 KB Output is correct
25 Correct 57 ms 17592 KB Output is correct
26 Correct 71 ms 17624 KB Output is correct
27 Correct 2 ms 592 KB Output is correct
28 Correct 1 ms 592 KB Output is correct
29 Correct 1 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 1 ms 592 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4056 ms 4440 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 464 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 336 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 0 ms 208 KB Output is correct
13 Correct 1 ms 592 KB Output is correct
14 Correct 1 ms 592 KB Output is correct
15 Correct 2 ms 592 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 2 ms 592 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 2 ms 592 KB Output is correct
21 Correct 2 ms 592 KB Output is correct
22 Correct 2 ms 640 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 1 ms 592 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 2 ms 464 KB Output is correct
36 Correct 45 ms 10168 KB Output is correct
37 Correct 66 ms 6584 KB Output is correct
38 Correct 68 ms 11028 KB Output is correct
39 Correct 69 ms 4552 KB Output is correct
40 Correct 72 ms 16024 KB Output is correct
41 Correct 66 ms 11192 KB Output is correct
42 Correct 74 ms 17580 KB Output is correct
43 Correct 69 ms 9448 KB Output is correct
44 Correct 60 ms 9248 KB Output is correct
45 Correct 45 ms 5160 KB Output is correct
46 Correct 69 ms 5980 KB Output is correct
47 Correct 74 ms 17564 KB Output is correct
48 Correct 74 ms 17612 KB Output is correct
49 Correct 75 ms 17572 KB Output is correct
50 Correct 54 ms 17580 KB Output is correct
51 Correct 74 ms 17560 KB Output is correct
52 Correct 76 ms 17624 KB Output is correct
53 Correct 75 ms 17544 KB Output is correct
54 Correct 80 ms 17564 KB Output is correct
55 Correct 53 ms 17608 KB Output is correct
56 Correct 78 ms 17564 KB Output is correct
57 Correct 71 ms 7616 KB Output is correct
58 Correct 67 ms 9752 KB Output is correct
59 Correct 68 ms 12332 KB Output is correct
60 Correct 77 ms 17568 KB Output is correct
61 Correct 78 ms 16060 KB Output is correct
62 Correct 68 ms 13052 KB Output is correct
63 Correct 71 ms 16348 KB Output is correct
64 Correct 51 ms 7204 KB Output is correct
65 Correct 48 ms 6884 KB Output is correct
66 Correct 95 ms 5296 KB Output is correct
67 Correct 50 ms 6968 KB Output is correct
68 Correct 590 ms 17412 KB Output is correct
69 Correct 791 ms 17508 KB Output is correct
70 Correct 792 ms 17532 KB Output is correct
71 Correct 906 ms 17596 KB Output is correct
72 Correct 816 ms 17580 KB Output is correct
73 Correct 866 ms 17600 KB Output is correct
74 Correct 747 ms 17596 KB Output is correct
75 Correct 771 ms 17568 KB Output is correct
76 Correct 842 ms 17608 KB Output is correct
77 Correct 697 ms 17596 KB Output is correct
78 Correct 784 ms 17560 KB Output is correct
79 Correct 886 ms 17568 KB Output is correct
80 Correct 804 ms 17560 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 1 ms 592 KB Output is correct
83 Correct 1 ms 592 KB Output is correct
84 Correct 74 ms 17616 KB Output is correct
85 Correct 74 ms 17604 KB Output is correct
86 Correct 90 ms 17620 KB Output is correct
87 Correct 54 ms 17560 KB Output is correct
88 Correct 74 ms 17564 KB Output is correct
89 Correct 74 ms 17560 KB Output is correct
90 Correct 73 ms 17580 KB Output is correct
91 Correct 74 ms 17596 KB Output is correct
92 Correct 57 ms 17592 KB Output is correct
93 Correct 71 ms 17624 KB Output is correct
94 Correct 2 ms 592 KB Output is correct
95 Correct 1 ms 592 KB Output is correct
96 Correct 1 ms 592 KB Output is correct
97 Correct 1 ms 592 KB Output is correct
98 Correct 1 ms 592 KB Output is correct
99 Correct 2 ms 592 KB Output is correct
100 Correct 1 ms 592 KB Output is correct
101 Correct 2 ms 592 KB Output is correct
102 Correct 1 ms 592 KB Output is correct
103 Correct 1 ms 592 KB Output is correct
104 Correct 624 ms 13116 KB Output is correct
105 Correct 708 ms 11932 KB Output is correct
106 Correct 776 ms 8796 KB Output is correct
107 Correct 885 ms 13632 KB Output is correct
108 Correct 792 ms 5144 KB Output is correct
109 Correct 759 ms 13108 KB Output is correct
110 Correct 953 ms 17580 KB Output is correct
111 Correct 893 ms 8320 KB Output is correct
112 Correct 601 ms 7176 KB Output is correct
113 Correct 761 ms 4564 KB Output is correct
114 Correct 788 ms 6868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 4035 ms 6196 KB Time limit exceeded
2 Halted 0 ms 0 KB -