Submission #748430

#TimeUsernameProblemLanguageResultExecution timeMemory
748430dooweySum Zero (RMI20_sumzero)C++14
0 / 100
16 ms19540 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N = (int)4e5 + 10; const int LOG = 19; ll c[N]; vector<int> T[N]; vector<pii> Q[N]; int sol[N]; bool vis[N]; int path[N]; int iter = 0; void dfs(int u){ path[iter] = u; iter ++ ; vis[u]=true; for(auto xi : Q[u]){ int lf = 0, rf = iter; int mid; while(lf < rf){ mid = (lf + rf) / 2; if(path[mid] > xi.fi){ lf = mid + 1; } else{ rf = mid; } } sol[xi.se] = iter - 1 - lf; } for(auto x : T[u]){ dfs(x); } iter -- ; } int main(){ fastIO; freopen("in.txt", "r", stdin); int n; cin >> n; for(int i = 1; i <= n; i ++ ){ cin >> c[i]; } ll suff = 0; map<ll, int> en; en[0ll] = n + 1; int low = n + 2; for(int i = n; i >= 1; i -- ){ suff += c[i]; if(en.count(suff)){ low = min(low, en[suff]); } if(low < n + 2) T[low].push_back(i); //cout << i << " -> " << low << "\n"; en[suff] = i; } int q; cin >> q; int li, ri; int ans; for(int iq = 1; iq <= q; iq ++ ){ cin >> li >> ri; Q[li].push_back(mp(ri + 1, iq)); } for(int i = n + 1; i >= 1; i -- ){ if(!vis[i]){ dfs(i); } } for(int iq = 1; iq <= q; iq ++ ){ cout << sol[iq] << "\n"; } return 0; }

Compilation message (stderr)

sumzero.cpp: In function 'int main()':
sumzero.cpp:75:9: warning: unused variable 'ans' [-Wunused-variable]
   75 |     int ans;
      |         ^~~
sumzero.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...