Submission #489589

#TimeUsernameProblemLanguageResultExecution timeMemory
489589pliamElection (BOI18_election)C++14
28 / 100
3079 ms2020 KiB
#include <bits/stdc++.h>
#define MAXN 500000
using namespace std;

int N,Q,a[MAXN],b[MAXN];

int main(){
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        char c;
        scanf(" %c",&c);
        a[i]=(c=='C')?1:-1;
    }
    scanf("%d",&Q);
    for(int i=0;i<Q;i++){
        int l,r;
        scanf("%d %d",&l,&r);
        l--; r--;
        int sum=0,countb=0;
        for(int pos=l;pos<=r;pos++){
            b[pos]=0;
            sum+=a[pos];
            if(sum<0){
                b[pos]--;
                sum=0;
                countb++;
            }
        }
        sum=0;
        for(int pos=r;pos>=l;pos--){
            sum+=a[pos];
            if(sum<0){
                b[pos]++;
                sum=0;
            }
        }
        sum=0;
        for(int pos=l;pos<=r;pos++){
            sum+=b[pos];
            if(sum<0) sum=0;
        }
        printf("%d\n",countb+sum);
    }
}

Compilation message (stderr)

election.cpp: In function 'int main()':
election.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
election.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf(" %c",&c);
      |         ~~~~~^~~~~~~~~~
election.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%d",&Q);
      |     ~~~~~^~~~~~~~~
election.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf("%d %d",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...