Submission #729835

# Submission time Handle Problem Language Result Execution time Memory
729835 2023-04-24T17:41:08 Z NeroZein Election (BOI18_election) C++17
0 / 100
13 ms 16084 KB
#include <bits/stdc++.h>
using namespace std;

signed main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); 
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n); 
  for (int i = 0; i < n; ++i) {
    a[i] = (s[i] == 'C' ? 1 : -1); 
  }
  auto Or = [&](vector<int>& x, const vector<int>& y) {
    for (int i = 0; i < n; ++i) {
      x[i] |= y[i];
    }
  };
  vector<int> tmp(n); 
  vector<vector<int>> ver(n, vector<int> (n)); 
  stack<int> stk; 
  for (int i = 0; i < n; ++i) {//if we start decreasingly
    if (a[i] == 1) {
      if (stk.size()) {
        int top = stk.top();
        stk.pop();
        tmp[top] = 0; 
      }
    } else {
      stk.push(i); 
      tmp[i] = 1; 
    }
    Or(ver[i], tmp);
  }
  while (stk.size()) stk.pop();
  for (int i = n - 1; i >= 0; --i) {
    if (a[i] == 1) {
      if (stk.size()) {
        int top = stk.top();
        stk.pop();
        tmp[top] = 0; 
      }
    } else {
      stk.push(i); 
      tmp[i] = 1; 
    }
    Or(ver[n - i - 1], tmp); 
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    --l, --r;
    int ans = 0; 
    for (int i = l; i <= r; ++i) {
      ans += ver[l][i];
    }
    cout << ans << '\n'; 
  }
}
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 16084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 16084 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 16084 KB Output isn't correct
2 Halted 0 ms 0 KB -