Submission #376332

#TimeUsernameProblemLanguageResultExecution timeMemory
376332ja_kingyZoltan (COCI16_zoltan)C++14
0 / 140
1097 ms24300 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; typedef long double ld; typedef pair<int,int> pii; using vi = vector<int>; #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define LOG2(x)(31-__builtin_clz(x|1)) #define rep(i, a, b) for (__typeof(a) i = a; i < b; i++) #define repe(i, a, b) for (__typeof(a) i = a; i <= b; i++) // Debugging template <typename T> string arrayStr(T *arr,int sz){string ret = "[";for(int i=0;i<sz;i++){ret+=to_string(arr[i])+", "; } return ret + "]";} #define db(x) cout << (#x) << ": " << x << ", " #define dbbin(x, n) cout << (#x) << ": " << bitset<n>(x) << ", " #define dbarr(x, n) cout << (#x) << ": " << arrayStr((x), (n)) << ", " #define dbvec(x) dbarr((x).data(),sz(x)) #define dbln cout << endl; const int mxN = 2e5, MOD = 1e9+7; int n, a[mxN], ord[mxN], mnp[mxN], mxp[mxN], pt, pfx[mxN]; pii ans; pii comb(pii a, pii b) { if (a.first != b.first) { return max(a,b); } else { return {a.first, (a.second + b.second) % MOD}; } } struct ST { vector<pii> st; int sz; ST(int sz) : sz(sz), st(sz*2) {} void upd(int x, pii v) { db(x); db(v.first); db(v.second); dbln; for (x += sz; x; x /= 2) st[x] = comb(st[x], v); } pii qry(int l, int r) { pii res = {0,0}; for (l += n, r += n; l < r; l /= 2, r /= 2) { if (l&1) res = comb(res, st[l++]); if (r&1) res = comb(res, st[--r]); } return res; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; ord[i] = a[i]; } sort(ord, ord+n); for (int i = 0; i < n; ++i) { a[i] = lower_bound(ord, ord+n, a[i]) - ord; } int mn = mxN, mx = 0; for (int i = 0; i < n; ++i) { if (a[i] < mn || a[i] > mx && pt == i) { pt++; } mn = min(mn, a[i]); mx = max(mx, a[i]); mnp[i] = mn; mxp[i] = mx; } ST lis(n), lds(n); if (pt == n) { ans = comb(ans, {n, 1}); } int t = 1; for (int i = n; i--;) { if (i && i-1 < pt) { pii res = lis.qry(mxp[i-1]+1, n); res = comb(res, {0,t*2%MOD}); res.first += i; ans = comb(ans, res); res = lds.qry(0, mnp[i-1]); res = comb(res, {0,t*2%MOD}); res.first += i; ans = comb(ans, res); } if (i == 0) { ans = comb(ans, lis.qry(0, n)); ans = comb(ans, lds.qry(0, n)); } pii res = lis.qry(a[i]+1, n); res = comb(res, {0,t}); res.first++; lis.upd(a[i], res); res = lds.qry(0, a[i]); res = comb(res, {0,t}); res.first++; lds.upd(a[i], res); t = t * 2 % MOD; } if (ans.first == 1) ans.second = ((long long)ans.second * 500000004 + 1) % MOD; cout << ans.first << ' ' << ans.second; }

Compilation message (stderr)

zoltan.cpp: In constructor 'ST::ST(int)':
zoltan.cpp:38:9: warning: 'ST::sz' will be initialized after [-Wreorder]
   38 |     int sz;
      |         ^~
zoltan.cpp:37:17: warning:   'std::vector<std::pair<int, int> > ST::st' [-Wreorder]
   37 |     vector<pii> st;
      |                 ^~
zoltan.cpp:39:5: warning:   when initialized here [-Wreorder]
   39 |     ST(int sz) : sz(sz), st(sz*2) {}
      |     ^~
zoltan.cpp: In function 'int main()':
zoltan.cpp:68:36: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   68 |         if (a[i] < mn || a[i] > mx && pt == i) {
      |                          ~~~~~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...