Submission #874502

# Submission time Handle Problem Language Result Execution time Memory
874502 2023-11-17T07:19:29 Z serifefedartar Zoltan (COCI16_zoltan) C++17
14 / 140
259 ms 25768 KB
#include <bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9+9;
const ll LOGN = 20; 
const ll MAXN = 2e5 + 100;

vector<pair<int,int>> v;
vector<int> arr, cc;
pair<int,int> sg[4*MAXN], w1[MAXN], w2[MAXN];
pair<int,int> merge(pair<int,int> a, pair<int,int> b) {
	if (a.f == b.f)
		return {a.f, a.s + b.s};
	return max(a, b);
}

void update(int k, int a, int b, int plc, pair<int,int> val) {
	if (b < plc || a > plc)
		return ;
	if (a == b) {
		sg[k] = merge(val, sg[k]);
		return ;
	}
	update(2*k, a, (a+b)/2, plc, val);
	update(2*k+1, (a+b)/2+1, b, plc, val);
	sg[k] = merge(sg[2*k], sg[2*k+1]);
}

pair<int,int> query(int k, int a, int b, int q_l, int q_r) {
	if (b < q_l || a > q_r)
		return {0, 0};
	if (q_l <= a && b <= q_r)
		return sg[k];
	return merge(query(2*k, a, (a+b)/2, q_l, q_r),
				query(2*k+1, (a+b)/2+1, b, q_l, q_r));
}

int index(int k) {
	return upper_bound(cc.begin(), cc.end(), k) - cc.begin();
}

map<int,int> cnt;
int main() {
	fast
	int N;
	cin >> N;

	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		cc.push_back(A[i]);
		cnt[A[i]]++;
	}
	for (int i = 0; i < N; i++)
		v.push_back({A[i], i+1});
	sort(v.begin(), v.end());
	sort(cc.begin(), cc.end());
	cc.erase(unique(cc.begin(), cc.end()), cc.end()); 

	for (auto u : v)
		arr.push_back(u.s);

	for (int i = 0; i < N; i++) {
		pair<int,int> Q = query(1, 0, N, index(arr[i]) + 1, N);
		if (Q.f == 0)
			Q.s++;
		w1[i+1] = {Q.f + 1, Q.s};
		update(1, 0, N, index(arr[i]), w1[i+1]);
	}
	for (int i = 0; i < 4*MAXN; i++)
		sg[i] = {0, 0};

	for (int i = N-1; i >= 0; i--) {
		pair<int,int> Q = query(1, 0, N, index(arr[i]) + 1, N);
		if (Q.f == 0)
			Q.s++;
		w2[i+1] = {Q.f + 1, Q.s};
		update(1, 0, N, index(arr[i]), w2[i+1]); 
	}

	pair<int,int> ans = {0, 0};
	for (int i = 1; i <= N; i++)
		ans = merge(ans, {w1[i].f + w2[i].f - 1, w1[i].s * w2[i].s});

	for (auto u : cnt)
		ans.s *= u.s; 
	cout << ans.f << " " << ans.s << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 8540 KB Output isn't correct
2 Incorrect 2 ms 8540 KB Output isn't correct
3 Incorrect 2 ms 8656 KB Output isn't correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Incorrect 2 ms 8540 KB Output isn't correct
7 Incorrect 3 ms 8796 KB Output isn't correct
8 Incorrect 4 ms 8796 KB Output isn't correct
9 Incorrect 3 ms 8796 KB Output isn't correct
10 Incorrect 3 ms 8796 KB Output isn't correct
11 Incorrect 156 ms 22072 KB Output isn't correct
12 Incorrect 139 ms 20548 KB Output isn't correct
13 Incorrect 129 ms 19320 KB Output isn't correct
14 Incorrect 161 ms 20820 KB Output isn't correct
15 Incorrect 193 ms 23616 KB Output isn't correct
16 Incorrect 226 ms 25768 KB Output isn't correct
17 Incorrect 246 ms 23836 KB Output isn't correct
18 Incorrect 251 ms 23876 KB Output isn't correct
19 Incorrect 259 ms 23876 KB Output isn't correct
20 Incorrect 243 ms 23804 KB Output isn't correct