Submission #978954

#TimeUsernameProblemLanguageResultExecution timeMemory
978954NintsiChkhaidzeSum Zero (RMI20_sumzero)C++17
0 / 100
11 ms33368 KiB
#include <bits/stdc++.h> #define ll long long #define s second #define f first #define pb push_back #define pii pair <int,int> #define left (h<<1),l,(l + r)/2 #define right ((h<<1)|1),(l + r)/2 + 1,r using namespace std; const int N = 4e5 + 5; int a[N],p[N],last[N]; int dp[N],d[23][N]; signed main(){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n; cin>>n; vector <int> vec; map <int,int> mp; vec.pb(0); for(int i=1;i<=n;i++){ cin>>a[i]; } for (int i = n; i >= 1; i--){ p[i]=p[i+1]+a[i]; vec.pb(p[i]); } sort(vec.begin(),vec.end()); int val=0; for (int i=0;i<vec.size();i++){ if (!i || vec[i] != vec[i - 1]) { ++val; mp[vec[i]] = val; } } for (int i = 1; i <= n+1; i++) p[i] = mp[p[i]],last[p[i]] = 1e9; last[mp[0]] = n + 1; dp[n + 1] = 1e9; for (int i = n; i >= 1; i--){ dp[i] = min(dp[i + 1],last[p[i]]); d[0][i] = dp[i]; last[p[i]] = i; } d[0][n+1] = 1e9; for (int j = 1; j <= 18; j++){ for (int i = 1; i <= n+1; i++){ int l = d[j - 1][i]; if (l >= 1e9) d[j][i] = 1e9; else d[j][i] = d[j - 1][l]; } } int q; cin>>q; while(q--){ int l,r; cin>>l>>r; int x = l,ans = 0; for (int i = 18; i >= 0; i--){ if (d[i][x] <= r + 1){ x = d[i][x]; ans += (1<<i); } } cout<<ans<<endl; } }

Compilation message (stderr)

sumzero.cpp: In function 'int main()':
sumzero.cpp:36:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |  for (int i=0;i<vec.size();i++){
      |               ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...