Submission #1333664

#TimeUsernameProblemLanguageResultExecution timeMemory
1333664nguyengiabach1201Election (BOI18_election)C++20
28 / 100
3091 ms640 KiB
// https://oj.uz/problem/view/BOI18_election

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define el '\n'
#define FNAME ""
#define ll long long
#define int long long
#define ld long double

const int MOD = 1e9 + 7;
const ll INF = 1e18 + 7;
const double EPS = 1e-9;

void setup()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    if (fopen(FNAME ".inp", "r"))
    {
        freopen(FNAME ".inp", "r", stdin);
        freopen(FNAME ".out", "w", stdout);
    }

    return;
}

int n, q;
string s;

void solve()
{
    cin >> n >> s >> q, s = " " + s;

    for (int l, r, i = 1; i <= q; ++i)
    {
        cin >> l >> r;
        set<int> nullIdx;

        int cCnt = 0, tCnt = 0;

        for (int i = l; i <= r; ++i)
        {
            if (nullIdx.count(i))
                continue;

            if (s[i] == 'C')
                ++cCnt;
            else
            {
                if (tCnt >= cCnt)
                    nullIdx.insert(i);
                else
                    ++tCnt;
            }
        }

        cCnt = tCnt = 0;

        for (int i = r; i >= l; --i)
        {
            if (nullIdx.count(i))
                continue;

            if (s[i] == 'C')
                ++cCnt;
            else
            {
                if (tCnt >= cCnt)
                    nullIdx.insert(i);
                else
                    ++tCnt;
            }
        }

        // for (int i : nullIdx)
        //     cerr << i << " ";
        // cerr << el;

        cout << nullIdx.size() << el;
    }

    return;
}

signed main()
{
    setup();

    int t = 1;
    bool multiTest = false;

    if (multiTest)
        cin >> t;

    while (t--)
        solve();

    return 0;
}

Compilation message (stderr)

election.cpp: In function 'void setup()':
election.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |         freopen(FNAME ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(FNAME ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...