답안 #69531

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69531 2018-08-21T08:09:03 Z 3zp Election (BOI18_election) C++14
82 / 100
2330 ms 263168 KB
#include<bits/stdc++.h>
using namespace std;
struct NODE{
    int S, mil, mir, mal, mar, ans;
    NODE *L, *R;
    void CO(NODE *&X, NODE *&Y){
        if(!X && !Y) return;
        if(!X) {
            this -> S = Y -> S;
            this -> mil = Y -> mil;
            this -> mir = Y -> mir;
            this -> mal = Y -> mal;
            this -> mar = Y -> mar;
            this -> ans = Y -> ans;
            return;
        }
        if(!Y){
            this -> S = X -> S;
            this -> mil = X -> mil;
            this -> mir = X -> mir;
            this -> mal = X -> mal;
            this -> mar = X -> mar;
            this -> ans = X -> ans;
            return;
        }
        this->S = X->S+ Y->S;
        this->mil = X->mil;
        this->mir = min(Y->mir + X->S, X->mir);
        this->mal = max(X->mal, Y->mal + X->S);
        this->mar = Y->mar + X->S;
        this->ans = max(X->ans, Y->ans);
        this->ans = max(this->ans, Y->mal + X->S - X->mir);

    }
    void upd(){
        this->CO(this->L, this->R);
    }
};
int s[500009];
void build(NODE *&x, int l, int r){
    x = new NODE();
    if(l == r){
        int k =  s[l] - s[l-1];
        x->S = k;
        x->mil = 0;
        x->mir = min(0, k);
        x->mal = max(0, k);
        x->mar = k;
        x->ans = max(k, 0);
    }
    else{
        int mid = (l + r)/2;
        build(x->L, l, mid);
        build(x->R, mid+1, r);
        x->upd();
    }
 }
void cnt(NODE *&x, NODE *&ans, int l, int r, int a, int b){
    if(a > r || b < l) return;
    if(l >= a && r <= b) {ans = x; return;}
    int mid = (l + r)/2;
    NODE *ans1 = NULL, *ans2 = NULL;
    cnt(x->L, ans1, l, mid, a ,b);
    cnt(x->R, ans2, mid+1, r, a, b);
    ans = new NODE();
    ans->CO(ans1, ans2);
}
NODE *rt, *ANS;
main(){
    int n;
    cin >> n;
    string W;
    cin >> W;
    for(int i = 1; i <= W.size(); i++)
        if(W[i-1] == 'C') s[i] = s[i-1]+1;
    else s[i] =  s[i-1] - 1;

    build(rt,1,n);
    int q;
    cin >> q;
    while(q--){
        int l, r;
        cin >> l >> r;
        cnt(rt, ANS, 1, n, l, r);
        cout << ANS-> ans - ANS->S << endl;
        /*int S = 0;
        int M = 0;
        for(int i = l - 1; i <= r; i++){
            if(s[i] + S < s[l - 1]){
                S++;
                M = max(0, M-1);
            }
            if(s[i] > s[r]){
                M = max(M, s[i] - s[r]);
            }

        }
        cout << S + M << endl;*/

    }

}

Compilation message

election.cpp:69:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
election.cpp: In function 'int main()':
election.cpp:74:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1; i <= W.size(); i++)
                    ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2168 KB Output is correct
2 Correct 11 ms 2280 KB Output is correct
3 Correct 10 ms 2352 KB Output is correct
4 Correct 10 ms 2352 KB Output is correct
5 Correct 10 ms 2352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2168 KB Output is correct
2 Correct 11 ms 2280 KB Output is correct
3 Correct 10 ms 2352 KB Output is correct
4 Correct 10 ms 2352 KB Output is correct
5 Correct 10 ms 2352 KB Output is correct
6 Correct 419 ms 98540 KB Output is correct
7 Correct 350 ms 104052 KB Output is correct
8 Correct 383 ms 104052 KB Output is correct
9 Correct 336 ms 104052 KB Output is correct
10 Correct 399 ms 104052 KB Output is correct
11 Correct 404 ms 104052 KB Output is correct
12 Correct 415 ms 104052 KB Output is correct
13 Correct 524 ms 104572 KB Output is correct
14 Correct 481 ms 105580 KB Output is correct
15 Correct 436 ms 106548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2168 KB Output is correct
2 Correct 11 ms 2280 KB Output is correct
3 Correct 10 ms 2352 KB Output is correct
4 Correct 10 ms 2352 KB Output is correct
5 Correct 10 ms 2352 KB Output is correct
6 Correct 419 ms 98540 KB Output is correct
7 Correct 350 ms 104052 KB Output is correct
8 Correct 383 ms 104052 KB Output is correct
9 Correct 336 ms 104052 KB Output is correct
10 Correct 399 ms 104052 KB Output is correct
11 Correct 404 ms 104052 KB Output is correct
12 Correct 415 ms 104052 KB Output is correct
13 Correct 524 ms 104572 KB Output is correct
14 Correct 481 ms 105580 KB Output is correct
15 Correct 436 ms 106548 KB Output is correct
16 Runtime error 2330 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
17 Halted 0 ms 0 KB -