제출 #1083657

#제출 시각아이디문제언어결과실행 시간메모리
1083657preskoSum Zero (RMI20_sumzero)C++14
0 / 100
12 ms7372 KiB
#include<iostream> #include<vector> #define MAXN 400010 using namespace std; int a[MAXN]; long long pre[MAXN]; vector<pair<long long,int>> sums; vector<pair<int,int>> parts; int locate(int val) { if(sums.size()==0)return -1; int l=0,r=sums.size()-1; while(l<r) { int mid=(l+r)>>1; if(sums[mid].first<val)l=mid+1; else if(sums[mid].first==val){l=mid;break;} else r=mid-1; } if(sums[l].first!=val)return -1; return sums[l].second; } int calc(int l, int r) { long long sum=0; for(int i=l;i<=r;i++) { if(a[i]==0) { parts.push_back({i,i}); sums.clear(); sums.push_back({0,i}); sum=0; continue; } sum+=a[i]; int res=locate(sum); if(res>-1){parts.push_back({res+1,i});sums.clear();sums.push_back({0,i});sum=0;} sums.push_back({sum,i}); } } int main() { int n,q; ios_base::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; pre[i]=pre[i-1]+a[i]; } /*sums.push_back({0,0}); calc(1,n);*/ cin>>q; for(int t=0;t<q;t++) { int l,r; cin>>l>>r; sums.clear();parts.clear(); sums.push_back({0,l-1}); calc(l,r); cout<<parts.size()<<"\n"; } }

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

sumzero.cpp: In function 'int calc(int, int)':
sumzero.cpp:41:1: warning: no return statement in function returning non-void [-Wreturn-type]
   41 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...