제출 #853983

#제출 시각아이디문제언어결과실행 시간메모리
853983divadSum Zero (RMI20_sumzero)C++14
61 / 100
266 ms25528 KiB
#include <bits/stdc++.h> #define ends saradanciu using namespace std; const int BASE = 4; const int LMAX = 7; const int NMAX = 4e5+2; int n,q,c,x,y,nxt[LMAX][NMAX]; int ends[NMAX],pwr[LMAX]; ifstream fin("test.in"); ofstream fout("test.out"); signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); pwr[0] = 1; for(int i = 1; i < LMAX; i++){ pwr[i] = pwr[i-1]*BASE; } cin >> n; map<int, int> mp; int pref = 0; mp[pref] = 0; for(int i = 1; i <= n; i++){ cin >> c; pref += c; if(mp.count(pref)){ ends[mp[pref]+1] = i; } mp[pref] = i; } int mini = n+1; nxt[0][n+1] = n+2; for(int i = n; i >= 1; i--){ if(ends[i] != 0){ mini = min(mini, ends[i]); } nxt[0][i] = mini+1; } for(int j = 1; j < LMAX; j++){ for(int i = 1; i <= n+1; i++){ nxt[j][i] = i; for(int k = 1; k <= BASE; k++){ nxt[j][i] = nxt[j-1][nxt[j][i]]; } nxt[j][i] = (nxt[j][i] == 0 ? n+2 : nxt[j][i]); } } cin >> q; int ct = 0; while(q--){ cin >> x >> y; int ans = 0; for(int i = LMAX-1; i >= 0; i--){ while(nxt[i][x]-1 <= y){ ans += pwr[i]; x = nxt[i][x]; } } cout << ans << "\n"; } return 0; }

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

sumzero.cpp: In function 'int main()':
sumzero.cpp:51:9: warning: unused variable 'ct' [-Wunused-variable]
   51 |     int ct = 0;
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...