Submission #1126978

#TimeUsernameProblemLanguageResultExecution timeMemory
1126978VinhLuuElection (BOI18_election)C++20
28 / 100
3093 ms2496 KiB
#include <bits/stdc++.h>
#define ll long long
#define all(lpv) lpv.begin(), lpv.end()
#define pot(x, y) lower_bound(x.begin(), x.end(), y) - x.begin() + 1
using namespace std;

#define lpv

#ifndef lpv
#include "AC.h"
#endif // lpv

const int N = 1e6 + 5;
const int oo = 1e9;

int n, q, a[N], s[N], p[N], b[N], bs[N], bp[N];

#ifdef lpv
signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define task "v"
  if(fopen(task ".inp","r")) {
    freopen(task ".inp","r",stdin);
    freopen(task ".out","w",stdout);
  }
  cin >> n;
  string str; cin >> str;
  str = " " + str;
  for(int i = 1; i <= n; i ++) {
    if(str[i] == 'C') a[i] = 1;
    else a[i] = -1;
    s[i] = s[i - 1] + a[i];
  }
  for(int i = n; i >= 1; i --) p[i] = p[i + 1] + a[i];
  cin >> q;
  while(q--) {
    int l, r; cin >> l >> r;
    int cnt = 0;
    bs[l - 1] = 0;
    for(int i = l; i <= r; i ++) {
      b[i] = a[i];
      bs[i] = bs[i - 1] + b[i];
      if(bs[i] < 0) {
        bs[i] = bs[i - 1];
        b[i] = 0;
        cnt++;
      }
    }
    bp[r + 1] = 0;
    for(int i = r; i >= l; i --) {
      bp[i] = bp[i + 1] + b[i];
      if(bp[i] < 0) {
        bp[i] = bp[i + 1];
        b[i] = 0;
        cnt++;
      }
    }
    cout << cnt << "\n";
  }
}
#endif // lpv

Compilation message (stderr)

election.cpp: In function 'int main()':
election.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     freopen(task ".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
election.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     freopen(task ".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...