Submission #445506

# Submission time Handle Problem Language Result Execution time Memory
445506 2021-07-18T11:11:33 Z keta_tsimakuridze Zoltan (COCI16_zoltan) C++14
49 / 140
564 ms 23336 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
const int N=2e5+5,mod=1e9+7;
int t,a[N],b[N],n,pwr[N];
pair<int,int> tree[4*N][2],l[N][2];
map<int,int> ind;
void upd(pii &a,pii b){
	if(a.f == b.f) {
		a.s = (a.s + b.s)%mod;
	}
	else if(a.f < b.f) {
		a.s = b.s;
		a.f = b.f;
	}
}
void update(int u,int ind,int l,int r,int val1,int val2,int t) {
	if(l>ind || r<ind) return;
	if(l==r) {
		upd(tree[u][t],{val1,val2});
		return;
	}
	int mid = (l+r)/2;
	update(2*u,ind,l,mid,val1,val2,t);
	update(2*u+1,ind,mid+1,r,val1,val2,t);
	tree[u][t] = {0,0};
	upd(tree[u][t],tree[2*u][t]);
	upd(tree[u][t],tree[2*u+1][t]);
}
pii getans(int u,int start,int end,int l,int r,int t) {
	if(l > end || r<start) return {0,0};
	if(start<=l && r<=end) return tree[u][t];
	int mid = (l+r)/2;
	pii g1 = getans(2*u,start,end,l,mid,t);
	pii g2 = getans(2*u+1,start,end,mid+1,r,t);
	upd(g1,g2);
	return g1;
}
 main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i] = a[i];
	}
	sort(b+1,b+n+1);
	int idx = 0;
	b[0] = -1;
	pwr[0] = 1;
	for(int i=1;i<=n;i++){
		pwr[i] = pwr[i-1] * 2 % mod;
		if(b[i]!=b[i-1]) idx++;
		ind[b[i]] = idx;
	}
	for(int i=n;i>=2;i--){
		a[i] = ind[a[i]];
		pii p = getans(1,1,a[i]-1,1,n,1);
		p.f++;
		if(p.f == 1) p.s = 1;
		upd(l[a[i]][1],p);
		update(1,a[i],1,n,p.f,p.s,1);
		
			 p = getans(1,a[i]+1,n,1,n,0);
			p.f++;
			if(p.f == 1) p.s = 1;
			update(1,a[i],1,n,p.f,p.s,0);
			upd(l[a[i]][0],p);
		
	}
	l[0][1] = {0,1};
	l[idx+1][0] = {0,1}; 
	pii ans;
	ans = {0,0};
	for(int i=idx;i>=0;i--){
		upd(l[i][0],l[i+1][0]);
	}
	for(int i=0;i<=idx;i++) {
		if(i)upd(l[i][1],l[i-1][1]);
		upd(ans,{l[i][1].f + l[i+1][0].f,(long long) l[i][1].s * l[i+1][0].s %mod* pwr[n -l[i][1].f - l[i+1][0].f - 1]%mod});
	}
	// 
	a[1] = ind[a[1]];
	pii p = getans(1,a[1]+1,n,1,n,0);
	p.f++;
	if(p.f==1) p.s = 1;
	for(int i=0; i<a[1]; i++) {
		upd(ans,{l[i][1].f + p.f,(long long) l[i][1].s * p.s %mod* pwr[n -l[i][1].f - p.f]%mod});
		
	}

	cout<<ans.f<<" "<<ans.s;
	
}

Compilation message

zoltan.cpp:41:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 |  main(){
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 300 KB Output isn't correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 2 ms 332 KB Output isn't correct
8 Incorrect 2 ms 440 KB Output isn't correct
9 Incorrect 2 ms 332 KB Output isn't correct
10 Incorrect 2 ms 332 KB Output isn't correct
11 Correct 336 ms 20332 KB Output is correct
12 Correct 281 ms 18756 KB Output is correct
13 Correct 265 ms 14052 KB Output is correct
14 Incorrect 375 ms 18824 KB Output isn't correct
15 Incorrect 486 ms 21388 KB Output isn't correct
16 Incorrect 564 ms 23336 KB Output isn't correct
17 Incorrect 415 ms 20156 KB Output isn't correct
18 Incorrect 419 ms 20064 KB Output isn't correct
19 Incorrect 420 ms 20052 KB Output isn't correct
20 Incorrect 428 ms 20032 KB Output isn't correct