Editorial for Bedao Mini Contest 05 - BALLS


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Code mẫu

#include <bits/stdc++.h>

using namespace std;
const string filename = "BALLS";

int n, q;
int a[100001];
bool have[3];

int ans[100001];

int main(int argc, char** argv)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    freopen( (filename + ".inp").c_str(), "r", stdin);
    freopen( (filename + ".out").c_str(), "w", stdout);

    cin >> n >> q;
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        cnt++;
        if (a[i] == 1 && have[1])
        {
            have[1] = false; 
            cnt--;
            if (have[2])
            {
                have[2] = false;
                cnt--;  
            }
            else
                have[2] = true;
        }
        else if (a[i] == 1)
            have[1] = true;
        if (a[i] == 2 && have[2])
        {
            have[2] = false;
            cnt--;
        }
        else if (a[i] == 2)
            have[2] = true;
        ans[i] = cnt;
    }   
    while (q--)
    {
        int u; cin >> u;
        cout << ans[u] << ' ';
    }
}

Comments

Please read the guidelines before commenting.


There are no comments at the moment.