# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
82219 |
2018-10-29T14:02:59 Z |
luciocf |
Doktor (COCI17_doktor) |
C++14 |
|
430 ms |
132096 KB |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5+10;
struct Node
{
Node *l, *r;
int v;
Node()
{
l = r = NULL;
v = 0;
}
};
Node *version[maxn];
int num[maxn], soma[maxn], n;
void build(Node *node, int l, int r)
{
if (l == r) return;
int mid = (l+r)>>1;
node->l = new Node(), node->r = new Node();
build(node->l, l, mid); build(node->r, mid+1, r);
}
void upd(Node *prev, Node *node, int l, int r, int pos)
{
if (l == r)
{
node->v = prev->v+1;
return;
}
int mid = (l+r)>>1;
if (pos <= mid)
{
node->r = prev->r;
if (node->l == NULL) node->l = new Node();
upd(prev->l, node->l, l, mid, pos);
}
else
{
node->l = prev->l;
if (node->r == NULL) node->r = new Node();
upd(prev->r, node->r, mid+1, r, pos);
}
node->v = node->l->v+node->r->v;
}
int query(Node *prev, Node *node, int l, int r, int pos)
{
if (l == r) return node->v-prev->v;
int mid = (l+r)>>1;
if (pos <= mid) return query(prev->l, node->l, l, mid, pos);
return query(prev->r, node->r, mid+1, r, pos);
}
int main(void)
{
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> num[i];
if (num[i] == i) soma[i] = soma[i-1]+1;
else soma[i] = soma[i-1];
}
version[0] = new Node();
build(version[0], 1, 2*n);
for (int i = 1; i <= n; i++)
{
version[i] = new Node();
upd(version[i-1], version[i], 1, 2*n, num[i]+i);
}
int ans = 0, ind1 = num[1], ind2 = num[2];
for (int i = 1; i <= n; i++)
{
if (num[i] < i) continue;
int aux = soma[i-1]+soma[n]-soma[num[i]];
aux += query(version[i-1], version[num[i]], 1, 2*n, num[i]+i);
if (aux > ans)
{
ans = aux;
ind1 = num[i], ind2 = num[num[i]];
}
}
for (int i = 1; i <= n; i++)
{
if (num[i] > i) continue;
int aux = soma[n]-soma[i]+soma[num[i]-1];
aux += query(version[num[i]-1], version[i], 1, 2*n, num[i]+i);
if (aux > ans)
{
ans = aux;
ind1 = num[num[i]], ind2 = num[i];
}
}
cout << ind1 << " " << ind2 << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
552 KB |
Output is correct |
2 |
Correct |
3 ms |
772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1704 KB |
Output is correct |
2 |
Correct |
4 ms |
1704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
3196 KB |
Output is correct |
2 |
Correct |
5 ms |
3196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
3548 KB |
Output is correct |
2 |
Correct |
3 ms |
3548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
6748 KB |
Output is correct |
2 |
Runtime error |
301 ms |
132096 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
291 ms |
132096 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
392 ms |
132096 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
430 ms |
132096 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |