Submission #727013

# Submission time Handle Problem Language Result Execution time Memory
727013 2023-04-19T20:03:29 Z YENGOYAN Election (BOI18_election) C++17
0 / 100
11 ms 340 KB
/*
                                    //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
                                    \\                                    //
                                    //  271828___182845__904523__53602__  \\
                                    \\  87___47____13______52____66__24_  //
                                    //  97___75____72______47____09___36  \\
                                    \\  999595_____74______96____69___67  //
                                    //  62___77____24______07____66__30_  \\
                                    \\  35___35____47______59____45713__  //
                                    //                                    \\
                                    \\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
*/
#include <algorithm>
#include <bitset>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using LL = long long;
const int N = 1e5 + 5;
const LL mod = 1e9 + 7, inf = 1e9;

vector<int> dx = { 1, 0, 0, -1, 1, 1, -1, -1 };
vector<int> dy = { 0, 1, -1, 0, 1, -1, 1, -1 };

int block_size = 700;

struct qry {
  int l, r; 
  bool operator<(const qry& other) const {
    return make_pair(l / block_size, r) < make_pair(other.l / block_size, r);
  }
};

void solve() {
  int n; cin >> n;
  string s; cin >> s;
  vector<int> pref(n + 1), suf(n + 1);
  for(int i = 0; i < n; ++i) {
    if(s[i] == 'C') pref[i + 1] = pref[i] + 1;
    else pref[i + 1] = pref[i] - 1;
  }
  for(int i = n - 1; i >= 0; --i) {
    if(s[i] == 'C') suf[i] = suf[i + 1] + 1;
    else suf[i] = suf[i + 1] - 1;
  }
  int q; cin >> q;
  vector<qry> chpl(q), vp(q);
  for(int i = 0; i < q; ++i){
    cin >> chpl[i].l >> chpl[i].r;
    vp[i] = chpl[i];
  }
  sort(chpl.begin(), chpl.end());
  int cur_l = 1, cur_r = 0, ans = 0;
  map<qry, int> answ;
  function<void(int, int, int)> add = [&](int i, int l, int r){
    if(s[i - 1] == 'T') {
      if(i == l || i == r) {
        ++ans;
        return;
      }
      if(pref[i] - pref[l - 1] < 0) {
        ++ans;
        return;
      }
      if(suf[i - 1]  - suf[r] < 0) {
        ++ans;
      }
    }
  };
  function<void(int, int, int)> remove = [&](int i, int l, int r) {
    if(s[i - 1] == 'T') {
      if(i == l || i == r) {
        --ans;
        return;
      }
      if(pref[i] - pref[l - 1] < 0) {
        --ans;
        return;
      }
      if(suf[i - 1]  - suf[r] < 0) {
        --ans;
      }
    }

  };
  for(qry q : chpl) {
    while(cur_l > q.l) {
      cur_l--;
      add(cur_l, q.l, q.r);
    }
    while(cur_r < q.r) {
      cur_r++;
      add(cur_r, q.l, q.r);
    }
    while(cur_l < q.l) {
      remove(cur_l, q.l, q.r);
      cur_l++;
    }
    while(cur_r > q.r) {
      remove(cur_r, q.l, q.r);
      cur_r--;
    }
    answ[q] = ans;
  }
  for(qry q : vp) {
    cout << answ[q] << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 // int t; cin >> t; while(t--)
    solve();
}
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -