WA+TLE样例已过求调
查看原帖
WA+TLE样例已过求调
920211
wuxikai楼主2024/10/21 19:56

只拿了5pts

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
bool a[N];
string op[N];
int n, k;
bool cal()
{
    stack<bool> stk;
    for (int i = 1; i <= k; i++)
    {
        if (op[i] == "!")
        {
            bool t = stk.top();
            stk.pop();
            stk.push(!(t));
        }
        else if (op[i] == "&")
        {
            bool t1 = stk.top();
            stk.pop();
            bool t2 = stk.top();
            stk.pop();
            stk.push(t1 && t2);
        }
        else if (op[i] == "|")
        {
            bool t1 = stk.top();
            stk.pop();
            bool t2 = stk.top();
            stk.pop();
            stk.push(t1 || t2);
        }
        else
        {
            stk.push(a[op[i][1] - '0']);
        }
    }
    return stk.top();
}
int main()
{
    string s;
    getline(cin, s);
    string t = "";
    s = s + " ";
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == ' ')
            op[++k] = t, t = "";
        else
            t += s[i];
    }
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    int q;
    cin >> q;
    while (q--)
    {
        int i;
        cin >> i;
        a[i] ^= 1;
        cout << cal() << '\n';
        a[i] ^= 1;
    }
    return 0;
}
2024/10/21 19:56
加载中...