제출 #978973

#제출 시각아이디문제언어결과실행 시간메모리
978973NintsiChkhaidzeSum Zero (RMI20_sumzero)C++17
0 / 100
13 ms23384 KiB
#include <bits/stdc++.h> #define ll long long #define s second #define f first #define pb push_back #define pii pair <int,int> using namespace std; const int N = 4e5 + 3; int p[N],last[N],l,r,res,mid,path[N],id; vector <int> v[N]; vector <pii> qr[N]; void dfs(int x){ p[x] = -1; path[++id] = x; for (auto [y,i]: qr[x]){ l = 1; r = id; res=-1; while (l <= r){ mid = (l + r)/2; if (path[mid] <= y){ res = mid; r = mid - 1; }else{ l = mid + 1; } } last[i] = id - res; } for (int to: v[x]) dfs(to); --id; } signed main(){ ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n,i; cin>>n; map <int,int> mp; path[++id] = 0; for(i=1;i<=n;i++) cin>>p[i]; for (i = n; i >= 1; i--){ p[i]+=p[i+1]; path[++id] = p[i]; } sort(path+1,path+1+id); int val=0; for (i=1;i<=id;i++){ if (!i || path[i] != path[i - 1]) { ++val; mp[path[i]] = val; } } for (i = 1; i <= n+1; i++) p[i] = mp[p[i]],last[p[i]] = 1e9; last[mp[0]] = n + 1; int k = 1e9; for (i = n; i >= 1; i--){ k = min(k,last[p[i]]); if (k != 1e9) v[k].pb(i); last[p[i]] = i; } int q,l,r; cin>>q; for (i = 1; i <= q; i++){ cin>>l>>r; qr[l].pb({r + 1,i}); } id=0; for (i = n+1; i >= 1; i--){ if (p[i] != -1) dfs(i); } for (i = 1; i <= q; i++) cout<<last[i]<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...