This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
#define TREE_SIZE (1<<20)
#define ls (v * 2)
#define rs (v * 2 + 1)
using namespace std;
struct node
{
pair <int, int> value;
string type;
} tree[TREE_SIZE * 2];
string s;
void insert(int v, int mx, int n)
{
tree[v].value = {1, n};
while(v != 0)
{
v /= 2;
if(tree[v].type == "max")
{
tree[v].value = {min(tree[ls].value.first, tree[rs].value.first) + 1, max(tree[ls].value.second, tree[rs].value.second)};
}
if(tree[v].type == "min")
{
tree[v].value = {min(tree[ls].value.first, tree[rs].value.first), min(tree[ls].value.second, tree[rs].value.second) - 1};
}
}
}
signed main()
{
cin.tie(0) -> ios_base::sync_with_stdio(0);
cin >> s;
int question_marks = count(s.begin(), s.end(), '?');
vector <int> q;
int mx = 0, mm = 0, it = 0, son = 0;
for(auto u : s)
{
if(u == 'm' || u == 'a' || u == 'i') continue;
if(u == '(') it *= 2;
if(u == ')') it /= 2;
it += son;
int act_son = it;
if(u == ',') son = 1;
else son = 0;
if(u == 'n')
{
tree[act_son].type = "min";
mm++;
}
if(u == 'x')
{
tree[act_son].type = "max";
mx++;
}
if(u == '?')
{
tree[act_son].type = "const";
q.push_back(act_son);
}
}
for(auto u : q)
insert(u, q[q.size() - 1], question_marks);
if(mx == 0 || mm == 0)
cout << tree[1].value.second - tree[1].value.first - 1 << '\n';
else
cout << tree[1].value.second - tree[1].value.first << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |