Submission #754082

#TimeUsernameProblemLanguageResultExecution timeMemory
754082keta_tsimakuridzeSum Zero (RMI20_sumzero)C++14
22 / 100
172 ms39228 KiB
#include<bits/stdc++.h> #define f first #define s second #define pii pair<int,int> #define Pii pair<int, pair<int,int>> using namespace std; const int N = 4e5 + 5, mod = 1e9 + 7; // ! int t, ans[N], a[N]; //set<pair<int, pair<int,int> >> v[N]; vector<int> V[N], p; map<int,int> f; vector<Pii> v[N]; void dfs(int u) { p.push_back(u); for(int i = 0; i < V[u].size(); i++) dfs(V[u][i]); p.pop_back(); for(int I = 18; I >= 0; I--) { for(int i = (int)v[u].size() - 1; i >= 0; i--) { Pii x = v[u][i]; if(x.f != I) continue; swap(v[u][i], v[u].back()); v[u].pop_back(); if(x.f < 0) continue; if((int)p.size() >= (1 << x.f) && p[(int)p.size() - (1 << x.f)] <= x.s.s) ans[x.s.f] += 1 << x.f, v[p[(int)p.size() - (1 << x.f)]].push_back({x.f - 1, x.s}); else if(x.f) v[u].push_back({x.f - 1, x.s}); } } // p.push_back(u); } main(){ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); int n, q; cin >> n; for(int i = 1; i <= n; i++) { cin >> a[i]; a[i] += a[i - 1]; } cin >> q; int mn = n + 1; for(int i = n; i >= 0; i--) { if(f[a[i]]) mn = min(mn, f[a[i]]); V[mn].push_back(i); f[a[i]] = i; } for(int i = 1; i <= q; i++) { int l, r; cin >> l >> r; --l; v[l].push_back({18, {i, r}}); } dfs(n + 1); for(int i = 1; i <= q; i++) cout << ans[i] << "\n"; }

Compilation message (stderr)

sumzero.cpp: In function 'void dfs(int)':
sumzero.cpp:15:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i = 0; i < V[u].size(); i++) dfs(V[u][i]);
      |                    ~~^~~~~~~~~~~~~
sumzero.cpp: At global scope:
sumzero.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   30 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...