Submission #577256

#TimeUsernameProblemLanguageResultExecution timeMemory
577256GioChkhaidzeZoltan (COCI16_zoltan)C++14
140 / 140
290 ms10944 KiB
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> #define lf (h << 1) #define mf ((l + r) >> 1) #define rf ((h << 1) | 1) #define tree int h, int l, int r #define left lf, l, mf #define right rf, mf + 1, r #define ll long long #define pb push_back #define f first #define s second using namespace std; const int N = 2e5 + 5; ll mod = 1e9 + 7; int n, L, R, id, a[N]; pair < int , ll > vld, vli; pair < int , int > vd[4 * N], vi[4 * N]; void updd(tree) { if (r < id || id < l) return; if (l == id && id == r) { if (vd[h].f < vld.f) { vd[h] = vld; } else if (vd[h].f == vld.f) { vd[h].s = (vd[h].s + vld.s) % mod; } return ; } updd(left), updd(right); if (vd[lf].f > vd[rf].f) vd[h] = vd[lf]; else if (vd[lf].f < vd[rf].f) vd[h] = vd[rf]; else { vd[h].f = vd[lf].f; vd[h].s = (vd[lf].s + vd[rf].s) % mod; } } void updi(tree) { if (r < id || id < l) return; if (l == id && id == r) { if (vi[h].f < vli.f) { vi[h] = vli; } else if (vi[h].f == vli.f) { vi[h].s = (vi[h].s + vli.s) % mod; } return ; } updi(left), updi(right); if (vi[lf].f > vi[rf].f) vi[h] = vi[lf]; else if (vi[lf].f < vi[rf].f) vi[h] = vi[rf]; else { vi[h].f = vi[lf].f; vi[h].s = (vi[lf].s + vi[rf].s) % mod; } } pair < int , int > geti(tree) { if (r < L || R < l) return {0, 1}; if (L <= l && r <= R) return vi[h]; pair < int , int > x = geti(left); pair < int , int > y = geti(right); if (x.f > y.f) return x; if (x.f < y.f) return y; return {x.f, (x.s + y.s) % mod}; } pair < int , int > getd(tree) { if (r < L || R < l) return {0, 1}; if (L <= l && r <= R) return vd[h]; pair < int , int > x = getd(left); pair < int , int > y = getd(right); if (x.f > y.f) return x; if (x.f < y.f) return y; return {x.f, (x.s + y.s) % mod}; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; vector < pair < int , int > > s; for (int i = 1; i <= n; ++i) { cin >> a[i]; s.pb({a[i], i}); } int ts = 0; sort(s.begin(), s.end()); for (int i = 0; i < s.size(); ++i) { if (!i || s[i].f != s[i - 1].f) ++ts; a[s[i].s] = ts; } pair < int , ll > ans = {0, 0}; for (int i = n; i >= 1; --i) { id = a[i]; L = a[i] + 1, R = n, vld = getd(1, 1, n); if (!vld.f) vld.s = 1; ++vld.f, updd(1, 1, n); L = 1, R = a[i] - 1, vli = geti(1, 1, n); if (!vli.f) vli.s = 1; ++vli.f, updi(1, 1, n); int cst = vld.f - 1 + vli.f; ll num = (vld.s * vli.s) % mod; if (ans.f < cst) { ans.f = cst; ans.s = num; } else if (ans.f == cst) { ans.s = (ans.s + num) % mod; } } for (int i = 1; i <= n - ans.f; ++i) { ans.s = (ans.s * 2) % mod; } cout << ans.f << " " << ans.s << "\n"; }

Compilation message (stderr)

zoltan.cpp: In function 'int main()':
zoltan.cpp:100:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |  for (int i = 0; i < s.size(); ++i) {
      |                  ~~^~~~~~~~~~
zoltan.cpp:109:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  109 |   if (!vld.f) vld.s = 1; ++vld.f, updd(1, 1, n);
      |   ^~
zoltan.cpp:109:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  109 |   if (!vld.f) vld.s = 1; ++vld.f, updd(1, 1, n);
      |                          ^~
zoltan.cpp:111:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  111 |   if (!vli.f) vli.s = 1; ++vli.f, updi(1, 1, n);
      |   ^~
zoltan.cpp:111:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  111 |   if (!vli.f) vli.s = 1; ++vli.f, updi(1, 1, n);
      |                          ^~
#Verdict Execution timeMemoryGrader output
Fetching results...