Submission #853888

#TimeUsernameProblemLanguageResultExecution timeMemory
853888divadSum Zero (RMI20_sumzero)C++14
0 / 100
5 ms11352 KiB
#include <bits/stdc++.h> #define ends saradanciu using namespace std; const int LMAX = 20; const int NMAX = 1e5+2; int n,q,c[NMAX],x,y,nxt[LMAX][NMAX]; vector<int> ends[NMAX]; ifstream fin("test.in"); ofstream fout("test.out"); int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); #ifdef ONPC #define cin fin #define cout fout #endif // ONPC cin >> n; map<int, int> mp; int pref = 0; mp[0] = 0; int nrp = 0; for(int i = 1; i <= n; i++){ cin >> c[i]; pref += c[i]; ends[mp[pref]+1].push_back(i); mp[pref] = i; } set<int> s; s.insert(n+1); nxt[0][n+1] = n+2; for(int i = n; i >= 1; i--){ for(int it: ends[i]){ s.insert(it); } nxt[0][i] = *s.lower_bound(i)+1; } for(int j = 1; j < LMAX; j++){ for(int i = n+1; i >= 1; i--){ nxt[j][i] = nxt[j-1][nxt[j-1][i]]; } for(int i = 1; i <= n+1; i++){ if(nxt[j][i] == 0){ nxt[j][i] = n+2; } } } cin >> q; while(q--){ cin >> x >> y; int ans = 0; for(int i = LMAX-1; i >= 0; i--){ if(nxt[i][x]-1 <= y){ ans += (1<<i); x = nxt[i][x]; } } cout << ans << "\n"; } return 0; }

Compilation message (stderr)

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