제출 #756418

#제출 시각아이디문제언어결과실행 시간메모리
756418keta_tsimakuridzeSum Zero (RMI20_sumzero)C++14
61 / 100
249 ms24768 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 = 4e5 + 5, mod = 1e9 + 7; // ! int t, a[N]; int jump[N], p[N], level[N]; unordered_map<ll, int> f; main(){ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); int n; cin >> n; ll tot = 0; for(int i = 1; i <= n; i++) { cin >> a[i]; tot += a[i]; } int mn = n + 1; for(int i = n; i >= 0; i--) { if(f[tot]) mn = min(mn, f[tot]); f[tot] = i; tot -= a[i]; p[i] = mn; level[i] = level[p[i]] + 1; if(mn < n + 1 && level[p[i]] - level[jump[p[i]]] == level[jump[p[i]]] - level[jump[jump[p[i]]]]) jump[i] = jump[jump[p[i]]]; else jump[i] = p[i]; } 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 += level[l] - level[jump[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...