Submission #319223

# Submission time Handle Problem Language Result Execution time Memory
319223 2020-11-04T14:18:06 Z kshitij_sodani Money (IZhO17_money) C++14
45 / 100
1500 ms 153384 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
//#define endl '\n'
int n;
int it[1000001];
int tree[1000001*4];
void build(int no,int l,int r){
	if(l==r){
		tree[no]=it[l];
	}
	else{
		int mid=(l+r)/2;
		build(no*2+1,l,mid);
		build(no*2+2,mid+1,r);
		tree[no]=max(tree[no*2+1],tree[no*2+2]);
	}
}
int query(int no,int l,int r,int aa,int bb){
	if(r<aa){
		return -1;
	}
	if(aa<=l){
		if(tree[no]<=bb){
			return -1;
		}
		if(l==r){
			return l;
		}
	}
	int mid=(l+r)/2;
	int x=query(no*2+1,l,mid,aa,bb);
	if(x==-1){
		return query(no*2+2,mid+1,r,aa,bb);
	}
	else{
		return x;
	}
}
bool cmp(pair<int,int> aa,pair<int,int> bb){
	return aa.b<bb.b;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>it[i];
	}
	vector<pair<int,int>> ss;
	vector<pair<int,int>> tt;
	set<int> kk;
	build(0,0,n-1);
	for(int i=0;i<n;i++){
		while(ss.size()){
			if(ss.back().a<=it[i]){
				ss.pop_back();
			}
			else{
				break;
			}
		}
		if(ss.size()){
			int ne=ss.back().b;
			tt.pb({ne,i-1});
			int jj=*kk.upper_bound(it[i]);
			/*int low=i;
			for(int j=19;j>=0;j--){
				if(low+(1<<j)<n){
					if(query(0,0,n-1,i,low+(1<<j))<=jj){
						low+=(1<<j);
					}
				}
			}*/
			int low=query(0,0,n-1,i,jj);
			if(low!=-1){
				tt.pb({i,low-1});
			}
		}
		kk.insert(it[i]);
		ss.pb({it[i],i});
	}
	set<pair<int,int>> mm;
	for(auto j:tt){
		mm.insert(j);
	}
	sort(tt.begin(),tt.end(),cmp);
	int ans=1;
	for(auto j:tt){
		if(mm.find(j)!=mm.end()){
			ans+=1;
			while(mm.size()){
				if((*mm.begin()).a<=j.b){
					mm.erase(mm.begin());
				}
				else{
					break;
				}
			}
		}
	}
	cout<<ans<<endl;
 
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 444 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 404 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 0 ms 396 KB Output is correct
8 Correct 0 ms 356 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 444 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 404 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 0 ms 396 KB Output is correct
8 Correct 0 ms 356 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 444 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 404 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 0 ms 396 KB Output is correct
8 Correct 0 ms 356 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 444 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 0 ms 404 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 0 ms 396 KB Output is correct
8 Correct 0 ms 356 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 346 ms 46532 KB Output is correct
40 Correct 703 ms 90040 KB Output is correct
41 Correct 264 ms 35216 KB Output is correct
42 Correct 310 ms 41796 KB Output is correct
43 Correct 216 ms 28952 KB Output is correct
44 Correct 857 ms 105436 KB Output is correct
45 Correct 781 ms 98536 KB Output is correct
46 Correct 844 ms 105264 KB Output is correct
47 Correct 401 ms 43596 KB Output is correct
48 Correct 561 ms 71108 KB Output is correct
49 Correct 1427 ms 133336 KB Output is correct
50 Correct 1325 ms 129072 KB Output is correct
51 Correct 1426 ms 139604 KB Output is correct
52 Correct 1335 ms 129336 KB Output is correct
53 Correct 1368 ms 133808 KB Output is correct
54 Correct 1314 ms 128976 KB Output is correct
55 Execution timed out 1610 ms 153384 KB Time limit exceeded
56 Halted 0 ms 0 KB -