#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Stack {
stack<ll> base;
int xorv;
Stack() : base(), xorv(0) {}
void flip() {
xorv^=1;
}
void push(ll v) {
base.push(v^xorv);
}
ll top() {
return (base.empty()?0:base.top())^xorv;
}
void add() {
ll v=top();
pop();
v+=top();
pop();
push(v);
}
void pop() {
if(!base.empty()) base.pop();
}
};
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll q;
cin >> q;
while(q--) {
ll x, l, n;
cin >> x >> l >> n;
Stack s1, s2;
ll counter=x;
while(counter>0) {
s2.push(s1.top());
s1.pop();
s1.flip();
if(s2.top()>l) {
counter--;
if(!counter) cout << s2.top() << endl;
} else {
s2.push(n);
s2.push(n);
s2.add();
s2.add();
s1.push(s2.top());
s1.push(s2.top());
s2.pop();
s2.pop();
}
}
}
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |