제출 #467960

#제출 시각아이디문제언어결과실행 시간메모리
467960MilosMilutinovicSum Zero (RMI20_sumzero)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=400005;
const int L=10;
int st[L][N];
void Build(int n){
    for(int i=0;i<N;i++){
        for(int j=0;j<L;j++)st[j][i]=N-2;
    }
    ll sum=0;
    was[0]=0;
    int x;
    for(int i=1;i<=n;i++){
        scanf("%i",&x);
        sum+=x;
        if(was.count(sum)){
            st[0][was[sum]+1]=i;
        }
        was[sum]=i;
    }
    int mn=N-1;
    for(int i=n;i>=1;i--)st[0][i]=min(st[0][i+1],st[0][i]);
    for(int i=1;i<L;i++){
        for(int j=1;j<=n;j++){
            st[i][j]=st[i-1][st[i-1][j]+1];
        }
    }
}
int main(){
    int n;scanf("%i",&n);
    Build(n);
    int q;scanf("%i",&q);
    int l,r,ans=0;
    while(q--){
        scanf("%i%i",&l,&r);
        ans=0;
        for(int i=L-1;i>=0;i--){
            if(st[i][l]<=r)ans+=(1<<i),l=st[i][l]+1;
        }
        printf("%i\n",ans);
    }
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

sumzero.cpp: In function 'void Build(int)':
sumzero.cpp:12:5: error: 'was' was not declared in this scope
   12 |     was[0]=0;
      |     ^~~
sumzero.cpp:22:9: warning: unused variable 'mn' [-Wunused-variable]
   22 |     int mn=N-1;
      |         ^~
sumzero.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%i",&x);
      |         ~~~~~^~~~~~~~~
sumzero.cpp: In function 'int main()':
sumzero.cpp:31:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     int n;scanf("%i",&n);
      |           ~~~~~^~~~~~~~~
sumzero.cpp:33:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     int q;scanf("%i",&q);
      |           ~~~~~^~~~~~~~~
sumzero.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         scanf("%i%i",&l,&r);
      |         ~~~~~^~~~~~~~~~~~~~