Submission #705554

#TimeUsernameProblemLanguageResultExecution timeMemory
705554krizsu222Homework (CEOI22_homework)C++17
0 / 100
120 ms182780 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") { 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 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...