Submission #534449

# Submission time Handle Problem Language Result Execution time Memory
534449 2022-03-08T07:23:12 Z amunduzbaev Arboras (RMI20_arboras) C++17
0 / 100
113 ms 55108 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
#define int long long

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	vector<vector<int>> par(n + 1, vector<int>(20, -1));
	map<int, int> last;
	int pref = 0; last[pref] = n;
	for(int i=n-1;~i;i--){
		pref += a[i];
		if(last.count(pref)) par[i][0] = last[pref];
		
		last[pref] = i;
		if(i + 1 < n && ~par[i+1][0]){
			if(par[i][0] == -1) par[i][0] = par[i+1][0];
			else par[i][0] = min(par[i][0], par[i+1][0]);
		}
	}
	
	for(int j=1;j<20;j++){
		for(int i=0;i<n;i++){
			if(~par[i][j-1])
				par[i][j] = par[par[i][j-1]][j-1];
		}
	}
	
	int q; cin>>q;
	while(q--){
		int l, r; cin>>l>>r;
		l--;
		int res = 0;
		for(int j=19;~j && l < r;j--){
			if(~par[l][j] && par[l][j] <= r){
				res += (1 << j), l = par[l][j];
			}
		}
		
		cout<<res<<"\n";
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 27580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 113 ms 55108 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 580 KB Output isn't correct
2 Halted 0 ms 0 KB -