Submission #445505

# Submission time Handle Problem Language Result Execution time Memory
445505 2021-07-18T11:01:30 Z keta_tsimakuridze Zoltan (COCI16_zoltan) C++14
35 / 140
687 ms 41932 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
#define pii pair<int,int>
using namespace std;
const int N=5e5+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;
	
	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]);
	//	cout<<i<<"__"<<l[i][1].f<<" "<<l[i+1][0].f<<" "<<l[i][1].s*l[i+1][0].s<<endl;
		upd(ans,{l[i][1].f + l[i+1][0].f, 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, 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:42:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   42 |  main(){
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Correct 1 ms 304 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Incorrect 2 ms 460 KB Output isn't correct
8 Incorrect 2 ms 460 KB Output isn't correct
9 Incorrect 2 ms 460 KB Output isn't correct
10 Incorrect 2 ms 460 KB Output isn't correct
11 Runtime error 384 ms 36420 KB Memory limit exceeded
12 Runtime error 337 ms 33856 KB Memory limit exceeded
13 Correct 288 ms 24640 KB Output is correct
14 Runtime error 442 ms 34240 KB Memory limit exceeded
15 Runtime error 565 ms 38596 KB Memory limit exceeded
16 Runtime error 687 ms 41932 KB Memory limit exceeded
17 Runtime error 512 ms 35736 KB Memory limit exceeded
18 Runtime error 460 ms 35736 KB Memory limit exceeded
19 Runtime error 452 ms 35776 KB Memory limit exceeded
20 Runtime error 458 ms 35760 KB Memory limit exceeded