답안 #313418

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313418 2020-10-16T00:18:57 Z Benq Election (BOI18_election) C++14
컴파일 오류
0 ms 0 KB
#include<iostream>
#include<algorithm>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;
 
struct Node {
    int l_max, r_max, tot, ans;
 
    Node operator+(Node b) {
        Node ret;
        ret.l_max = max(l_max, b.l_max + tot);
        ret.r_max = max(r_max + b.tot, b.r_max);
        ret.tot = tot + b.tot;
        ret.ans = max(max(ans + b.tot, b.ans + tot), l_max + b.r_max);
        return ret;
    }
};
 
Node segtree[2000001];
char s[500001];
int n;
 
void build(int node = 1, int l = 1, int r = n) {
    if (l == r) {
        if (s[l] == 'T') segtree[node] = {1, 1, 1, 1};
        else segtree[node] = {0, 0, -1, 0};
    } else {
        int mid = (l + r) / 2;
        build(node * 2, l, mid);
        build(node * 2 + 1, mid + 1, r);
        segtree[node] = segtree[node * 2] + segtree[node * 2 + 1];
    }
}
 
Node query(int a, int b, int node = 1, int l = 1, int r = n) {
    if (l > b || r < a) return {0, 0, 0, 0};
    if (l >= a && r <= b) return segtree[node];
    int mid = (l + r) / 2;
    return query(a, b, node * 2, l, mid) + query(a, b, node * 2 + 1, mid + 1, r);
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    freopen("elections.in", "r", stdin);
    freopen("elections.out", "w", stdout);
    cin >> n; assert(1 <= n && n <= 500000);
    FOR(i, 1, n + 1) cin >> s[i];
    build();
    int q;
    cin >> q; // assert(1 <= q && q <= 500000);
    while (q--) {
        int a, b;
        cin >> a >> b;
        cout << query(a, b).ans << '\n';
    }
    return 0;
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:48:15: error: 'assert' was not declared in this scope
   48 |     cin >> n; assert(1 <= n && n <= 500000);
      |               ^~~~~~
election.cpp:3:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
    2 | #include<algorithm>
  +++ |+#include <cassert>
    3 | #define FOR(i, x, y) for (int i = x; i < y; i++)
election.cpp:46:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   46 |     freopen("elections.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:47:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   47 |     freopen("elections.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~