Submission #705557

#TimeUsernameProblemLanguageResultExecution timeMemory
705557krizsu222Homework (CEOI22_homework)C++17
23 / 100
114 ms181000 KiB
#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") { //if(rs > mx) tree[v].value = tree[ls].value; //else tree[v].value = {max(tree[ls].value.first, tree[rs].value.first) + 1, max(tree[ls].value.second, tree[rs].value.second)}; tree[v].value = {tree[ls].value.first + tree[rs].value.first, max(tree[ls].value.second, tree[rs].value.second)}; } if(tree[v].type == "min") { //if(rs > mx) tree[v].value = tree[ls].value; //else tree[v].value = {min(tree[ls].value.first, tree[rs].value.first), min(tree[ls].value.second, tree[rs].value.second) - 1}; tree[v].value = {min(tree[ls].value.first, tree[rs].value.first), tree[ls].value.second + tree[rs].value.second - n - 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 = 1, 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) // cout << u << ' '; for(auto u : q) insert(u, q[q.size() - 1], question_marks); cout << tree[1].value.second - tree[1].value.first + 1 << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...