Submission #105888

#TimeUsernameProblemLanguageResultExecution timeMemory
105888IOrtroiiiElection (BOI18_election)C++14
28 / 100
3100 ms1688 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 500500;

char s[N];
bool del[N];

int brute(int l,int r) {
  int nw = 0;
  int ans = 0;
  for (int i = l; i <= r; ++i) {
    nw += (s[i] == 'C' ? +1 : -1);
    if (nw < 0) {
      ++ans;
      del[i] = true;
      nw = 0;
    }
  }
  nw = 0;
  for (int i = r; i >= l; --i) {
    if (del[i]) continue;
    nw += (s[i] == 'C' ? +1 : -1);
    if (nw < 0) {
      ++ans;
      del[i] = true;
      nw = 0;
    }
  }
  for (int i = l; i <= r; ++i) del[i] = false;
  return ans;
}

int main() {
  int n;
  scanf("%d %s", &n, s + 1);
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", brute(l, r));
  }
}

Compilation message (stderr)

election.cpp: In function 'int main()':
election.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %s", &n, s + 1);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
election.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &q);
   ~~~~~^~~~~~~~~~
election.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &l, &r);
     ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...