Submission #1170672

#TimeUsernameProblemLanguageResultExecution timeMemory
1170672uranhishigIndex (COCI21_index)C++20
0 / 110
1 ms320 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ss second

const int N = 8e6 + 5;
int bit[N];
int a[N];

void update (int idx, int val) {
	while(idx < N) {	
		bit[idx] += val;	
		idx += idx & -idx;	
	}
}
int get (int idx) {
	if (idx<=0) {
		return 0;
	}
	int s = 0;
	while (idx > 0){
		s += bit[idx];
		idx -= idx& -idx;
	}
	return s;
}
signed main() {
	int n, q;	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		update(i, a[i]);
	}
	while (q--) {
		int l, r;
		cin >> l >> r;
		int L = 0;
		int R = (r - l + 1);
		while (L + 1 < R) {
			int mid = (L + R + 1) / 2;
			if ( get(R) - get(L + 1) > mid ) {
				L = mid;
			}
			else {
				R = mid;
			}
		}
		cout << " * "<< L << endl;
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...