Submission #577256

# Submission time Handle Problem Language Result Execution time Memory
577256 2022-06-14T11:02:50 Z GioChkhaidze Zoltan (COCI16_zoltan) C++14
140 / 140
290 ms 10944 KB
// 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

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 time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 149 ms 10456 KB Output is correct
12 Correct 139 ms 10196 KB Output is correct
13 Correct 118 ms 6036 KB Output is correct
14 Correct 176 ms 10292 KB Output is correct
15 Correct 195 ms 10676 KB Output is correct
16 Correct 290 ms 10944 KB Output is correct
17 Correct 192 ms 9732 KB Output is correct
18 Correct 179 ms 9728 KB Output is correct
19 Correct 249 ms 9728 KB Output is correct
20 Correct 218 ms 9664 KB Output is correct