# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1050060 |
2024-08-09T07:07:11 Z |
hungeazy |
Zoltan (COCI16_zoltan) |
C++17 |
|
83 ms |
23496 KB |
/*
* @Author: hungeazy
* @Date: 2024-08-09 13:41:17
* @Last Modified by: hungeazy
* @Last Modified time: 2024-08-09 14:05:48
*/
#include <bits/stdc++.h>
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long
#define ull unsigned long long
#define sz(x) x.size()
#define sqr(x) (1LL * (x) * (x))
#define all(x) x.begin(), x.end()
#define fill(f,x) memset(f,x,sizeof(f))
#define FOR(i,l,r) for(int i=l;i<=r;i++)
#define FOD(i,r,l) for(int i=r;i>=l;i--)
#define ii pair<int,int>
#define iii pair<int,ii>
#define di pair<ii,ii>
#define vi vector<int>
#define vii vector<ii>
#define mii map<int,int>
#define fi first
#define se second
#define pb push_back
#define MOD 1000000007
#define __lcm(a,b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define YES cout << "YES\n"
#define NO cout << "NO\n"
#define MASK(i) (1LL << (i))
#define c_bit(i) __builtin_popcountll(i)
#define BIT(x,i) ((x) & MASK(i))
#define SET_ON(x,i) ((x) | MASK(i))
#define SET_OFF(x,i) ((x) & ~MASK(i))
#define oo 1e18
#define name ""
#define endl '\n'
#define time() cerr << endl << "-------------Time:" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms.";
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
const int N = (int)1e6+10;
int a[N],n;
namespace hungeazy {
ii bit[N][2];
int cnt[N][2],f[N][2];
vi v;
void update(int pos, int type, int val, int way)
{
int id = pos;
while (id <= v.size())
{
if (bit[id][type].fi < val) bit[id][type] = {val,way};
else if (bit[id][type].fi == val) (bit[id][type].se += way) %= MOD;
id += (id&(-id));
}
}
ii get(int pos, int type)
{
int id = pos;
ii ans = {0,1};
while (id)
{
if (ans.fi == bit[id][type].fi) (ans.se += bit[id][type].se) %= MOD;
else if (ans.fi < bit[id][type].fi) ans = bit[id][type];
id -= (id&(-id));
}
return ans;
}
void solve(void)
{
FOR(i,1,n) v.pb(a[i]);
sort(all(v));
v.erase(unique(all(v)),v.end());
FOR(i,1,n) a[i] = lower_bound(all(v),a[i])-v.begin()+1;
ii ans = {0,0};
FOD(i,n,1)
{
ii val = get(a[i]-1,0);
int w = val.se;
if (f[a[i]][0] < val.fi+1)
{
f[a[i]][0] = val.fi+1;
cnt[a[i]][0] = w;
update(a[i],0,f[a[i]][0],cnt[a[i]][0]);
}
else if (f[a[i]][0] == val.fi+1)
{
(cnt[a[i]][0] += w) %= MOD;
update(a[i],0,f[a[i]][0],val.se);
}
val = get(v.size()-a[i],1);
(w *= val.se) %= MOD;
if (f[a[i]][1] < val.fi+1)
{
f[a[i]][1] = val.fi+1;
cnt[a[i]][1] = val.se;
update(v.size()-a[i]+1,1,f[a[i]][1],cnt[a[i]][1]);
}
else if (f[a[i]][1] == val.fi+1)
{
(cnt[a[i]][1] += val.se) %= MOD;
update(v.size()-a[i]+1,1,f[a[i]][1],val.se);
}
if (f[a[i]][0]+f[a[i]][1]-1 > ans.fi) ans = {f[a[i]][0]+f[a[i]][1]-1,w};
else if (f[a[i]][0]+f[a[i]][1]-1 == ans.fi) (ans.se += w) %= MOD;
}
FOR(i,ans.fi+1,n) ans.se = 2*ans.se%MOD;
cout << ans.fi << " " << ans.se;
}
}
signed main()
{
fast;
if (fopen(name".inp","r"))
{
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
cin >> n;
FOR(i,1,n) cin >> a[i];
hungeazy::solve();
time();
return 0;
}
// ██░ ██ █ ██ ███▄ █ ▄████
//▓██░ ██▒ ██ ▓██▒ ██ ▀█ █ ██▒ ▀█▒
//▒██▀▀██░▓██ ▒██░▓██ ▀█ ██▒▒██░▄▄▄░
//░▓█ ░██ ▓▓█ ░██░▓██▒ ▐▌██▒░▓█ ██▓
//░▓█▒░██▓▒▒█████▓ ▒██░ ▓██░░▒▓███▀▒
// ▒ ░░▒░▒░▒▓▒ ▒ ▒ ░ ▒░ ▒ ▒ ░▒ ▒
// ▒ ░▒░ ░░░▒░ ░ ░ ░ ░░ ░ ▒░ ░ ░
// ░ ░░ ░ ░░░ ░ ░ ░ ░ ░ ░ ░ ░
// ░ ░ ░ ░ ░ ░
Compilation message
zoltan.cpp: In function 'void hungeazy::update(long long int, long long int, long long int, long long int)':
zoltan.cpp:57:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | while (id <= v.size())
| ~~~^~~~~~~~~~~
zoltan.cpp: In function 'int main()':
zoltan.cpp:127:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
127 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
zoltan.cpp:128:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
128 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
0 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
45 ms |
18668 KB |
Output is correct |
12 |
Correct |
37 ms |
15304 KB |
Output is correct |
13 |
Correct |
34 ms |
14796 KB |
Output is correct |
14 |
Correct |
52 ms |
15552 KB |
Output is correct |
15 |
Correct |
68 ms |
19848 KB |
Output is correct |
16 |
Correct |
83 ms |
23496 KB |
Output is correct |
17 |
Correct |
48 ms |
19316 KB |
Output is correct |
18 |
Correct |
52 ms |
19408 KB |
Output is correct |
19 |
Correct |
60 ms |
19536 KB |
Output is correct |
20 |
Correct |
48 ms |
19396 KB |
Output is correct |