제출 #1297466

#제출 시각아이디문제언어결과실행 시간메모리
1297466dostsSum Zero (RMI20_sumzero)C++20
100 / 100
987 ms17752 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2") //#define int long long #define pii pair<int,int> #define vi vector<int> #define ff first #define ss second #define sp << " " << #define all(x) x.begin(),x.end() #define big(x) ((int)(x.size())) using namespace std; const int MOD = 1e9+7, LIM = 1e6+1, inf = 2e18; const int N = 1e5+1; const int L = 19; void solve() { int n; cin >> n; vi a(n+1); for (int i=1;i<=n;i++) cin >> a[i]; int up[n+2]; int sm = 0; map<int,int> sms; up[n+1] = n+1; sms[0] = n+1; for (int i = n;i>=1;i--) { up[i] = up[i+1]; sm+=a[i]; if (sms.count(sm)) up[i] = min(up[i],sms[sm]-1); sms[sm] = i; } int b = 10; vi jump(n+2),jump2(n+2); for (int i=1;i<=n+1;i++) jump2[i] = up[i]; for (int i=1;i<=b;i++) { for (int j = 1;j<=n+1;j++) { if (jump2[j] != n+1) jump[j] = jump2[jump2[j]+1]; else jump[j] = jump2[j]; } for (int j =1;j<=n+1;j++) jump2[j] = jump[j]; } int q; cin >> q; while (q--) { int l,r; cin >> l >> r; int ans = 0; int cur = l; while (cur <= r) { if (jump[cur] <= r) { ans+=(1LL<<b); cur = jump[cur]+1; } else if (up[cur] <= r) { ans++; cur = up[cur]+1; } else break; } cout << ans << '\n'; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; while (t --> 0) solve(); }

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

sumzero.cpp:13:43: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
   13 | const int MOD = 1e9+7, LIM = 1e6+1, inf = 2e18;
      |                                           ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...