제출 #756409

#제출 시각아이디문제언어결과실행 시간메모리
756409keta_tsimakuridzeSum Zero (RMI20_sumzero)C++14
22 / 100
1046 ms6368 KiB
#include<bits/stdc++.h> #define f first #define s second #define ll long long #define pii pair<int,int> using namespace std; const int N = 2e5 + 5, mod = 1e9 + 7; // ! ll t, a[N]; int jump[N], p[N], c[N]; map<ll, int> f; main(){ int n; cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; } int mn = n + 1; for(int i = n; i >= 0; i--) { if(f[a[i]]) mn = min(mn, f[a[i]]); f[a[i]] = i; // cout << i << "-->" << mn << endl; p[i] = mn; if(mn < n + 1 && c[p[i]] == c[jump[p[i]]]) c[i] = 1 + c[jump[i]] * 2, jump[i] = jump[jump[p[i]]]; else jump[i] = p[i], c[i] = 1; } int q; cin >> q; while(q--) { int l, r; cin >> l >> r; --l; int ans = 0; while(true) { if(p[l] > r) break; if(jump[l] <= r) ans += c[l], l = jump[l]; else ans++, l = p[l]; } cout << ans << "\n"; } }

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

sumzero.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...