답안 #653183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
653183 2022-10-26T02:51:57 Z guagua0407 Zoltan (COCI16_zoltan) C++17
7 / 140
203 ms 38420 KB
    #include <bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define f first
    #define s second
    #define all(x) x.begin(),x.end()
    #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     
    void setIO(string s) {
    	freopen((s + ".in").c_str(), "r", stdin);
    	freopen((s + ".out").c_str(), "w", stdout);
    }
     
    const ll mxn=2e5+5;
    const ll mod=1e9+7;
    ll arr[mxn];
    ll id[mxn];
    map<ll,ll> num;
    ll MX=0;
    pair<ll,ll> segtree[mxn][2];
     
    ll fpow(ll a,ll b){
    	ll ans=1;
    	while(b>0){
    		if(b&1) ans=(ans*a)%mod;
    		a=(a*a)%mod;
    		b/=2;
    	}
    	return ans;
    }
     
    pair<ll,ll> comb(pair<ll,ll> a,pair<ll,ll> b){
    	if(a.f==b.f){
    		return {a.f,(a.s+b.s)%mod};
    	}
    	return max(a,b);
    }
     
    void update(ll pos,pair<ll,ll> val,ll k,ll l=1,ll r=MX,ll v=1){
    	if(l==r){
    		segtree[v][k]=comb(segtree[v][k],val);
    		return;
    	}
    	ll mid=(l+r)/2;
    	if(pos<=mid) update(pos,val,k,l,mid,v*2);
    	else update(pos,val,k,mid+1,r,v*2+1);
    	segtree[v][k]=comb(segtree[v*2][k],segtree[v*2+1][k]);
    }
     
    pair<ll,ll> query(ll tl,ll tr,ll k,ll l=1,ll r=MX,ll v=1){
    	if(tl>tr or l>r){
    		return {0,1};
    	}
    	else if(tl<=l and r<=tr){
    		return segtree[v][k];
    	}
    	ll mid=(l+r)/2;
    	return comb(query(tl,min(mid,tr),k,l,mid,v*2),query(max(tl,mid+1),tr,k,mid+1,r,v*2+1));
    }
     
     
    int main() {_
    	//setIO("wayne");
        ll n;
    	cin>>n;
    	for(ll i=1;i<=n;i++){
    		cin>>arr[i];
    		num[arr[i]]++;
    	}
    	for(auto &v:num){
    		MX++;
    		v.s=MX;
    	}
    	for(ll i=1;i<=n;i++){
    		id[i]=num[arr[i]];
    	}
    	for(ll i=n;i>=1;i--){
    		pair<ll,ll> tmp=query(id[i]+1,MX,0);
    		update(id[i],{tmp.f+1,tmp.s},0);
    	}
    	for(ll i=n;i>=1;i--){
    		pair<ll,ll> tmp=query(1,id[i]-1,1);
    		update(id[i],{tmp.f+1,tmp.s},1);
    	}
    	pair<ll,ll> best={1,n};
    	for(ll i=1;i<=n;i++){
    		best=comb(best,{(query(id[i],id[i],1).f+query(id[i]+1,MX,0).f)%mod,(query(id[i],id[i],1).s*query(id[i]+1,MX,0).s)%mod});
    		//cout<<best.f<<' '<<best.s<<'\n';
    	}
    	ll inv2=fpow(2,mod-2);
    	cout<<best.f<<' '<<((best.s*fpow(2,n-best.f))%mod*inv2)%mod;
    	return 0;
    }
    //maybe its multiset not set

Compilation message

zoltan.cpp: In function 'void setIO(std::string)':
zoltan.cpp:10:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |      freopen((s + ".in").c_str(), "r", stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
zoltan.cpp:11:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |      freopen((s + ".out").c_str(), "w", stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Incorrect 0 ms 212 KB Output isn't correct
7 Incorrect 2 ms 468 KB Output isn't correct
8 Incorrect 2 ms 468 KB Output isn't correct
9 Incorrect 2 ms 468 KB Output isn't correct
10 Incorrect 2 ms 468 KB Output isn't correct
11 Runtime error 106 ms 25900 KB Execution killed with signal 11
12 Runtime error 86 ms 22396 KB Execution killed with signal 11
13 Runtime error 99 ms 26452 KB Execution killed with signal 11
14 Runtime error 136 ms 22704 KB Execution killed with signal 11
15 Runtime error 184 ms 27764 KB Execution killed with signal 11
16 Runtime error 203 ms 38420 KB Execution killed with signal 11
17 Runtime error 114 ms 28176 KB Execution killed with signal 11
18 Runtime error 129 ms 28020 KB Execution killed with signal 11
19 Runtime error 97 ms 28128 KB Execution killed with signal 11
20 Runtime error 106 ms 28080 KB Execution killed with signal 11